summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2017-04-21 16:32:10 +0100
committerPhil Hughes <me@iamphill.com>2017-04-21 16:32:10 +0100
commitf5f97359456bff5226f55f5338e01120ea90cbb8 (patch)
tree33977284fd549fe63b2946eac27eec155b5530f6
parentb8a96fda9c2a36aab6af603bf376fc97c19c2bca (diff)
downloadgitlab-ce-form-focus-previous-incorrect-form.tar.gz
Now correctly tests against different forms
-rw-r--r--spec/javascripts/shortcuts_spec.js34
1 files changed, 25 insertions, 9 deletions
diff --git a/spec/javascripts/shortcuts_spec.js b/spec/javascripts/shortcuts_spec.js
index 9dd7bc5b42c..9b8373df29e 100644
--- a/spec/javascripts/shortcuts_spec.js
+++ b/spec/javascripts/shortcuts_spec.js
@@ -1,29 +1,45 @@
/* global Shortcuts */
describe('Shortcuts', () => {
- const fixtureName = 'issues/open-issue.html.raw';
+ const fixtureName = 'issues/issue_with_comment.html.raw';
+ const createEvent = (type, target) => $.Event(type, {
+ target,
+ });
preloadFixtures(fixtureName);
describe('toggleMarkdownPreview', () => {
let sc;
- let event;
beforeEach(() => {
loadFixtures(fixtureName);
- spyOnEvent('.js-md-preview-button', 'focus');
-
- event = $.Event('', {
- target: document.querySelector('.js-note-text'),
- });
+ spyOnEvent('.js-new-note-form .js-md-preview-button', 'focus');
+ spyOnEvent('.edit-note .js-md-preview-button', 'focus');
sc = new Shortcuts();
});
it('focuses preview button in form', () => {
- sc.toggleMarkdownPreview(event);
+ sc.toggleMarkdownPreview(
+ createEvent('KeyboardEvent', document.querySelector('.js-new-note-form .js-note-text'),
+ ));
+
+ expect('focus').toHaveBeenTriggeredOn('.js-new-note-form .js-md-preview-button');
+ });
- expect('focus').toHaveBeenTriggeredOn('.js-md-preview-button');
+ it('focues preview button inside edit comment form', (done) => {
+ document.querySelector('.js-note-edit').click();
+
+ setTimeout(() => {
+ sc.toggleMarkdownPreview(
+ createEvent('KeyboardEvent', document.querySelector('.edit-note .js-note-text'),
+ ));
+
+ expect('focus').not.toHaveBeenTriggeredOn('.js-new-note-form .js-md-preview-button');
+ expect('focus').toHaveBeenTriggeredOn('.edit-note .js-md-preview-button');
+
+ done();
+ });
});
});
});