Commit 2dc5b8e8 by Christine Lytwynec

make verifyElementInFocus a ViewHelpers method

parent f96d4b71
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.1
(function() { (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"], 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, sinon) { function($, SystemFeedback, NotificationView, AlertView, PromptView, ViewHelpers, sinon) {
var tpl; var tpl;
tpl = readFixtures('system-feedback.underscore'); tpl = readFixtures('system-feedback.underscore');
beforeEach(function() { beforeEach(function() {
...@@ -137,21 +137,13 @@ ...@@ -137,21 +137,13 @@
var view; var view;
view = new PromptView.Confirmation(this.options).show(); view = new PromptView.Confirmation(this.options).show();
expect(this.inFocusSpy).toHaveBeenCalled(); expect(this.inFocusSpy).toHaveBeenCalled();
return waitsFor( return ViewHelpers.verifyElementInFocus(view, ".wrapper-prompt")
function() { return view.$('.wrapper-prompt:focus').length === 1; },
"The modal should have focus",
500
);
}); });
it("is not focused on hide", function() { it("is not focused on hide", function() {
var view; var view;
view = new PromptView.Confirmation(this.options).hide(); view = new PromptView.Confirmation(this.options).hide();
expect(this.outFocusSpy).toHaveBeenCalled(); expect(this.outFocusSpy).toHaveBeenCalled();
return waitsFor( return ViewHelpers.verifyElementNotInFocus(view, ".wrapper-prompt")
function() { return view.$('.wrapper-prompt:focus').length === 0; },
"The modal should not have focus",
500
);
}); });
it("traps keyboard focus when moving forward", function() { it("traps keyboard focus when moving forward", function() {
var view; var view;
...@@ -161,11 +153,7 @@ ...@@ -161,11 +153,7 @@
"keydown", "keydown",
{ keyCode: $.simulate.keyCode.TAB } { keyCode: $.simulate.keyCode.TAB }
); );
return waitsFor( return ViewHelpers.verifyElementInFocus(view, ".action-primary")
function() { return view.$('.action-primary:focus').length === 1; },
"The first action button should have focus",
500
);
}); });
it("traps keyboard focus when moving backward", function() { it("traps keyboard focus when moving backward", function() {
var view; var view;
...@@ -175,11 +163,7 @@ ...@@ -175,11 +163,7 @@
"keydown", "keydown",
{ keyCode: $.simulate.keyCode.TAB, shiftKey: true } { keyCode: $.simulate.keyCode.TAB, shiftKey: true }
); );
return waitsFor( return ViewHelpers.verifyElementInFocus(view, ".action-secondary")
function() { return view.$('.action-secondary:focus').length === 1; },
"The last action button should have focus",
500
);
}); });
return it("changes class on body", function() { return it("changes class on body", function() {
var view; var view;
......
...@@ -10,7 +10,8 @@ define(["jquery", "common/js/components/views/feedback_notification", "common/js ...@@ -10,7 +10,8 @@ define(["jquery", "common/js/components/views/feedback_notification", "common/js
verifyFeedbackHidden, createNotificationSpy, verifyNotificationShowing, verifyFeedbackHidden, createNotificationSpy, verifyNotificationShowing,
verifyNotificationHidden, createPromptSpy, confirmPrompt, inlineEdit, verifyInlineEditChange, verifyNotificationHidden, createPromptSpy, confirmPrompt, inlineEdit, verifyInlineEditChange,
installMockAnalytics, removeMockAnalytics, verifyPromptShowing, verifyPromptHidden, installMockAnalytics, removeMockAnalytics, verifyPromptShowing, verifyPromptHidden,
clickDeleteItem, patchAndVerifyRequest, submitAndVerifyFormSuccess, submitAndVerifyFormError; clickDeleteItem, patchAndVerifyRequest, submitAndVerifyFormSuccess, submitAndVerifyFormError,
verifyElementInFocus, verifyElementNotInFocus;
installViewTemplates = function() { installViewTemplates = function() {
appendSetFixtures('<div id="page-notification"></div>'); appendSetFixtures('<div id="page-notification"></div>');
...@@ -127,6 +128,22 @@ define(["jquery", "common/js/components/views/feedback_notification", "common/js ...@@ -127,6 +128,22 @@ define(["jquery", "common/js/components/views/feedback_notification", "common/js
verifyNotificationShowing(notificationSpy, /Saving/); 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 { return {
'installViewTemplates': installViewTemplates, 'installViewTemplates': installViewTemplates,
'createNotificationSpy': createNotificationSpy, 'createNotificationSpy': createNotificationSpy,
...@@ -143,7 +160,9 @@ define(["jquery", "common/js/components/views/feedback_notification", "common/js ...@@ -143,7 +160,9 @@ define(["jquery", "common/js/components/views/feedback_notification", "common/js
'clickDeleteItem': clickDeleteItem, 'clickDeleteItem': clickDeleteItem,
'patchAndVerifyRequest': patchAndVerifyRequest, 'patchAndVerifyRequest': patchAndVerifyRequest,
'submitAndVerifyFormSuccess': submitAndVerifyFormSuccess, 'submitAndVerifyFormSuccess': submitAndVerifyFormSuccess,
'submitAndVerifyFormError': submitAndVerifyFormError 'submitAndVerifyFormError': submitAndVerifyFormError,
'verifyElementInFocus': verifyElementInFocus,
'verifyElementNotInFocus': verifyElementNotInFocus
}; };
}); });
}).call(this, define || RequireJS.define); }).call(this, define || RequireJS.define);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment