make verifyElementInFocus a ViewHelpers method
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
(function() {
|
||||
|
||||
define(["jquery", "common/js/components/views/feedback", "common/js/components/views/feedback_notification", "common/js/components/views/feedback_alert", "common/js/components/views/feedback_prompt", "sinon", "jquery.simulate"],
|
||||
function($, SystemFeedback, NotificationView, AlertView, PromptView, sinon) {
|
||||
define(["jquery", "common/js/components/views/feedback", "common/js/components/views/feedback_notification", "common/js/components/views/feedback_alert", "common/js/components/views/feedback_prompt", 'common/js/spec_helpers/view_helpers', "sinon", "jquery.simulate"],
|
||||
function($, SystemFeedback, NotificationView, AlertView, PromptView, ViewHelpers, sinon) {
|
||||
var tpl;
|
||||
tpl = readFixtures('system-feedback.underscore');
|
||||
beforeEach(function() {
|
||||
@@ -137,21 +137,13 @@
|
||||
var view;
|
||||
view = new PromptView.Confirmation(this.options).show();
|
||||
expect(this.inFocusSpy).toHaveBeenCalled();
|
||||
return waitsFor(
|
||||
function() { return view.$('.wrapper-prompt:focus').length === 1; },
|
||||
"The modal should have focus",
|
||||
500
|
||||
);
|
||||
return ViewHelpers.verifyElementInFocus(view, ".wrapper-prompt")
|
||||
});
|
||||
it("is not focused on hide", function() {
|
||||
var view;
|
||||
view = new PromptView.Confirmation(this.options).hide();
|
||||
expect(this.outFocusSpy).toHaveBeenCalled();
|
||||
return waitsFor(
|
||||
function() { return view.$('.wrapper-prompt:focus').length === 0; },
|
||||
"The modal should not have focus",
|
||||
500
|
||||
);
|
||||
return ViewHelpers.verifyElementNotInFocus(view, ".wrapper-prompt")
|
||||
});
|
||||
it("traps keyboard focus when moving forward", function() {
|
||||
var view;
|
||||
@@ -161,11 +153,7 @@
|
||||
"keydown",
|
||||
{ keyCode: $.simulate.keyCode.TAB }
|
||||
);
|
||||
return waitsFor(
|
||||
function() { return view.$('.action-primary:focus').length === 1; },
|
||||
"The first action button should have focus",
|
||||
500
|
||||
);
|
||||
return ViewHelpers.verifyElementInFocus(view, ".action-primary")
|
||||
});
|
||||
it("traps keyboard focus when moving backward", function() {
|
||||
var view;
|
||||
@@ -175,11 +163,7 @@
|
||||
"keydown",
|
||||
{ keyCode: $.simulate.keyCode.TAB, shiftKey: true }
|
||||
);
|
||||
return waitsFor(
|
||||
function() { return view.$('.action-secondary:focus').length === 1; },
|
||||
"The last action button should have focus",
|
||||
500
|
||||
);
|
||||
return ViewHelpers.verifyElementInFocus(view, ".action-secondary")
|
||||
});
|
||||
return it("changes class on body", function() {
|
||||
var view;
|
||||
|
||||
@@ -10,7 +10,8 @@ define(["jquery", "common/js/components/views/feedback_notification", "common/js
|
||||
verifyFeedbackHidden, createNotificationSpy, verifyNotificationShowing,
|
||||
verifyNotificationHidden, createPromptSpy, confirmPrompt, inlineEdit, verifyInlineEditChange,
|
||||
installMockAnalytics, removeMockAnalytics, verifyPromptShowing, verifyPromptHidden,
|
||||
clickDeleteItem, patchAndVerifyRequest, submitAndVerifyFormSuccess, submitAndVerifyFormError;
|
||||
clickDeleteItem, patchAndVerifyRequest, submitAndVerifyFormSuccess, submitAndVerifyFormError,
|
||||
verifyElementInFocus, verifyElementNotInFocus;
|
||||
|
||||
installViewTemplates = function() {
|
||||
appendSetFixtures('<div id="page-notification"></div>');
|
||||
@@ -127,6 +128,22 @@ define(["jquery", "common/js/components/views/feedback_notification", "common/js
|
||||
verifyNotificationShowing(notificationSpy, /Saving/);
|
||||
};
|
||||
|
||||
verifyElementInFocus = function(view, selector) {
|
||||
waitsFor(
|
||||
function() { return view.$(selector + ':focus').length === 1; },
|
||||
"element to have focus: " + selector,
|
||||
500
|
||||
);
|
||||
};
|
||||
|
||||
verifyElementNotInFocus = function(view, selector) {
|
||||
waitsFor(
|
||||
function() { return view.$(selector + ':focus').length === 0; },
|
||||
"element to not have focus: " + selector,
|
||||
500
|
||||
);
|
||||
};
|
||||
|
||||
return {
|
||||
'installViewTemplates': installViewTemplates,
|
||||
'createNotificationSpy': createNotificationSpy,
|
||||
@@ -143,7 +160,9 @@ define(["jquery", "common/js/components/views/feedback_notification", "common/js
|
||||
'clickDeleteItem': clickDeleteItem,
|
||||
'patchAndVerifyRequest': patchAndVerifyRequest,
|
||||
'submitAndVerifyFormSuccess': submitAndVerifyFormSuccess,
|
||||
'submitAndVerifyFormError': submitAndVerifyFormError
|
||||
'submitAndVerifyFormError': submitAndVerifyFormError,
|
||||
'verifyElementInFocus': verifyElementInFocus,
|
||||
'verifyElementNotInFocus': verifyElementNotInFocus
|
||||
};
|
||||
});
|
||||
}).call(this, define || RequireJS.define);
|
||||
|
||||
Reference in New Issue
Block a user