Skip to content

Commit

Permalink
Merge pull request #17461 from emberjs/fix-substates
Browse files Browse the repository at this point in the history
[BUGFIX] Fix substate interactions with aborts
  • Loading branch information
chadhietala authored Jan 10, 2019
2 parents 1fd6f2a + 2b58f7a commit cf14c21
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 33 deletions.
62 changes: 29 additions & 33 deletions packages/ember/tests/routing/decoupled_basic_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,20 @@ moduleFor(
return this.applicationInstance.lookup(`controller:${name}`);
}

handleURLAborts(assert, path) {
handleURLAborts(assert, path, deprecated) {
run(() => {
let router = this.applicationInstance.lookup('router:main');
router.handleURL(path).then(
let result;

if (deprecated !== undefined) {
expectDeprecation(() => {
result = router.handleURL(path);
});
} else {
result = router.handleURL(path);
}

result.then(
function() {
assert.ok(false, 'url: `' + path + '` was NOT to be handled');
},
Expand Down Expand Up @@ -2749,33 +2759,15 @@ moduleFor(
}

['@test Router `willTransition` hook passes in cancellable transition'](assert) {
// Should hit willTransition 3 times, once for the initial route, and then 2 more times
// for the two handleURL calls below
if (EMBER_ROUTING_ROUTER_SERVICE) {
assert.expect(7);

this.router.reopen({
init() {
this._super(...arguments);
this.on('routeWillChange', transition => {
assert.ok(true, 'routeWillChange was called');
if (transition.intent && transition.intent.url !== '/') {
transition.abort();
}
});
},
});
} else {
assert.expect(5);
this.router.reopen({
willTransition(_, _2, transition) {
assert.ok(true, 'willTransition was called');
if (transition.intent.url !== '/') {
transition.abort();
}
},
});
}
assert.expect(8);
this.router.reopen({
willTransition(_, _2, transition) {
assert.ok(true, 'willTransition was called');
if (transition.intent.url !== '/') {
transition.abort();
}
},
});

this.router.map(function() {
this.route('nork');
Expand Down Expand Up @@ -2809,10 +2801,14 @@ moduleFor(
})
);

return this.visit('/').then(() => {
this.handleURLAborts(assert, '/nork');
this.handleURLAborts(assert, '/about');
});
let deprecation = /You attempted to override the "willTransition" method which is deprecated\./;

return expectDeprecation(() => {
return this.visit('/').then(() => {
this.handleURLAborts(assert, '/nork', deprecation);
this.handleURLAborts(assert, '/about', deprecation);
});
}, deprecation);
}

['@test Aborting/redirecting the transition in `willTransition` prevents LoadingRoute from being entered'](
Expand Down
22 changes: 22 additions & 0 deletions packages/ember/tests/routing/router_service_test/basic_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ moduleFor(
});
}

'@test substates survive aborts GH#17430'(assert) {
assert.expect(2);
this.add(
`route:parent.child`,
Route.extend({
beforeModel(transition) {
transition.abort();
this.intermediateTransitionTo('parent.sister');
},
})
);

return this.visit('/')
.then(() => {
return this.routerService.transitionTo('/child');
})
.catch(e => {
assert.equal(this.routerService.currentRouteName, 'parent.sister');
assert.equal(e.message, 'TransitionAborted');
});
}

['@test RouterService#currentRouteName is correctly set on each transition'](assert) {
if (EMBER_ROUTING_ROUTER_SERVICE) {
assert.expect(9);
Expand Down

0 comments on commit cf14c21

Please sign in to comment.