Skip to content

Commit

Permalink
define shape of the run('s this
Browse files Browse the repository at this point in the history
  • Loading branch information
ro0gr committed May 10, 2020
1 parent f5b582b commit 20869f0
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 13 deletions.
15 changes: 9 additions & 6 deletions addon-test-support/-private/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ export default function action(query, cb) {
* @param {Function} cb Some async activity callback
* @returns {Ceibo}
*/
export function run(node, query, cb) {
function run(node, query, cb) {
const adapter = getExecutionContext(node);
adapter.query = query;
adapter.node = adapter.pageObjectNode;
const executionContext = Object.freeze({
query,
node,
adapter
});

const chainedRoot = getRoot(node)._chainedTree;

Expand All @@ -66,21 +69,21 @@ export function run(node, query, cb) {
// chanined VS independent action invocations. Awaiting for the previous
// action settlement, before invoke a new action, is a part of
// the legacy testing helpers adapters for backward compat reasons
chainedRoot._promise = adapter.andThen(cb);
chainedRoot._promise = adapter.andThen.bind(executionContext)(cb);

return node;
} else if (!chainedRoot) {
// Our root is already the root of the chained tree,
// we need to wait on its promise if it has one so the
// previous invocations can resolve before we run ours.
let root = getRoot(node)
root._promise = resolve(root._promise).then(() => cb(adapter));
root._promise = resolve(root._promise).then(() => cb(executionContext));

return node;
} else {
// Store our invocation result on the chained root
// so that chained calls can find it to wait on it.
chainedRoot._promise = cb(adapter);
chainedRoot._promise = cb(executionContext);

return chainable(node);
}
Expand Down
2 changes: 1 addition & 1 deletion addon-test-support/properties/blurrable.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function blurrable(selector = '', userOptions = {}) {
return action(assign({}, userOptions, { selector }), function() {
const element = findOne(this.node, this.query.selector, this.query);

return this.blur(element);
return this.adapter.blur(element);
});
}

2 changes: 1 addition & 1 deletion addon-test-support/properties/click-on-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ export function clickOnText(scope, userOptions = {}) {

const element = findOne(this.node, selector, this.query);

return this.click(element);
return this.adapter.click(element);
});
}
2 changes: 1 addition & 1 deletion addon-test-support/properties/clickable.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ export function clickable(selector, userOptions = {}) {
return action(assign({}, userOptions, { selector }), function() {
const element = findOne(this.node, this.query.selector, this.query);

return this.click(element);
return this.adapter.click(element);
});
}
2 changes: 1 addition & 1 deletion addon-test-support/properties/fillable.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function fillable(selector = '', userOptions = {}) {

const element = findOne(this.node, scopeSelector, this.query);

return this.fillIn(element, content);
return this.adapter.fillIn(element, content);
});
}

Expand Down
2 changes: 1 addition & 1 deletion addon-test-support/properties/focusable.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ export function focusable(selector = '', userOptions = {}) {
return action(query, function() {
const element = findOne(this.node, this.query.selector, this.query);

return this.focus(element);
return this.adapter.focus(element);
});
}
2 changes: 1 addition & 1 deletion addon-test-support/properties/triggerable.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function triggerable(event, selector, userOptions = {}) {

const element = findOne(this.node, this.query.selector, this.query);

return this.triggerEvent(element, event, mergedEventProperties);
return this.adapter.triggerEvent(element, event, mergedEventProperties);
});
}

2 changes: 1 addition & 1 deletion addon-test-support/properties/visitable.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ export function visitable(path) {

fullPath = appendQueryParams(fullPath, params);

return this.visit(fullPath);
return this.adapter.visit(fullPath);
});
}
16 changes: 16 additions & 0 deletions tests/unit/-private/action-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ if (require.has('@ember/test-helpers')) {
assert.deepEqual(finished, [1]);
});

test('this is frozen', async function(assert) {
const p = create({
scope: 'it works',

run: action(function() {
executionContext = this;
})
});

await p.run();

assert.throws(() => {
executionContext.test = 1;
})
});

test('it handles sync errors', async function(assert) {
const p = create({
scope: '.Scope',
Expand Down

0 comments on commit 20869f0

Please sign in to comment.