Skip to content

Commit

Permalink
Merge pull request #17467 from emberjs/substates-beta
Browse files Browse the repository at this point in the history
[BUGFIX beta] Fix substate interactions with aborts
  • Loading branch information
rwjblue committed Jan 10, 2019
2 parents 58160e1 + 58edec5 commit 24612b2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -148,7 +148,7 @@
"puppeteer": "^1.11.0",
"qunit": "^2.8.0",
"route-recognizer": "^0.3.4",
"router_js": "^6.2.1",
"router_js": "^6.2.2",
"rsvp": "^4.8.4",
"semver": "^5.5.0",
"serve-static": "^1.13.2",
Expand Down
62 changes: 29 additions & 33 deletions packages/ember/tests/routing/decoupled_basic_test.js
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
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
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -7441,10 +7441,10 @@ route-recognizer@^0.3.4:
resolved "https://registry.yarnpkg.com/route-recognizer/-/route-recognizer-0.3.4.tgz#39ab1ffbce1c59e6d2bdca416f0932611e4f3ca3"
integrity sha512-2+MhsfPhvauN1O8KaXpXAOfR/fwe8dnUXVM+xw7yt40lJRfPVQxV6yryZm0cgRvAj5fMF/mdRZbL2ptwbs5i2g==

router_js@^6.2.1:
version "6.2.1"
resolved "https://registry.yarnpkg.com/router_js/-/router_js-6.2.1.tgz#60130764ad3ed41592a41b9a0bb9133b3edc7d84"
integrity sha512-DL0FPuLZUkk7/mhIcXK3SO7215gyOVcQinPtdcLRHKJDt8GGqN6c0pNr0+vuE1IQX7QW1YyuIxBICZ0egzn8Dg==
router_js@^6.2.2:
version "6.2.2"
resolved "https://registry.yarnpkg.com/router_js/-/router_js-6.2.2.tgz#173fe28f004d437a150a42be8220a0341d8df4d8"
integrity sha512-gjNl8cxJYHXxLKe/BimTuXLANAb6AVIpK5nK4XvY5d5Do69RMr80YrNFmfHvgD31p0qXUDlz3+fcfAn7ylqIjg==
dependencies:
"@types/node" "^10.5.5"

Expand Down

0 comments on commit 24612b2

Please sign in to comment.