Skip to content

Commit

Permalink
migrate visitable to action
Browse files Browse the repository at this point in the history
  • Loading branch information
ro0gr committed May 10, 2020
1 parent 692eb0d commit f5b582b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 49 deletions.
5 changes: 0 additions & 5 deletions addon-test-support/-private/execution_context/acceptance.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import $ from '-jquery';
import { run } from '../action';
import {
fillElement,
assertFocusable
Expand All @@ -20,10 +19,6 @@ AcceptanceExecutionContext.prototype = {
});
},

runAsync(cb) {
return run(this.pageObjectNode, {}, cb);
},

visit(path) {
/* global visit */
visit(path);
Expand Down
5 changes: 0 additions & 5 deletions addon-test-support/-private/execution_context/integration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import $ from '-jquery';
import { run } from '@ember/runloop';
import { run as runAction } from '../action';
import {
fillElement,
assertFocusable
Expand Down Expand Up @@ -28,10 +27,6 @@ IntegrationExecutionContext.prototype = {
return wait();
},

runAsync(cb) {
return runAction(this.pageObjectNode, {}, cb);
},

visit() {},

click(element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
blur
} from 'ember-native-dom-helpers';

import { run } from '../action';
import {
fillElement,
assertFocusable
Expand All @@ -27,10 +26,6 @@ ExecutionContext.prototype = {
'#ember-testing';
},

runAsync(cb) {
return run(this.pageObjectNode, {}, cb);
},

click(element) {
click(element);
},
Expand Down
5 changes: 0 additions & 5 deletions addon-test-support/-private/execution_context/rfc268.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { run } from '../action';
import {
getRootElement,
visit,
Expand All @@ -19,10 +18,6 @@ ExecutionContext.prototype = {
return getRootElement();
},

runAsync(cb) {
return run(this.pageObjectNode, {}, cb);
},

visit(path) {
return visit(path);
},
Expand Down
24 changes: 7 additions & 17 deletions addon-test-support/properties/visitable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assign } from '../-private/helpers';
import { getExecutionContext } from '../-private/execution_context';
import action from '../-private/action'

import $ from '-jquery';

Expand Down Expand Up @@ -90,22 +90,12 @@ function appendQueryParams(path, queryParams) {
* @throws Will throw an error if dynamic segments are not filled
*/
export function visitable(path) {
return {
isDescriptor: true,
return action(function(dynamicSegmentsAndQueryParams = {}) {
let params = assign({}, dynamicSegmentsAndQueryParams);
let fullPath = fillInDynamicSegments(path, params);

get() {
return function(dynamicSegmentsAndQueryParams = {}) {
let executionContext = getExecutionContext(this);
fullPath = appendQueryParams(fullPath, params);

return executionContext.runAsync((context) => {
let params = assign({}, dynamicSegmentsAndQueryParams);
let fullPath = fillInDynamicSegments(path, params);

fullPath = appendQueryParams(fullPath, params);

return context.visit(fullPath);
});
}
}
};
return this.visit(fullPath);
});
}
17 changes: 5 additions & 12 deletions tests/unit/-private/properties/visitable-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,12 @@ moduleForProperty('visitable', { needsVisit: true }, function(test) {
});

test("raises an exception if params aren't given for all dynamic segments", async function(assert) {
assert.expect(1);

let page;

try {
page = create({
foo: visitable('/users/:user_id')
});
let page = create({
foo: visitable('/users/:user_id')
});

await this.adapter.await(page.foo());
} catch(e) {
assert.equal(e.message, "Missing parameter for 'user_id'");
}
this.adapter.throws(assert, () => page.foo(), /Missing parameter for \'user_id\'/);
this.adapter.throws(assert, () => page.foo(), /page\.foo\(\)/);
});

test('appends query params to the path', async function(assert) {
Expand Down

0 comments on commit f5b582b

Please sign in to comment.