Add unit tests for custom tabs and modal titles

This commit is contained in:
Andy Armstrong
2014-04-03 12:02:48 -04:00
parent 5ab159b079
commit b779b8a6fb
6 changed files with 111 additions and 43 deletions

View File

@@ -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');
});
});
});
});

View File

@@ -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) {

View File

@@ -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);
},