Skip to content

Commit

Permalink
Backport/bugfix query params helpers pr #18458 issue #18076 (#18555)
Browse files Browse the repository at this point in the history
Backport/bugfix query params helpers pr #18458 issue #18076
  • Loading branch information
rwjblue authored Nov 17, 2019
2 parents 1b0c903 + e45ee5d commit 89a3c0b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
14 changes: 7 additions & 7 deletions packages/@ember/-internals/glimmer/lib/components/link-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,14 +864,14 @@ if (EMBER_GLIMMER_ANGLE_BRACKET_BUILT_INS) {
)
);

if (DEBUG && this.query === UNDEFINED) {
let { _models: models } = this;
let lastModel = models.length > 0 && models[models.length - 1];
let { _models: models } = this;
if (models.length > 0) {
let lastModel = models[models.length - 1];

assert(
'The `(query-params)` helper can only be used when invoking the `{{link-to}}` component.',
!(lastModel && lastModel.isQueryParams)
);
if (typeof lastModel === 'object' && lastModel !== null && lastModel.isQueryParams) {
this.query = lastModel.values;
models.pop();
}
}

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,23 @@ moduleFor(
});
}

async ['@feature(ember-glimmer-angle-bracket-built-ins) `(query-params)` must be used in conjunction with `{{link-to}}'](
assert
) {
['@test `(query-params)` can be used outside of `{{link-to}}'](assert) {
if (!DEBUG) {
assert.expect(0);
return;
}
this.addTemplate(
'index',
`{{#let (query-params foo='456' bar='NAW') as |qp|}}{{link-to 'Index' 'index' qp}}{{/let}}`
`{{#let (query-params foo='456' alon='BUKAI') as |qp|}}{{link-to 'Index' 'index' qp}}{{/let}}`
);

// TODO If we visit this page at all in production mode, it'll fail for
// entirely different reasons than what this test is trying to test.
let promise = DEBUG ? this.visit('/') : null;

await assert.rejectsAssertion(
promise,
/The `\(query-params\)` helper can only be used when invoking the `{{link-to}}` component\./
);
return this.visit('/').then(async () => {
this.assertComponentElement(this.firstChild, {
tagName: 'a',
attrs: { href: '/?alon=BUKAI&foo=456', class: classMatcher('ember-view') },
content: 'Index',
});
});
}
}
);
Expand Down

0 comments on commit 89a3c0b

Please sign in to comment.