* fix: eslint operator-linebreak issue * fix: eslint quotes issue * fix: react jsx indent and props issues * fix: eslint trailing spaces issues * fix: eslint line around directives issue * fix: eslint semi rule * fix: eslint newline per chain rule * fix: eslint space infix ops rule * fix: eslint space-in-parens issue * fix: eslint space before function paren issue * fix: eslint space before blocks issue * fix: eslint arrow body style issue * fix: eslint dot-location issue * fix: eslint quotes issue * fix: eslint quote props issue * fix: eslint operator assignment issue * fix: eslint new line after import issue * fix: indent issues * fix: operator assignment issue * fix: all autofixable eslint issues * fix: all react related fixable issues * fix: autofixable eslint issues * chore: remove all template literals * fix: remaining autofixable issues * fix: failing js test
142 lines
4.4 KiB
JavaScript
142 lines
4.4 KiB
JavaScript
/**
|
|
* Provides helper methods for invoking Studio editors in Jasmine tests.
|
|
*/
|
|
import $ from 'jquery';
|
|
import _ from 'underscore';
|
|
import AjaxHelpers from 'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers';
|
|
import TemplateHelpers from 'common/js/spec_helpers/template_helpers';
|
|
import modal_helpers from 'js/spec_helpers/modal_helpers';
|
|
import EditXBlockModal from 'js/views/modals/edit_xblock';
|
|
import ComponentTemplates from 'js/collections/component_template';
|
|
import XModule from 'xmodule/js/src/xmodule';
|
|
import 'cms/js/main';
|
|
import 'xblock/cms.runtime.v1';
|
|
|
|
var installMockXBlock, uninstallMockXBlock, installMockXModule, uninstallMockXModule,
|
|
mockComponentTemplates, installEditTemplates, showEditModal, verifyXBlockRequest;
|
|
|
|
installMockXBlock = function(mockResult) {
|
|
window.MockXBlock = function(runtime, element) {
|
|
var block = {
|
|
runtime: runtime
|
|
};
|
|
if (mockResult) {
|
|
block.save = function() {
|
|
return mockResult;
|
|
};
|
|
}
|
|
return block;
|
|
};
|
|
};
|
|
|
|
uninstallMockXBlock = function() {
|
|
window.MockXBlock = null;
|
|
};
|
|
|
|
installMockXModule = function(mockResult) {
|
|
window.MockDescriptor = _.extend(XModule.Descriptor, {
|
|
save: function() {
|
|
return mockResult;
|
|
}
|
|
});
|
|
};
|
|
|
|
uninstallMockXModule = function() {
|
|
window.MockDescriptor = null;
|
|
};
|
|
|
|
mockComponentTemplates = new ComponentTemplates([
|
|
{
|
|
templates: [
|
|
{
|
|
category: 'discussion',
|
|
display_name: 'Discussion'
|
|
}],
|
|
type: 'discussion',
|
|
support_legend: {show_legend: false}
|
|
}, {
|
|
templates: [
|
|
{
|
|
category: 'html',
|
|
boilerplate_name: null,
|
|
display_name: 'Text'
|
|
}, {
|
|
category: 'html',
|
|
boilerplate_name: 'announcement.yaml',
|
|
display_name: 'Announcement'
|
|
}, {
|
|
category: 'html',
|
|
boilerplate_name: 'raw.yaml',
|
|
display_name: 'Raw HTML'
|
|
}],
|
|
type: 'html',
|
|
support_legend: {show_legend: false}
|
|
}],
|
|
{
|
|
parse: true
|
|
});
|
|
|
|
installEditTemplates = function(append) {
|
|
modal_helpers.installModalTemplates(append);
|
|
|
|
// Add templates needed by the add XBlock menu
|
|
TemplateHelpers.installTemplate('add-xblock-component');
|
|
TemplateHelpers.installTemplate('add-xblock-component-button');
|
|
TemplateHelpers.installTemplate('add-xblock-component-menu');
|
|
TemplateHelpers.installTemplate('add-xblock-component-menu-problem');
|
|
TemplateHelpers.installTemplate('add-xblock-component-support-legend');
|
|
TemplateHelpers.installTemplate('add-xblock-component-support-level');
|
|
|
|
// Add templates needed by the edit XBlock modal
|
|
TemplateHelpers.installTemplate('edit-xblock-modal');
|
|
TemplateHelpers.installTemplate('editor-mode-button');
|
|
TemplateHelpers.installTemplate('edit-title-button');
|
|
|
|
// Add templates needed by the settings editor
|
|
TemplateHelpers.installTemplate('metadata-editor');
|
|
TemplateHelpers.installTemplate('metadata-number-entry', false, 'metadata-number-entry');
|
|
TemplateHelpers.installTemplate('metadata-string-entry', false, 'metadata-string-entry');
|
|
};
|
|
|
|
showEditModal = function(requests, xblockElement, model, mockHtml, options) {
|
|
var modal = new EditXBlockModal({});
|
|
modal.edit(xblockElement, model, options);
|
|
AjaxHelpers.respondWithJson(requests, {
|
|
html: mockHtml,
|
|
resources: []
|
|
});
|
|
return modal;
|
|
};
|
|
|
|
verifyXBlockRequest = function(requests, expectedJson) {
|
|
var request = AjaxHelpers.currentRequest(requests),
|
|
actualJson = JSON.parse(request.requestBody);
|
|
expect(request.url).toEqual('/xblock/');
|
|
expect(request.method).toEqual('POST');
|
|
expect(actualJson).toEqual(expectedJson);
|
|
};
|
|
|
|
var editHelpers = $.extend(modal_helpers, {
|
|
installMockXBlock: installMockXBlock,
|
|
uninstallMockXBlock: uninstallMockXBlock,
|
|
installMockXModule: installMockXModule,
|
|
uninstallMockXModule: uninstallMockXModule,
|
|
mockComponentTemplates: mockComponentTemplates,
|
|
installEditTemplates: installEditTemplates,
|
|
showEditModal: showEditModal,
|
|
verifyXBlockRequest: verifyXBlockRequest
|
|
});
|
|
|
|
export default editHelpers;
|
|
|
|
export {
|
|
installMockXBlock,
|
|
uninstallMockXBlock,
|
|
installMockXModule,
|
|
uninstallMockXModule,
|
|
mockComponentTemplates,
|
|
installEditTemplates,
|
|
showEditModal,
|
|
verifyXBlockRequest,
|
|
};
|