Skip to content

Commit

Permalink
ExecutionContext: triggerEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
ro0gr committed Oct 29, 2019
1 parent d712387 commit 2273504
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 30 deletions.
4 changes: 2 additions & 2 deletions addon-test-support/-private/execution_context/acceptance.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ AcceptanceExecutionContext.prototype = {
triggerEvent(element, 'change');
},

triggerEvent(selector, container, options, eventName, eventOptions) {
triggerEvent(element, eventName, eventOptions) {
/* global triggerEvent */
triggerEvent(selector, container, eventName, eventOptions);
triggerEvent(element, eventName, eventOptions);
},

focus(selector, options) {
Expand Down
8 changes: 2 additions & 6 deletions addon-test-support/-private/execution_context/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,10 @@ IntegrationExecutionContext.prototype = {
}
},

triggerEvent(selector, container, options, eventName, eventOptions) {
triggerEvent(element, eventName, eventOptions) {
let event = $.Event(eventName, eventOptions);

if (container) {
$(selector, container).trigger(event);
} else {
this.testContext.$(selector).trigger(event);
}
$(element).trigger(event);
},

focus(selector, options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ ExecutionContext.prototype = {
}
},

triggerEvent(selector, container, options, eventName, eventOptions) {
const element = this.$(selector, container)[0];

triggerEvent(element, eventName, eventOptions) {
// `keyCode` is a deprecated property.
// @see: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
// Due to this deprecation `ember-native-dom-helpers` doesn't accept `keyCode` as a `KeyboardEvent` option.
Expand Down
6 changes: 3 additions & 3 deletions addon-test-support/-private/execution_context/rfc268.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ ExecutionContext.prototype = {
return fillIn(selector, content);
},

triggerEvent(selector, container, options, eventName, eventOptions) {
triggerEvent(element, eventName, eventOptions) {
if (typeof eventOptions.key !== 'undefined' || typeof eventOptions.keyCode !== 'undefined') {
const key = eventOptions.key || eventOptions.keyCode;

return this.invokeHelper(selector, options, triggerKeyEvent, eventName, key, eventOptions);
return triggerKeyEvent(element, eventName, key, eventOptions);
}

return this.invokeHelper(selector, options, triggerEvent, eventName, eventOptions);
return triggerEvent(element, eventName, eventOptions);
},

focus(selector, options) {
Expand Down
24 changes: 8 additions & 16 deletions addon-test-support/properties/triggerable.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {
assign,
buildSelector,
findClosestValue
} from '../-private/helpers';
import { getExecutionContext } from '../-private/execution_context';
import { action } from '../extend/index';
import { assign } from '../-private/helpers';
import run from '../-private/run';

/**
*
Expand Down Expand Up @@ -88,18 +85,13 @@ export function triggerable(event, selector, userOptions = {}) {

get(key) {
return function(eventProperties = {}) {
const executionContext = getExecutionContext(this);
const options = assign({ pageObjectKey: `${key}()` }, userOptions);
const staticEventProperties = assign({}, options.eventProperties);
const mergedEventProperties = assign({}, options.eventProperties, eventProperties);

return executionContext.runAsync((context) => {
const fullSelector = buildSelector(this, selector, options);
const container = options.testContainer || findClosestValue(this, 'testContainer');

context.assertElementExists(fullSelector, options);

const mergedEventProperties = assign(staticEventProperties, eventProperties);
return context.triggerEvent(fullSelector, container, options, event, mergedEventProperties);
return run(this, ({ triggerEvent }) => {
return action(this, selector, options,
(element) => triggerEvent(element, event, mergedEventProperties)
)
});
};
}
Expand Down

0 comments on commit 2273504

Please sign in to comment.