Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import NoneLocation from '@ember/routing/none-location';
import { RouterTestCase, moduleFor } from 'internal-test-helpers';
import { RouterTestCase, moduleFor, runLoopSettled } from 'internal-test-helpers';
import { InternalTransition as Transition } from 'router_js';
import Controller from '@ember/controller';
import Route from '@ember/routing/route';

moduleFor(
'Router Service - replaceWith',
Expand Down Expand Up @@ -136,5 +137,45 @@ moduleFor(
assert.deepEqual(this.state, ['/', '/child']);
});
}

async ['@test RouterService#replaceWith with `refreshModel: true` query param does not always refresh'](
assert
) {
assert.expect(3);

let parentBeforeModelCount = 0;

this.add(
'route:parent',
Route.extend({
beforeModel() {
parentBeforeModelCount++;
},
queryParams: {
foo: {
refreshModel: true,
},
},
})
);

this.add(
'controller:parent',
Controller.extend({
queryParams: ['foo'],
foo: 'default',
})
);

await this.visit('/child');

assert.equal(parentBeforeModelCount, 1, 'parent.beforeModel called once');

this.routerService.replaceWith('parent.sister');
await runLoopSettled();

assert.equal(this.routerService.get('currentURL'), '/sister', 'transitioned');
assert.equal(parentBeforeModelCount, 1, 'parent.beforeModel still called only once');
}
}
);
143 changes: 142 additions & 1 deletion packages/ember/tests/routing/router_service_test/transitionTo_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import NoneLocation from '@ember/routing/none-location';
import Controller from '@ember/controller';
import { run } from '@ember/runloop';
import { get } from '@ember/object';
import { RouterTestCase, moduleFor } from 'internal-test-helpers';
import { RouterTestCase, moduleFor, runLoopSettled } from 'internal-test-helpers';
import { InternalTransition as Transition } from 'router_js';

moduleFor(
Expand Down Expand Up @@ -423,5 +423,146 @@ moduleFor(
assert.equal(this.routerService.get('currentURL'), '/?url_sort=a');
});
}

async ['@test RouterService#transitionTo with `refreshModel: true` query param does not always refresh'](
assert
) {
assert.expect(3);

let parentBeforeModelCount = 0;

this.add(
'route:parent',
Route.extend({
beforeModel() {
parentBeforeModelCount++;
},
queryParams: {
foo: {
refreshModel: true,
},
},
})
);

this.add(
'controller:parent',
Controller.extend({
queryParams: ['foo'],
foo: 'default',
})
);

await this.visit('/child');

assert.equal(parentBeforeModelCount, 1, 'parent.beforeModel called once');

this.routerService.transitionTo('parent.sister');
await runLoopSettled();

assert.equal(this.routerService.get('currentURL'), '/sister', 'transitioned');
assert.equal(parentBeforeModelCount, 1, 'parent.beforeModel still called only once');
}

async ['@test RouterService#transitionTo query param transition during initial transition'](
assert
) {
assert.expect(1);

let initialTransition = true;

this.add(
'route:parent',
Route.extend({
queryParams: {
foo: {
refreshModel: true,
},
},
})
);

this.add(
'controller:parent',
Controller.extend({
queryParams: ['foo'],
foo: 'default',
})
);

this.add(
'route:parent.child',
Route.extend({
routerService: service('router'),
afterModel() {
if (initialTransition) {
initialTransition = false;
this.routerService.transitionTo('parent.child', {
queryParams: {
foo: 'bar',
},
});
}
},
})
);

await this.visit('/child');

assert.equal(this.routerService.get('currentURL'), '/child?foo=bar');
}

async ['@test RouterService#transitionTo query param transition during later transition'](
assert
) {
assert.expect(2);

let initialTransition = true;

this.add(
'route:parent',
Route.extend({
queryParams: {
foo: {
refreshModel: true,
},
},
})
);

this.add(
'controller:parent',
Controller.extend({
queryParams: ['foo'],
foo: 'default',
})
);

this.add(
'route:parent.child',
Route.extend({
routerService: service('router'),
afterModel() {
if (initialTransition) {
initialTransition = false;
this.routerService.transitionTo('parent.child', {
queryParams: {
foo: 'bar',
},
});
}
},
})
);

await this.visit('/');

assert.equal(this.routerService.get('currentURL'), '/');

this.routerService.transitionTo('parent.child');
await runLoopSettled();

assert.equal(this.routerService.get('currentURL'), '/child?foo=bar');
}
}
);