Skip to content

Commit b90b4b7

Browse files
wagenetgitKrystan
authored andcommitted
Add failing test for query param scoping
1 parent 9e39b0d commit b90b4b7

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
@@ -813,6 +813,50 @@ moduleFor(
813813
});
814814
}
815815

816+
['@test query params are based on actual model not on url params of lowest route only'](
817+
assert
818+
) {
819+
assert.expect(2);
820+
821+
this.router.map(function() {
822+
this.route('parent', { path: '/parent/:parent_id/' }, function() {
823+
this.route('child', { path: '/child/:child_id' });
824+
});
825+
});
826+
827+
let parentCache = {};
828+
let childCache = {};
829+
830+
this.add(
831+
'route:parent',
832+
Route.extend({
833+
model({ parent_id }) {
834+
return parentCache[parent_id] || (parentCache[parent_id] = { id: parent_id });
835+
},
836+
})
837+
);
838+
839+
this.add(
840+
'route:parent.child',
841+
Route.extend({
842+
model({ child_id }) {
843+
let parent = this.modelFor('parent');
844+
let id = `${parent.id}:${child_id}`;
845+
return childCache[id] || (childCache[id] = { id });
846+
},
847+
})
848+
);
849+
850+
this.setSingleQPController('parent.child', 'query', '');
851+
852+
return this.visitAndAssert('/parent/1/child/2?query=foo').then(() => {
853+
this.transitionTo('parent.child', { id: 2 }, { id: 2 });
854+
// Since Child { id: '2:2' } != Child { id: '1:2' } we should not have the same query
855+
// params even though the url param for the parent.child route matches.
856+
this.assertCurrentPath('/parent/2/child/2');
857+
});
858+
}
859+
816860
['@test can opt into a replace query by specifying replace:true in the Route config hash'](
817861
assert
818862
) {

0 commit comments

Comments
 (0)