diff --git a/cms/static/js/spec/views/modals/edit_xblock_spec.js b/cms/static/js/spec/views/modals/edit_xblock_spec.js index 0ba90abae7..1007873241 100644 --- a/cms/static/js/spec/views/modals/edit_xblock_spec.js +++ b/cms/static/js/spec/views/modals/edit_xblock_spec.js @@ -1,5 +1,5 @@ define(["jquery", "underscore", "js/spec_helpers/create_sinon", "js/spec_helpers/edit_helpers", - "js/views/modals/edit_xblock", "js/models/xblock_info"], + "js/views/modals/edit_xblock", "js/models/xblock_info"], function ($, _, create_sinon, edit_helpers, EditXBlockModal, XBlockInfo) { describe("EditXBlockModal", function() { @@ -20,7 +20,13 @@ define(["jquery", "underscore", "js/spec_helpers/create_sinon", "js/spec_helpers }); }); - describe("Editing an xblock", function() { + afterEach(function() { + if (modal && edit_helpers.isShowingModal(modal)) { + edit_helpers.cancelModal(modal); + } + }); + + describe("XBlock Editor", function() { var mockXBlockEditorHtml; mockXBlockEditorHtml = readFixtures('mock/mock-xblock-editor.underscore'); @@ -43,15 +49,20 @@ define(["jquery", "underscore", "js/spec_helpers/create_sinon", "js/spec_helpers expect(modal.$('.wrapper-modal-window')).not.toHaveClass('is-shown'); }); + it('shows the correct title', function() { + var requests = create_sinon.requests(this); + modal = showModal(requests, mockXBlockEditorHtml); + expect(modal.$('.modal-window-title').text()).toBe('Editing: Component'); + }); + it('does not show any editor mode buttons', function() { var requests = create_sinon.requests(this); modal = showModal(requests, mockXBlockEditorHtml); expect(modal.$('.editor-modes a').length).toBe(0); - edit_helpers.cancelModal(modal); }); }); - describe("Editing an xmodule", function() { + describe("XModule Editor", function() { var mockXModuleEditorHtml; mockXModuleEditorHtml = readFixtures('mock/mock-xmodule-editor.underscore'); @@ -67,14 +78,18 @@ define(["jquery", "underscore", "js/spec_helpers/create_sinon", "js/spec_helpers it('can render itself', function() { var requests = create_sinon.requests(this); - - // Show the modal using a mock xblock response modal = showModal(requests, mockXModuleEditorHtml); expect(modal.$('.wrapper-modal-window')).toHaveClass('is-shown'); edit_helpers.cancelModal(modal); expect(modal.$('.wrapper-modal-window')).not.toHaveClass('is-shown'); }); + it('shows the correct title', function() { + var requests = create_sinon.requests(this); + modal = showModal(requests, mockXModuleEditorHtml); + expect(modal.$('.modal-window-title').text()).toBe('Editing: Component'); + }); + it('shows the correct default buttons', function() { var requests = create_sinon.requests(this), editorButton, @@ -87,7 +102,24 @@ define(["jquery", "underscore", "js/spec_helpers/create_sinon", "js/spec_helpers expect(editorButton).toHaveClass('is-set'); expect(settingsButton.length).toBe(1); expect(settingsButton).not.toHaveClass('is-set'); - edit_helpers.cancelModal(modal); + }); + + describe("Custom Tabs", function() { + var mockCustomTabsHtml; + + mockCustomTabsHtml = readFixtures('mock/mock-xmodule-editor-with-custom-tabs.underscore'); + + it('hides the modal\'s header', function() { + var requests = create_sinon.requests(this); + modal = showModal(requests, mockCustomTabsHtml); + expect(modal.$('.modal-header')).toBeHidden(); + }); + + it('shows the correct title', function() { + var requests = create_sinon.requests(this); + modal = showModal(requests, mockCustomTabsHtml); + expect(modal.$('.component-name').text()).toBe('Editing: Component'); + }); }); }); }); diff --git a/cms/static/js/spec_helpers/edit_helpers.js b/cms/static/js/spec_helpers/edit_helpers.js index 62289158b2..dab7270075 100644 --- a/cms/static/js/spec_helpers/edit_helpers.js +++ b/cms/static/js/spec_helpers/edit_helpers.js @@ -40,8 +40,17 @@ define(["jquery", "js/spec_helpers/create_sinon", "js/views/modals/edit_xblock", return modal; }; - isShowingModal = function() { - return $('.wrapper-modal-window').length > 0; + isShowingModal = function(modal) { + var modalElement; + if (modal) { + modalElement = modal.$el; + } else { + modalElement = $('.wrapper-modal-window'); + } + if (modalElement) { + return modalElement.hasClass('is-shown'); + } + return false; }; cancelModal = function(modal) { diff --git a/cms/static/js/views/modals/edit_xblock.js b/cms/static/js/views/modals/edit_xblock.js index c583e12e41..f5ce7d2cf0 100644 --- a/cms/static/js/views/modals/edit_xblock.js +++ b/cms/static/js/views/modals/edit_xblock.js @@ -70,7 +70,14 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal", }, getTitle: function() { - var displayName = this.xblockElement.find('.component-header').text().trim(); + var displayName = this.xblockElement.find('.xblock-header .header-details').text().trim(); + // If not found, try the old unit page style rendering + if (!displayName) { + displayName = this.xblockElement.find('.component-header').text().trim(); + if (!displayName) { + displayName = gettext('Component'); + } + } return interpolate(gettext("Editing: %(title)s"), { title: displayName }, true); }, diff --git a/cms/templates/js/mock/mock-xmodule-editor-with-custom-tabs.underscore b/cms/templates/js/mock/mock-xmodule-editor-with-custom-tabs.underscore new file mode 100644 index 0000000000..59124e7633 --- /dev/null +++ b/cms/templates/js/mock/mock-xmodule-editor-with-custom-tabs.underscore @@ -0,0 +1,21 @@ +
+
+
+
+ + +
+
+
+

Basic editor

+
+
+

Advanced editor

+
+
+
+
+
diff --git a/common/lib/xmodule/xmodule/js/fixtures/tabs-edit.html b/common/lib/xmodule/xmodule/js/fixtures/tabs-edit.html index 1633ebfebc..47cd59e045 100644 --- a/common/lib/xmodule/xmodule/js/fixtures/tabs-edit.html +++ b/common/lib/xmodule/xmodule/js/fixtures/tabs-edit.html @@ -5,34 +5,38 @@ - +