Skip to content

Commit 06da75b

Browse files
committed
Add failing test for query param scoping
1 parent 370cf34 commit 06da75b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

packages/ember/tests/routing/query_params_test.js

+44
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,50 @@ moduleFor(
870870
assert.equal(indexController.get('omg'), 'lol');
871871
}
872872

873+
['@test query params are based on actual model not on url params of lowest route only'](
874+
assert
875+
) {
876+
assert.expect(2);
877+
878+
this.router.map(function () {
879+
this.route('parent', { path: '/parent/:parent_id/' }, function () {
880+
this.route('child', { path: '/child/:child_id' });
881+
});
882+
});
883+
884+
let parentCache = {};
885+
let childCache = {};
886+
887+
this.add(
888+
'route:parent',
889+
Route.extend({
890+
model({ parent_id }) {
891+
return parentCache[parent_id] || (parentCache[parent_id] = { id: parent_id });
892+
},
893+
})
894+
);
895+
896+
this.add(
897+
'route:parent.child',
898+
Route.extend({
899+
model({ child_id }) {
900+
let parent = this.modelFor('parent');
901+
let id = `${parent.id}:${child_id}`;
902+
return childCache[id] || (childCache[id] = { id });
903+
},
904+
})
905+
);
906+
907+
this.setSingleQPController('parent.child', 'query', '');
908+
909+
return this.visitAndAssert('/parent/1/child/2?query=foo').then(() => {
910+
this.transitionTo('parent.child', { id: 2 }, { id: 2 });
911+
// Since Child { id: '2:2' } != Child { id: '1:2' } we should not have the same query
912+
// params even though the url param for the parent.child route matches.
913+
this.assertCurrentPath('/parent/2/child/2');
914+
});
915+
}
916+
873917
async ['@test can opt into a replace query by specifying replace:true in the Route config hash'](
874918
assert
875919
) {

0 commit comments

Comments
 (0)