Skip to content

Commit

Permalink
Add acceptance test helper nativeClick and use it in modal assert hel…
Browse files Browse the repository at this point in the history
…pers.

A helper for firing native click events in acceptance tests for ember versions < 2.5.
  • Loading branch information
oscarni committed Oct 26, 2016
1 parent e1caf48 commit 5d59294
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tests/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"andThen",
"currentURL",
"currentPath",
"currentRouteName"
"currentRouteName",
"nativeClick"
],
"node": false,
"browser": false,
Expand Down
23 changes: 23 additions & 0 deletions tests/helpers/acceptance-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Ember from 'ember';

function fireNativeMouseEvent(eventType, selectorOrDomElement, context) {
let event = new window.Event(eventType, { bubbles: true, cancelable: true, view: window });
let target;
if (typeof selectorOrDomElement === 'string') {
target = Ember.$(selectorOrDomElement, context)[0];
} else {
target = selectorOrDomElement;
}
Ember.run(() => target.dispatchEvent(event));
}

export default function acceptanceTestHelpers() {

Ember.Test.registerAsyncHelper('nativeClick', function(app, selectorOrDomElement, context) {
fireNativeMouseEvent('click', selectorOrDomElement, context);
wait();
});

}

export default acceptanceTestHelpers();
4 changes: 2 additions & 2 deletions tests/helpers/modal-asserts.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export default function registerAssertHelpers() {
message = message || `Dialog triggered by ${options.openSelector} failed to open and close`;
const dialogContent = [dialogSelector, `:contains(${options.dialogText})`].join('');
const self = this;
return click(options.openSelector, options.context).then(function() {
return nativeClick(options.openSelector, options.context).then(function() {
if (options.hasOverlay) {
self.isPresentOnce(overlaySelector);
}
self.isPresentOnce(dialogContent);
if (options.whileOpen) {
options.whileOpen();
}
return click(options.closeSelector, options.context).then(function() {
return nativeClick(options.closeSelector, options.context).then(function() {
self.isAbsent(overlaySelector);
self.isAbsent(dialogContent);
});
Expand Down
1 change: 1 addition & 0 deletions tests/helpers/start-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
import registerAssertHelpers from './modal-asserts';
import './acceptance-helpers';

export default function startApp(attrs) {
let application;
Expand Down

0 comments on commit 5d59294

Please sign in to comment.