From 0f95c777fe507940f2922e6d256125677d5bb882 Mon Sep 17 00:00:00 2001 From: Chad Hietala Date: Wed, 3 Oct 2018 09:41:54 -0400 Subject: [PATCH] Remove old Router Service FF This removes the FF around all the router service features that were go'd earlier this year. It also reuses the same flag to guard the new features that we are adding. --- .../@ember/application/lib/application.js | 7 +- packages/@ember/canary-features/index.ts | 2 +- .../tests/routing/decoupled_basic_test.js | 54 +- .../routing/deprecated_handler_infos_test.js | 8 +- .../routing/router_service_test/basic_test.js | 158 +++-- .../currenturl_lifecycle_test.js | 262 ++++--- .../router_service_test/isActive_test.js | 214 +++--- .../router_service_test/replaceWith_test.js | 270 ++++---- .../router_service_test/transitionTo_test.js | 644 +++++++++--------- .../router_service_test/urlFor_test.js | 474 +++++++------ 10 files changed, 1043 insertions(+), 1050 deletions(-) diff --git a/packages/@ember/application/lib/application.js b/packages/@ember/application/lib/application.js index b7cbe6ea168..2f59927c35f 100644 --- a/packages/@ember/application/lib/application.js +++ b/packages/@ember/application/lib/application.js @@ -30,7 +30,6 @@ import Engine from '@ember/engine'; import { privatize as P } from '@ember/-internals/container'; import { setupApplicationRegistry } from '@ember/-internals/glimmer'; import { RouterService } from '@ember/-internals/routing'; -import { EMBER_ROUTING_ROUTER_SERVICE } from '@ember/canary-features'; let librariesRegistered = false; @@ -1124,10 +1123,8 @@ function commonSetupRegistry(registry) { }, }); - if (EMBER_ROUTING_ROUTER_SERVICE) { - registry.register('service:router', RouterService); - registry.injection('service:router', '_router', 'router:main'); - } + registry.register('service:router', RouterService); + registry.injection('service:router', '_router', 'router:main'); } function registerLibraries() { diff --git a/packages/@ember/canary-features/index.ts b/packages/@ember/canary-features/index.ts index 07627d4a9ed..dc5ee4698b7 100644 --- a/packages/@ember/canary-features/index.ts +++ b/packages/@ember/canary-features/index.ts @@ -10,7 +10,7 @@ export const DEFAULT_FEATURES = { EMBER_LIBRARIES_ISREGISTERED: null, EMBER_IMPROVED_INSTRUMENTATION: null, EMBER_GLIMMER_NAMED_ARGUMENTS: true, - EMBER_ROUTING_ROUTER_SERVICE: true, + EMBER_ROUTING_ROUTER_SERVICE: null, EMBER_ENGINES_MOUNT_PARAMS: true, EMBER_MODULE_UNIFICATION: null, GLIMMER_CUSTOM_COMPONENT_MANAGER: true, diff --git a/packages/ember/tests/routing/decoupled_basic_test.js b/packages/ember/tests/routing/decoupled_basic_test.js index 6b083268997..a65e437f152 100644 --- a/packages/ember/tests/routing/decoupled_basic_test.js +++ b/packages/ember/tests/routing/decoupled_basic_test.js @@ -12,6 +12,7 @@ import { getTextOf } from 'internal-test-helpers'; import { Component } from '@ember/-internals/glimmer'; import Engine from '@ember/engine'; import { InternalTransition as Transition } from 'router_js'; +import { EMBER_ROUTING_ROUTER_SERVICE } from '@ember/canary-features'; let originalConsoleError; @@ -2750,22 +2751,37 @@ 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 - assert.expect(5); + 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(); + } + }, + }); + } this.router.map(function() { this.route('nork'); this.route('about'); }); - this.router.reopen({ - willTransition(_, _2, transition) { - assert.ok(true, 'willTransition was called'); - if (transition.intent.url !== '/') { - transition.abort(); - } - }, - }); - this.add( 'route:loading', Route.extend({ @@ -2922,13 +2938,17 @@ moduleFor( this.router.map(function() { this.route('nork'); }); - - this.router.reopen({ - didTransition() { - this._super(...arguments); - assert.ok(true, 'reopened didTransition was called'); - }, - }); + if (EMBER_ROUTING_ROUTER_SERVICE) { + assert.ok(true, 'no longer a valid test'); + return; + } else { + this.router.reopen({ + didTransition() { + this._super(...arguments); + assert.ok(true, 'reopened didTransition was called'); + }, + }); + } return this.visit('/'); } diff --git a/packages/ember/tests/routing/deprecated_handler_infos_test.js b/packages/ember/tests/routing/deprecated_handler_infos_test.js index 8bbc61121da..a650619edd6 100644 --- a/packages/ember/tests/routing/deprecated_handler_infos_test.js +++ b/packages/ember/tests/routing/deprecated_handler_infos_test.js @@ -60,9 +60,11 @@ if (EMBER_ROUTING_ROUTER_SERVICE) { '@test handlerInfos are deprecated and associated private apis'(assert) { let done = assert.async(); - return this.visit('/parent').then(() => { - done(); - }); + expectDeprecation(() => { + return this.visit('/parent').then(() => { + done(); + }); + }, /You attempted to override the \"(willTransition|didTransition)\" method which is deprecated. Please inject the router service and listen to the \"(routeWillChange|routeDidChange)\" event\./); } } ); diff --git a/packages/ember/tests/routing/router_service_test/basic_test.js b/packages/ember/tests/routing/router_service_test/basic_test.js index d1e05a1a710..1fa50a116ae 100644 --- a/packages/ember/tests/routing/router_service_test/basic_test.js +++ b/packages/ember/tests/routing/router_service_test/basic_test.js @@ -2,94 +2,90 @@ import { Route, NoneLocation } from '@ember/-internals/routing'; import { set } from '@ember/-internals/metal'; import { RouterTestCase, moduleFor } from 'internal-test-helpers'; -import { EMBER_ROUTING_ROUTER_SERVICE } from '@ember/canary-features'; +moduleFor( + 'Router Service - main', + class extends RouterTestCase { + ['@test RouterService#currentRouteName is correctly set for top level route'](assert) { + assert.expect(1); + + return this.visit('/').then(() => { + assert.equal(this.routerService.get('currentRouteName'), 'parent.index'); + }); + } + + ['@test RouterService#currentRouteName is correctly set for child route'](assert) { + assert.expect(1); + + return this.visit('/child').then(() => { + assert.equal(this.routerService.get('currentRouteName'), 'parent.child'); + }); + } -if (EMBER_ROUTING_ROUTER_SERVICE) { - moduleFor( - 'Router Service - main', - class extends RouterTestCase { - ['@test RouterService#currentRouteName is correctly set for top level route'](assert) { - assert.expect(1); + ['@test RouterService#currentRouteName is correctly set after transition'](assert) { + assert.expect(1); - return this.visit('/').then(() => { - assert.equal(this.routerService.get('currentRouteName'), 'parent.index'); + return this.visit('/child') + .then(() => { + return this.routerService.transitionTo('parent.sister'); + }) + .then(() => { + assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); }); - } + } - ['@test RouterService#currentRouteName is correctly set for child route'](assert) { - assert.expect(1); + ['@test RouterService#currentRouteName is correctly set on each transition'](assert) { + assert.expect(3); - return this.visit('/child').then(() => { + return this.visit('/child') + .then(() => { assert.equal(this.routerService.get('currentRouteName'), 'parent.child'); - }); - } - - ['@test RouterService#currentRouteName is correctly set after transition'](assert) { - assert.expect(1); - - return this.visit('/child') - .then(() => { - return this.routerService.transitionTo('parent.sister'); - }) - .then(() => { - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); - }); - } - - ['@test RouterService#currentRouteName is correctly set on each transition'](assert) { - assert.expect(3); - - return this.visit('/child') - .then(() => { - assert.equal(this.routerService.get('currentRouteName'), 'parent.child'); - - return this.visit('/sister'); - }) - .then(() => { - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); - - return this.visit('/brother'); - }) - .then(() => { - assert.equal(this.routerService.get('currentRouteName'), 'parent.brother'); - }); - } - - ['@test RouterService#rootURL is correctly set to the default value'](assert) { - assert.expect(1); - - return this.visit('/').then(() => { - assert.equal(this.routerService.get('rootURL'), '/'); - }); - } - - ['@test RouterService#rootURL is correctly set to a custom value'](assert) { - assert.expect(1); - - this.add( - 'route:parent.index', - Route.extend({ - init() { - this._super(); - set(this._router, 'rootURL', '/homepage'); - }, - }) - ); - - return this.visit('/').then(() => { - assert.equal(this.routerService.get('rootURL'), '/homepage'); - }); - } - ['@test RouterService#location is correctly delegated from router:main'](assert) { - assert.expect(2); + return this.visit('/sister'); + }) + .then(() => { + assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); - return this.visit('/').then(() => { - let location = this.routerService.get('location'); - assert.ok(location); - assert.ok(location instanceof NoneLocation); + return this.visit('/brother'); + }) + .then(() => { + assert.equal(this.routerService.get('currentRouteName'), 'parent.brother'); }); - } } - ); -} + + ['@test RouterService#rootURL is correctly set to the default value'](assert) { + assert.expect(1); + + return this.visit('/').then(() => { + assert.equal(this.routerService.get('rootURL'), '/'); + }); + } + + ['@test RouterService#rootURL is correctly set to a custom value'](assert) { + assert.expect(1); + + this.add( + 'route:parent.index', + Route.extend({ + init() { + this._super(); + set(this._router, 'rootURL', '/homepage'); + }, + }) + ); + + return this.visit('/').then(() => { + assert.equal(this.routerService.get('rootURL'), '/homepage'); + }); + } + + ['@test RouterService#location is correctly delegated from router:main'](assert) { + assert.expect(2); + + return this.visit('/').then(() => { + let location = this.routerService.get('location'); + assert.ok(location); + assert.ok(location instanceof NoneLocation); + }); + } + } +); diff --git a/packages/ember/tests/routing/router_service_test/currenturl_lifecycle_test.js b/packages/ember/tests/routing/router_service_test/currenturl_lifecycle_test.js index 89acdb19b9b..5fa5a355d60 100644 --- a/packages/ember/tests/routing/router_service_test/currenturl_lifecycle_test.js +++ b/packages/ember/tests/routing/router_service_test/currenturl_lifecycle_test.js @@ -5,145 +5,141 @@ import { Route } from '@ember/-internals/routing'; import { get } from '@ember/-internals/metal'; import { RouterTestCase, moduleFor } from 'internal-test-helpers'; -import { EMBER_ROUTING_ROUTER_SERVICE } from '@ember/canary-features'; - -if (EMBER_ROUTING_ROUTER_SERVICE) { - let results = []; - let ROUTE_NAMES = ['index', 'child', 'sister', 'brother']; - - let InstrumentedRoute = Route.extend({ - routerService: injectService('router'), - - beforeModel() { - let service = get(this, 'routerService'); - results.push([service.get('currentRouteName'), 'beforeModel', service.get('currentURL')]); - }, - - model() { - let service = get(this, 'routerService'); - results.push([service.get('currentRouteName'), 'model', service.get('currentURL')]); - }, - - afterModel() { - let service = get(this, 'routerService'); - results.push([service.get('currentRouteName'), 'afterModel', service.get('currentURL')]); - }, - }); - - moduleFor( - 'Router Service - currentURL', - class extends RouterTestCase { - constructor() { - super(...arguments); - - results = []; - - ROUTE_NAMES.forEach(name => { - let routeName = `parent.${name}`; - this.add(`route:${routeName}`, InstrumentedRoute.extend()); - this.addTemplate(routeName, '{{current-url}}'); - }); +let results = []; +let ROUTE_NAMES = ['index', 'child', 'sister', 'brother']; + +let InstrumentedRoute = Route.extend({ + routerService: injectService('router'), + + beforeModel() { + let service = get(this, 'routerService'); + results.push([service.get('currentRouteName'), 'beforeModel', service.get('currentURL')]); + }, + + model() { + let service = get(this, 'routerService'); + results.push([service.get('currentRouteName'), 'model', service.get('currentURL')]); + }, + + afterModel() { + let service = get(this, 'routerService'); + results.push([service.get('currentRouteName'), 'afterModel', service.get('currentURL')]); + }, +}); + +moduleFor( + 'Router Service - currentURL', + class extends RouterTestCase { + constructor() { + super(...arguments); + + results = []; + + ROUTE_NAMES.forEach(name => { + let routeName = `parent.${name}`; + this.add(`route:${routeName}`, InstrumentedRoute.extend()); + this.addTemplate(routeName, '{{current-url}}'); + }); + + this.addComponent('current-url', { + ComponentClass: Component.extend({ + routerService: injectService('router'), + currentURL: readOnly('routerService.currentURL'), + }), + template: '{{currentURL}}', + }); + } - this.addComponent('current-url', { - ComponentClass: Component.extend({ - routerService: injectService('router'), - currentURL: readOnly('routerService.currentURL'), - }), - template: '{{currentURL}}', - }); - } + ['@test RouterService#currentURL is correctly set for top level route'](assert) { + assert.expect(1); + + return this.visit('/').then(() => { + assert.equal(this.routerService.get('currentURL'), '/'); + }); + } - ['@test RouterService#currentURL is correctly set for top level route'](assert) { - assert.expect(1); + ['@test RouterService#currentURL is correctly set for child route'](assert) { + assert.expect(1); - return this.visit('/').then(() => { - assert.equal(this.routerService.get('currentURL'), '/'); + return this.visit('/child').then(() => { + assert.equal(this.routerService.get('currentURL'), '/child'); + }); + } + + ['@test RouterService#currentURL is correctly set after transition'](assert) { + assert.expect(1); + + return this.visit('/child') + .then(() => { + return this.routerService.transitionTo('parent.sister'); + }) + .then(() => { + assert.equal(this.routerService.get('currentURL'), '/sister'); }); - } + } - ['@test RouterService#currentURL is correctly set for child route'](assert) { - assert.expect(1); + ['@test RouterService#currentURL is correctly set on each transition'](assert) { + assert.expect(3); - return this.visit('/child').then(() => { + return this.visit('/child') + .then(() => { assert.equal(this.routerService.get('currentURL'), '/child'); + + return this.visit('/sister'); + }) + .then(() => { + assert.equal(this.routerService.get('currentURL'), '/sister'); + + return this.visit('/brother'); + }) + .then(() => { + assert.equal(this.routerService.get('currentURL'), '/brother'); + }); + } + + ['@test RouterService#currentURL is not set during lifecycle hooks'](assert) { + assert.expect(2); + + return this.visit('/') + .then(() => { + assert.deepEqual(results, [ + [null, 'beforeModel', null], + [null, 'model', null], + [null, 'afterModel', null], + ]); + + results = []; + + return this.visit('/child'); + }) + .then(() => { + assert.deepEqual(results, [ + ['parent.index', 'beforeModel', '/'], + ['parent.index', 'model', '/'], + ['parent.index', 'afterModel', '/'], + ]); + }); + } + + ['@test RouterService#currentURL is correctly set with component after consecutive visits']( + assert + ) { + assert.expect(3); + + return this.visit('/') + .then(() => { + this.assertText('/'); + + return this.visit('/child'); + }) + .then(() => { + this.assertText('/child'); + + return this.visit('/'); + }) + .then(() => { + this.assertText('/'); }); - } - - ['@test RouterService#currentURL is correctly set after transition'](assert) { - assert.expect(1); - - return this.visit('/child') - .then(() => { - return this.routerService.transitionTo('parent.sister'); - }) - .then(() => { - assert.equal(this.routerService.get('currentURL'), '/sister'); - }); - } - - ['@test RouterService#currentURL is correctly set on each transition'](assert) { - assert.expect(3); - - return this.visit('/child') - .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child'); - - return this.visit('/sister'); - }) - .then(() => { - assert.equal(this.routerService.get('currentURL'), '/sister'); - - return this.visit('/brother'); - }) - .then(() => { - assert.equal(this.routerService.get('currentURL'), '/brother'); - }); - } - - ['@test RouterService#currentURL is not set during lifecycle hooks'](assert) { - assert.expect(2); - - return this.visit('/') - .then(() => { - assert.deepEqual(results, [ - [null, 'beforeModel', null], - [null, 'model', null], - [null, 'afterModel', null], - ]); - - results = []; - - return this.visit('/child'); - }) - .then(() => { - assert.deepEqual(results, [ - ['parent.index', 'beforeModel', '/'], - ['parent.index', 'model', '/'], - ['parent.index', 'afterModel', '/'], - ]); - }); - } - - ['@test RouterService#currentURL is correctly set with component after consecutive visits']( - assert - ) { - assert.expect(3); - - return this.visit('/') - .then(() => { - this.assertText('/'); - - return this.visit('/child'); - }) - .then(() => { - this.assertText('/child'); - - return this.visit('/'); - }) - .then(() => { - this.assertText('/'); - }); - } } - ); -} + } +); diff --git a/packages/ember/tests/routing/router_service_test/isActive_test.js b/packages/ember/tests/routing/router_service_test/isActive_test.js index 1b1c203dde3..0fec62fcaa2 100644 --- a/packages/ember/tests/routing/router_service_test/isActive_test.js +++ b/packages/ember/tests/routing/router_service_test/isActive_test.js @@ -1,113 +1,109 @@ import Controller from '@ember/controller'; import { RouterTestCase, moduleFor } from 'internal-test-helpers'; -import { EMBER_ROUTING_ROUTER_SERVICE } from '@ember/canary-features'; - -if (EMBER_ROUTING_ROUTER_SERVICE) { - moduleFor( - 'Router Service - isActive', - class extends RouterTestCase { - ['@test RouterService#isActive returns true for simple route'](assert) { - assert.expect(1); - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('parent.child'); - }) - .then(() => { - return this.routerService.transitionTo('parent.sister'); - }) - .then(() => { - assert.ok(this.routerService.isActive('parent.sister')); - }); - } - - ['@test RouterService#isActive returns true for simple route with dynamic segments'](assert) { - assert.expect(1); - - let dynamicModel = { id: 1 }; - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('dynamic', dynamicModel); - }) - .then(() => { - assert.ok(this.routerService.isActive('dynamic', dynamicModel)); - }); - } - - ['@test RouterService#isActive does not eagerly instantiate controller for query params']( - assert - ) { - assert.expect(1); - - let queryParams = this.buildQueryParams({ sort: 'ASC' }); - - this.add( - 'controller:parent.sister', - Controller.extend({ - queryParams: ['sort'], - sort: 'ASC', - - init() { - assert.ok(false, 'should never create'); - this._super(...arguments); - }, - }) - ); - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('parent.brother'); - }) - .then(() => { - assert.notOk(this.routerService.isActive('parent.sister', queryParams)); - }); - } - - ['@test RouterService#isActive is correct for simple route with basic query params'](assert) { - assert.expect(2); - - let queryParams = this.buildQueryParams({ sort: 'ASC' }); - - this.add( - 'controller:parent.child', - Controller.extend({ - queryParams: ['sort'], - sort: 'ASC', - }) - ); - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('parent.child', queryParams); - }) - .then(() => { - assert.ok(this.routerService.isActive('parent.child', queryParams)); - assert.notOk( - this.routerService.isActive('parent.child', this.buildQueryParams({ sort: 'DESC' })) - ); - }); - } - - ['@test RouterService#isActive for simple route with array as query params'](assert) { - assert.expect(1); - - let queryParams = this.buildQueryParams({ sort: ['ascending'] }); - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('parent.child', queryParams); - }) - .then(() => { - assert.notOk( - this.routerService.isActive( - 'parent.child', - this.buildQueryParams({ sort: 'descending' }) - ) - ); - }); - } +moduleFor( + 'Router Service - isActive', + class extends RouterTestCase { + ['@test RouterService#isActive returns true for simple route'](assert) { + assert.expect(1); + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('parent.child'); + }) + .then(() => { + return this.routerService.transitionTo('parent.sister'); + }) + .then(() => { + assert.ok(this.routerService.isActive('parent.sister')); + }); } - ); -} + + ['@test RouterService#isActive returns true for simple route with dynamic segments'](assert) { + assert.expect(1); + + let dynamicModel = { id: 1 }; + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('dynamic', dynamicModel); + }) + .then(() => { + assert.ok(this.routerService.isActive('dynamic', dynamicModel)); + }); + } + + ['@test RouterService#isActive does not eagerly instantiate controller for query params']( + assert + ) { + assert.expect(1); + + let queryParams = this.buildQueryParams({ sort: 'ASC' }); + + this.add( + 'controller:parent.sister', + Controller.extend({ + queryParams: ['sort'], + sort: 'ASC', + + init() { + assert.ok(false, 'should never create'); + this._super(...arguments); + }, + }) + ); + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('parent.brother'); + }) + .then(() => { + assert.notOk(this.routerService.isActive('parent.sister', queryParams)); + }); + } + + ['@test RouterService#isActive is correct for simple route with basic query params'](assert) { + assert.expect(2); + + let queryParams = this.buildQueryParams({ sort: 'ASC' }); + + this.add( + 'controller:parent.child', + Controller.extend({ + queryParams: ['sort'], + sort: 'ASC', + }) + ); + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('parent.child', queryParams); + }) + .then(() => { + assert.ok(this.routerService.isActive('parent.child', queryParams)); + assert.notOk( + this.routerService.isActive('parent.child', this.buildQueryParams({ sort: 'DESC' })) + ); + }); + } + + ['@test RouterService#isActive for simple route with array as query params'](assert) { + assert.expect(1); + + let queryParams = this.buildQueryParams({ sort: ['ascending'] }); + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('parent.child', queryParams); + }) + .then(() => { + assert.notOk( + this.routerService.isActive( + 'parent.child', + this.buildQueryParams({ sort: 'descending' }) + ) + ); + }); + } + } +); diff --git a/packages/ember/tests/routing/router_service_test/replaceWith_test.js b/packages/ember/tests/routing/router_service_test/replaceWith_test.js index 8589b431644..a1ca0bca866 100644 --- a/packages/ember/tests/routing/router_service_test/replaceWith_test.js +++ b/packages/ember/tests/routing/router_service_test/replaceWith_test.js @@ -3,142 +3,138 @@ import { RouterTestCase, moduleFor } from 'internal-test-helpers'; import { InternalTransition as Transition } from 'router_js'; import Controller from '@ember/controller'; -import { EMBER_ROUTING_ROUTER_SERVICE } from '@ember/canary-features'; - -if (EMBER_ROUTING_ROUTER_SERVICE) { - moduleFor( - 'Router Service - replaceWith', - class extends RouterTestCase { - constructor() { - super(...arguments); - - let testCase = this; - testCase.state = []; - - this.add( - 'location:test', - NoneLocation.extend({ - setURL(path) { - testCase.state.push(path); - this.set('path', path); - }, - - replaceURL(path) { - testCase.state.splice(testCase.state.length - 1, 1, path); - this.set('path', path); - }, - }) - ); - } - - get routerOptions() { - return { - location: 'test', - }; - } - - ['@test RouterService#replaceWith returns a Transition'](assert) { - assert.expect(1); - - let transition; - - return this.visit('/').then(() => { - transition = this.routerService.replaceWith('parent.child'); - - assert.ok(transition instanceof Transition); - - return transition; +moduleFor( + 'Router Service - replaceWith', + class extends RouterTestCase { + constructor() { + super(...arguments); + + let testCase = this; + testCase.state = []; + + this.add( + 'location:test', + NoneLocation.extend({ + setURL(path) { + testCase.state.push(path); + this.set('path', path); + }, + + replaceURL(path) { + testCase.state.splice(testCase.state.length - 1, 1, path); + this.set('path', path); + }, + }) + ); + } + + get routerOptions() { + return { + location: 'test', + }; + } + + ['@test RouterService#replaceWith returns a Transition'](assert) { + assert.expect(1); + + let transition; + + return this.visit('/').then(() => { + transition = this.routerService.replaceWith('parent.child'); + + assert.ok(transition instanceof Transition); + + return transition; + }); + } + + ['@test RouterService#replaceWith with basic route replaces location'](assert) { + assert.expect(1); + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('parent.child'); + }) + .then(() => { + return this.routerService.transitionTo('parent.sister'); + }) + .then(() => { + return this.routerService.replaceWith('parent.brother'); + }) + .then(() => { + assert.deepEqual(this.state, ['/', '/child', '/brother']); + }); + } + + ['@test RouterService#replaceWith with basic route using URLs replaces location'](assert) { + assert.expect(1); + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('/child'); + }) + .then(() => { + return this.routerService.transitionTo('/sister'); + }) + .then(() => { + return this.routerService.replaceWith('/brother'); + }) + .then(() => { + assert.deepEqual(this.state, ['/', '/child', '/brother']); + }); + } + + ['@test RouterService#replaceWith transitioning back to previously visited route replaces location']( + assert + ) { + assert.expect(1); + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('parent.child'); + }) + .then(() => { + return this.routerService.transitionTo('parent.sister'); + }) + .then(() => { + return this.routerService.transitionTo('parent.brother'); + }) + .then(() => { + return this.routerService.replaceWith('parent.sister'); + }) + .then(() => { + assert.deepEqual(this.state, ['/', '/child', '/sister', '/sister']); + }); + } + + ['@test RouterService#replaceWith with basic query params does not remove query param defaults']( + assert + ) { + assert.expect(1); + + this.add( + 'controller:parent.child', + Controller.extend({ + queryParams: ['sort'], + sort: 'ASC', + }) + ); + + let queryParams = this.buildQueryParams({ sort: 'ASC' }); + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('parent.brother'); + }) + .then(() => { + return this.routerService.replaceWith('parent.sister'); + }) + .then(() => { + return this.routerService.replaceWith('parent.child', queryParams); + }) + .then(() => { + assert.deepEqual(this.state, ['/', '/child?sort=ASC']); }); - } - - ['@test RouterService#replaceWith with basic route replaces location'](assert) { - assert.expect(1); - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('parent.child'); - }) - .then(() => { - return this.routerService.transitionTo('parent.sister'); - }) - .then(() => { - return this.routerService.replaceWith('parent.brother'); - }) - .then(() => { - assert.deepEqual(this.state, ['/', '/child', '/brother']); - }); - } - - ['@test RouterService#replaceWith with basic route using URLs replaces location'](assert) { - assert.expect(1); - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('/child'); - }) - .then(() => { - return this.routerService.transitionTo('/sister'); - }) - .then(() => { - return this.routerService.replaceWith('/brother'); - }) - .then(() => { - assert.deepEqual(this.state, ['/', '/child', '/brother']); - }); - } - - ['@test RouterService#replaceWith transitioning back to previously visited route replaces location']( - assert - ) { - assert.expect(1); - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('parent.child'); - }) - .then(() => { - return this.routerService.transitionTo('parent.sister'); - }) - .then(() => { - return this.routerService.transitionTo('parent.brother'); - }) - .then(() => { - return this.routerService.replaceWith('parent.sister'); - }) - .then(() => { - assert.deepEqual(this.state, ['/', '/child', '/sister', '/sister']); - }); - } - - ['@test RouterService#replaceWith with basic query params does not remove query param defaults']( - assert - ) { - assert.expect(1); - - this.add( - 'controller:parent.child', - Controller.extend({ - queryParams: ['sort'], - sort: 'ASC', - }) - ); - - let queryParams = this.buildQueryParams({ sort: 'ASC' }); - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('parent.brother'); - }) - .then(() => { - return this.routerService.replaceWith('parent.sister'); - }) - .then(() => { - return this.routerService.replaceWith('parent.child', queryParams); - }) - .then(() => { - assert.deepEqual(this.state, ['/', '/child?sort=ASC']); - }); - } } - ); -} + } +); diff --git a/packages/ember/tests/routing/router_service_test/transitionTo_test.js b/packages/ember/tests/routing/router_service_test/transitionTo_test.js index 2a023d8530c..4be05d10a45 100644 --- a/packages/ember/tests/routing/router_service_test/transitionTo_test.js +++ b/packages/ember/tests/routing/router_service_test/transitionTo_test.js @@ -7,364 +7,360 @@ import { get } from '@ember/-internals/metal'; import { RouterTestCase, moduleFor } from 'internal-test-helpers'; import { InternalTransition as Transition } from 'router_js'; -import { EMBER_ROUTING_ROUTER_SERVICE } from '@ember/canary-features'; - -if (EMBER_ROUTING_ROUTER_SERVICE) { - moduleFor( - 'Router Service - transitionTo', - class extends RouterTestCase { - constructor() { - super(...arguments); - - let testCase = this; - testCase.state = []; - - this.add( - 'location:test', - NoneLocation.extend({ - setURL(path) { - testCase.state.push(path); - this.set('path', path); - }, +moduleFor( + 'Router Service - transitionTo', + class extends RouterTestCase { + constructor() { + super(...arguments); + + let testCase = this; + testCase.state = []; + + this.add( + 'location:test', + NoneLocation.extend({ + setURL(path) { + testCase.state.push(path); + this.set('path', path); + }, + + replaceURL(path) { + testCase.state.splice(testCase.state.length - 1, 1, path); + this.set('path', path); + }, + }) + ); + } - replaceURL(path) { - testCase.state.splice(testCase.state.length - 1, 1, path); - this.set('path', path); - }, - }) - ); - } + get routerOptions() { + return { + location: 'test', + }; + } - get routerOptions() { - return { - location: 'test', - }; - } + ['@test RouterService#transitionTo returns a Transition'](assert) { + assert.expect(1); - ['@test RouterService#transitionTo returns a Transition'](assert) { - assert.expect(1); + let transition; - let transition; + return this.visit('/').then(() => { + transition = this.routerService.transitionTo('parent.child'); - return this.visit('/').then(() => { - transition = this.routerService.transitionTo('parent.child'); + assert.ok(transition instanceof Transition); - assert.ok(transition instanceof Transition); + return transition; + }); + } - return transition; + ['@test RouterService#transitionTo with basic route updates location'](assert) { + assert.expect(1); + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('parent.child'); + }) + .then(() => { + return this.routerService.transitionTo('parent.sister'); + }) + .then(() => { + return this.routerService.transitionTo('parent.brother'); + }) + .then(() => { + assert.deepEqual(this.state, ['/', '/child', '/sister', '/brother']); }); - } - - ['@test RouterService#transitionTo with basic route updates location'](assert) { - assert.expect(1); - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('parent.child'); - }) - .then(() => { - return this.routerService.transitionTo('parent.sister'); - }) - .then(() => { - return this.routerService.transitionTo('parent.brother'); - }) - .then(() => { - assert.deepEqual(this.state, ['/', '/child', '/sister', '/brother']); - }); - } - - ['@test RouterService#transitionTo transitioning back to previously visited route updates location']( - assert - ) { - assert.expect(1); - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('parent.child'); - }) - .then(() => { - return this.routerService.transitionTo('parent.sister'); - }) - .then(() => { - return this.routerService.transitionTo('parent.brother'); - }) - .then(() => { - return this.routerService.transitionTo('parent.sister'); - }) - .then(() => { - assert.deepEqual(this.state, ['/', '/child', '/sister', '/brother', '/sister']); - }); - } - - ['@test RouterService#transitionTo with basic route'](assert) { - assert.expect(1); - - let componentInstance; - - this.addTemplate('parent.index', '{{foo-bar}}'); - - this.addComponent('foo-bar', { - ComponentClass: Component.extend({ - routerService: injectService('router'), - init() { - this._super(); - componentInstance = this; - }, - actions: { - transitionToSister() { - get(this, 'routerService').transitionTo('parent.sister'); - }, - }, - }), - template: `foo-bar`, - }); - - return this.visit('/').then(() => { - run(function() { - componentInstance.send('transitionToSister'); - }); + } - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); + ['@test RouterService#transitionTo transitioning back to previously visited route updates location']( + assert + ) { + assert.expect(1); + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('parent.child'); + }) + .then(() => { + return this.routerService.transitionTo('parent.sister'); + }) + .then(() => { + return this.routerService.transitionTo('parent.brother'); + }) + .then(() => { + return this.routerService.transitionTo('parent.sister'); + }) + .then(() => { + assert.deepEqual(this.state, ['/', '/child', '/sister', '/brother', '/sister']); }); - } + } - ['@test RouterService#transitionTo with basic route using URL'](assert) { - assert.expect(1); + ['@test RouterService#transitionTo with basic route'](assert) { + assert.expect(1); - let componentInstance; + let componentInstance; - this.addTemplate('parent.index', '{{foo-bar}}'); + this.addTemplate('parent.index', '{{foo-bar}}'); - this.addComponent('foo-bar', { - ComponentClass: Component.extend({ - routerService: injectService('router'), - init() { - this._super(); - componentInstance = this; + this.addComponent('foo-bar', { + ComponentClass: Component.extend({ + routerService: injectService('router'), + init() { + this._super(); + componentInstance = this; + }, + actions: { + transitionToSister() { + get(this, 'routerService').transitionTo('parent.sister'); }, - actions: { - transitionToSister() { - get(this, 'routerService').transitionTo('/sister'); - }, - }, - }), - template: `foo-bar`, + }, + }), + template: `foo-bar`, + }); + + return this.visit('/').then(() => { + run(function() { + componentInstance.send('transitionToSister'); }); - return this.visit('/').then(() => { - run(function() { - componentInstance.send('transitionToSister'); - }); - - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); - }); - } + assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); + }); + } - ['@test RouterService#transitionTo with dynamic segment'](assert) { - assert.expect(3); + ['@test RouterService#transitionTo with basic route using URL'](assert) { + assert.expect(1); - let componentInstance; - let dynamicModel = { id: 1, contents: 'much dynamicism' }; + let componentInstance; - this.addTemplate('parent.index', '{{foo-bar}}'); - this.addTemplate('dynamic', '{{model.contents}}'); + this.addTemplate('parent.index', '{{foo-bar}}'); - this.addComponent('foo-bar', { - ComponentClass: Component.extend({ - routerService: injectService('router'), - init() { - this._super(); - componentInstance = this; + this.addComponent('foo-bar', { + ComponentClass: Component.extend({ + routerService: injectService('router'), + init() { + this._super(); + componentInstance = this; + }, + actions: { + transitionToSister() { + get(this, 'routerService').transitionTo('/sister'); }, - actions: { - transitionToDynamic() { - get(this, 'routerService').transitionTo('dynamic', dynamicModel); - }, - }, - }), - template: `foo-bar`, + }, + }), + template: `foo-bar`, + }); + + return this.visit('/').then(() => { + run(function() { + componentInstance.send('transitionToSister'); }); - return this.visit('/').then(() => { - run(function() { - componentInstance.send('transitionToDynamic'); - }); + assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); + }); + } - assert.equal(this.routerService.get('currentRouteName'), 'dynamic'); - assert.equal(this.routerService.get('currentURL'), '/dynamic/1'); - this.assertText('much dynamicism'); + ['@test RouterService#transitionTo with dynamic segment'](assert) { + assert.expect(3); + + let componentInstance; + let dynamicModel = { id: 1, contents: 'much dynamicism' }; + + this.addTemplate('parent.index', '{{foo-bar}}'); + this.addTemplate('dynamic', '{{model.contents}}'); + + this.addComponent('foo-bar', { + ComponentClass: Component.extend({ + routerService: injectService('router'), + init() { + this._super(); + componentInstance = this; + }, + actions: { + transitionToDynamic() { + get(this, 'routerService').transitionTo('dynamic', dynamicModel); + }, + }, + }), + template: `foo-bar`, + }); + + return this.visit('/').then(() => { + run(function() { + componentInstance.send('transitionToDynamic'); }); - } - - ['@test RouterService#transitionTo with dynamic segment and model hook'](assert) { - assert.expect(3); - let componentInstance; - let dynamicModel = { id: 1, contents: 'much dynamicism' }; + assert.equal(this.routerService.get('currentRouteName'), 'dynamic'); + assert.equal(this.routerService.get('currentURL'), '/dynamic/1'); + this.assertText('much dynamicism'); + }); + } - this.add( - 'route:dynamic', - Route.extend({ - model() { - return dynamicModel; - }, - }) - ); - - this.addTemplate('parent.index', '{{foo-bar}}'); - this.addTemplate('dynamic', '{{model.contents}}'); - - this.addComponent('foo-bar', { - ComponentClass: Component.extend({ - routerService: injectService('router'), - init() { - this._super(); - componentInstance = this; + ['@test RouterService#transitionTo with dynamic segment and model hook'](assert) { + assert.expect(3); + + let componentInstance; + let dynamicModel = { id: 1, contents: 'much dynamicism' }; + + this.add( + 'route:dynamic', + Route.extend({ + model() { + return dynamicModel; + }, + }) + ); + + this.addTemplate('parent.index', '{{foo-bar}}'); + this.addTemplate('dynamic', '{{model.contents}}'); + + this.addComponent('foo-bar', { + ComponentClass: Component.extend({ + routerService: injectService('router'), + init() { + this._super(); + componentInstance = this; + }, + actions: { + transitionToDynamic() { + get(this, 'routerService').transitionTo('dynamic', 1); }, - actions: { - transitionToDynamic() { - get(this, 'routerService').transitionTo('dynamic', 1); - }, - }, - }), - template: `foo-bar`, + }, + }), + template: `foo-bar`, + }); + + return this.visit('/').then(() => { + run(function() { + componentInstance.send('transitionToDynamic'); }); - return this.visit('/').then(() => { - run(function() { - componentInstance.send('transitionToDynamic'); - }); + assert.equal(this.routerService.get('currentRouteName'), 'dynamic'); + assert.equal(this.routerService.get('currentURL'), '/dynamic/1'); + this.assertText('much dynamicism'); + }); + } - assert.equal(this.routerService.get('currentRouteName'), 'dynamic'); - assert.equal(this.routerService.get('currentURL'), '/dynamic/1'); - this.assertText('much dynamicism'); + ['@test RouterService#transitionTo with basic query params does not remove query param defaults']( + assert + ) { + assert.expect(1); + + this.add( + 'controller:parent.child', + Controller.extend({ + queryParams: ['sort'], + sort: 'ASC', + }) + ); + + let queryParams = this.buildQueryParams({ sort: 'ASC' }); + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('parent.child', queryParams); + }) + .then(() => { + assert.equal(this.routerService.get('currentURL'), '/child?sort=ASC'); }); - } - - ['@test RouterService#transitionTo with basic query params does not remove query param defaults']( - assert - ) { - assert.expect(1); - - this.add( - 'controller:parent.child', - Controller.extend({ - queryParams: ['sort'], - sort: 'ASC', - }) - ); - - let queryParams = this.buildQueryParams({ sort: 'ASC' }); - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('parent.child', queryParams); - }) - .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child?sort=ASC'); - }); - } - - ['@test RouterService#transitionTo passing only queryParams works'](assert) { - assert.expect(2); - - this.add( - 'controller:parent.child', - Controller.extend({ - queryParams: ['sort'], - }) - ); - - let queryParams = this.buildQueryParams({ sort: 'DESC' }); - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('parent.child'); - }) - .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child'); - }) - .then(() => { - return this.routerService.transitionTo(queryParams); - }) - .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child?sort=DESC'); - }); - } - - ['@test RouterService#transitionTo with unspecified query params'](assert) { - assert.expect(1); - - this.add( - 'controller:parent.child', - Controller.extend({ - queryParams: ['sort', 'page', 'category', 'extra'], - sort: 'ASC', - page: null, - category: undefined, - }) - ); - - let queryParams = this.buildQueryParams({ sort: 'ASC' }); - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('parent.child', queryParams); - }) - .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child?sort=ASC'); - }); - } - - ['@test RouterService#transitionTo with aliased query params uses the original provided key']( - assert - ) { - assert.expect(1); - - this.add( - 'controller:parent.child', - Controller.extend({ - queryParams: { - cont_sort: 'url_sort', - }, - cont_sort: 'ASC', - }) - ); - - let queryParams = this.buildQueryParams({ url_sort: 'ASC' }); - - return this.visit('/') - .then(() => { - return this.routerService.transitionTo('parent.child', queryParams); - }) - .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child?url_sort=ASC'); - }); - } - - ['@test RouterService#transitionTo with aliased query params uses the original provided key when controller property name']( - assert - ) { - assert.expect(1); - - this.add( - 'controller:parent.child', - Controller.extend({ - queryParams: { - cont_sort: 'url_sort', - }, - cont_sort: 'ASC', - }) - ); + } + + ['@test RouterService#transitionTo passing only queryParams works'](assert) { + assert.expect(2); + + this.add( + 'controller:parent.child', + Controller.extend({ + queryParams: ['sort'], + }) + ); + + let queryParams = this.buildQueryParams({ sort: 'DESC' }); + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('parent.child'); + }) + .then(() => { + assert.equal(this.routerService.get('currentURL'), '/child'); + }) + .then(() => { + return this.routerService.transitionTo(queryParams); + }) + .then(() => { + assert.equal(this.routerService.get('currentURL'), '/child?sort=DESC'); + }); + } - let queryParams = this.buildQueryParams({ cont_sort: 'ASC' }); + ['@test RouterService#transitionTo with unspecified query params'](assert) { + assert.expect(1); + + this.add( + 'controller:parent.child', + Controller.extend({ + queryParams: ['sort', 'page', 'category', 'extra'], + sort: 'ASC', + page: null, + category: undefined, + }) + ); + + let queryParams = this.buildQueryParams({ sort: 'ASC' }); + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('parent.child', queryParams); + }) + .then(() => { + assert.equal(this.routerService.get('currentURL'), '/child?sort=ASC'); + }); + } - return this.visit('/').then(() => { - expectAssertion(() => { - return this.routerService.transitionTo('parent.child', queryParams); - }, 'You passed the `cont_sort` query parameter during a transition into parent.child, please update to url_sort'); + ['@test RouterService#transitionTo with aliased query params uses the original provided key']( + assert + ) { + assert.expect(1); + + this.add( + 'controller:parent.child', + Controller.extend({ + queryParams: { + cont_sort: 'url_sort', + }, + cont_sort: 'ASC', + }) + ); + + let queryParams = this.buildQueryParams({ url_sort: 'ASC' }); + + return this.visit('/') + .then(() => { + return this.routerService.transitionTo('parent.child', queryParams); + }) + .then(() => { + assert.equal(this.routerService.get('currentURL'), '/child?url_sort=ASC'); }); - } } - ); -} + + ['@test RouterService#transitionTo with aliased query params uses the original provided key when controller property name']( + assert + ) { + assert.expect(1); + + this.add( + 'controller:parent.child', + Controller.extend({ + queryParams: { + cont_sort: 'url_sort', + }, + cont_sort: 'ASC', + }) + ); + + let queryParams = this.buildQueryParams({ cont_sort: 'ASC' }); + + return this.visit('/').then(() => { + expectAssertion(() => { + return this.routerService.transitionTo('parent.child', queryParams); + }, 'You passed the `cont_sort` query parameter during a transition into parent.child, please update to url_sort'); + }); + } + } +); diff --git a/packages/ember/tests/routing/router_service_test/urlFor_test.js b/packages/ember/tests/routing/router_service_test/urlFor_test.js index abbda06df48..7eef0f561d8 100644 --- a/packages/ember/tests/routing/router_service_test/urlFor_test.js +++ b/packages/ember/tests/routing/router_service_test/urlFor_test.js @@ -4,8 +4,6 @@ import { Route } from '@ember/-internals/routing'; import { get } from '@ember/-internals/metal'; import { RouterTestCase, moduleFor } from 'internal-test-helpers'; -import { EMBER_ROUTING_ROUTER_SERVICE } from '@ember/canary-features'; - function setupController(app, name) { let controllerName = `${capitalize(name)}Controller`; @@ -16,292 +14,288 @@ function setupController(app, name) { }); } -if (EMBER_ROUTING_ROUTER_SERVICE) { - moduleFor( - 'Router Service - urlFor', - class extends RouterTestCase { - ['@test RouterService#urlFor returns URL for simple route'](assert) { - assert.expect(1); +moduleFor( + 'Router Service - urlFor', + class extends RouterTestCase { + ['@test RouterService#urlFor returns URL for simple route'](assert) { + assert.expect(1); - return this.visit('/').then(() => { - let expectedURL = this.routerService.urlFor('parent.child'); + return this.visit('/').then(() => { + let expectedURL = this.routerService.urlFor('parent.child'); - assert.equal('/child', expectedURL); - }); - } + assert.equal('/child', expectedURL); + }); + } - ['@test RouterService#urlFor returns URL for simple route with dynamic segments'](assert) { - assert.expect(1); + ['@test RouterService#urlFor returns URL for simple route with dynamic segments'](assert) { + assert.expect(1); - setupController(this.application, 'dynamic'); + setupController(this.application, 'dynamic'); - let dynamicModel = { id: 1, contents: 'much dynamicism' }; + let dynamicModel = { id: 1, contents: 'much dynamicism' }; - return this.visit('/').then(() => { - let expectedURL = this.routerService.urlFor('dynamic', dynamicModel); + return this.visit('/').then(() => { + let expectedURL = this.routerService.urlFor('dynamic', dynamicModel); - assert.equal('/dynamic/1', expectedURL); - }); - } + assert.equal('/dynamic/1', expectedURL); + }); + } - ['@test RouterService#urlFor returns URL for simple route with basic query params'](assert) { - assert.expect(1); + ['@test RouterService#urlFor returns URL for simple route with basic query params'](assert) { + assert.expect(1); - let queryParams = this.buildQueryParams({ foo: 'bar' }); + let queryParams = this.buildQueryParams({ foo: 'bar' }); - return this.visit('/').then(() => { - let expectedURL = this.routerService.urlFor('parent.child', queryParams); + return this.visit('/').then(() => { + let expectedURL = this.routerService.urlFor('parent.child', queryParams); - assert.equal('/child?foo=bar', expectedURL); - }); - } - - ['@test RouterService#urlFor returns URL for simple route with basic query params and default value']( - assert - ) { - assert.expect(1); - - this.add( - 'controller:parent.child', - Controller.extend({ - queryParams: ['sort'], - sort: 'ASC', - }) - ); + assert.equal('/child?foo=bar', expectedURL); + }); + } - let queryParams = this.buildQueryParams({ sort: 'ASC' }); + ['@test RouterService#urlFor returns URL for simple route with basic query params and default value']( + assert + ) { + assert.expect(1); - return this.visit('/').then(() => { - let expectedURL = this.routerService.urlFor('parent.child', queryParams); + this.add( + 'controller:parent.child', + Controller.extend({ + queryParams: ['sort'], + sort: 'ASC', + }) + ); - assert.equal('/child?sort=ASC', expectedURL); - }); - } - - ['@test RouterService#urlFor returns URL for simple route with basic query params and default value with stickyness']( - assert - ) { - assert.expect(2); - - this.add( - 'controller:parent.child', - Controller.extend({ - queryParams: ['sort', 'foo'], - sort: 'ASC', - }) - ); + let queryParams = this.buildQueryParams({ sort: 'ASC' }); - return this.visit('/child/?sort=DESC').then(() => { - let controller = this.applicationInstance.lookup('controller:parent.child'); - assert.equal(get(controller, 'sort'), 'DESC', 'sticky is set'); + return this.visit('/').then(() => { + let expectedURL = this.routerService.urlFor('parent.child', queryParams); - let queryParams = this.buildQueryParams({ foo: 'derp' }); - let actual = this.routerService.urlFor('parent.child', queryParams); + assert.equal('/child?sort=ASC', expectedURL); + }); + } - assert.equal(actual, '/child?foo=derp', 'does not use "stickiness"'); - }); - } + ['@test RouterService#urlFor returns URL for simple route with basic query params and default value with stickyness']( + assert + ) { + assert.expect(2); - ['@test RouterService#urlFor returns URL for simple route with array as query params']( - assert - ) { - assert.expect(1); + this.add( + 'controller:parent.child', + Controller.extend({ + queryParams: ['sort', 'foo'], + sort: 'ASC', + }) + ); - let queryParams = this.buildQueryParams({ - selectedItems: ['a', 'b', 'c'], - }); + return this.visit('/child/?sort=DESC').then(() => { + let controller = this.applicationInstance.lookup('controller:parent.child'); + assert.equal(get(controller, 'sort'), 'DESC', 'sticky is set'); - return this.visit('/').then(() => { - let expectedURL = this.routerService.urlFor('parent.child', queryParams); + let queryParams = this.buildQueryParams({ foo: 'derp' }); + let actual = this.routerService.urlFor('parent.child', queryParams); - assert.equal('/child?selectedItems[]=a&selectedItems[]=b&selectedItems[]=c', expectedURL); - }); - } + assert.equal(actual, '/child?foo=derp', 'does not use "stickiness"'); + }); + } - ['@test RouterService#urlFor returns URL for simple route with null query params'](assert) { - assert.expect(1); + ['@test RouterService#urlFor returns URL for simple route with array as query params'](assert) { + assert.expect(1); - let queryParams = this.buildQueryParams({ foo: null }); + let queryParams = this.buildQueryParams({ + selectedItems: ['a', 'b', 'c'], + }); - return this.visit('/').then(() => { - let expectedURL = this.routerService.urlFor('parent.child', queryParams); + return this.visit('/').then(() => { + let expectedURL = this.routerService.urlFor('parent.child', queryParams); - assert.equal('/child', expectedURL); - }); - } + assert.equal('/child?selectedItems[]=a&selectedItems[]=b&selectedItems[]=c', expectedURL); + }); + } - ['@test RouterService#urlFor returns URL for simple route with undefined query params']( - assert - ) { - assert.expect(1); + ['@test RouterService#urlFor returns URL for simple route with null query params'](assert) { + assert.expect(1); - let queryParams = this.buildQueryParams({ foo: undefined }); + let queryParams = this.buildQueryParams({ foo: null }); - return this.visit('/').then(() => { - let expectedURL = this.routerService.urlFor('parent.child', queryParams); + return this.visit('/').then(() => { + let expectedURL = this.routerService.urlFor('parent.child', queryParams); - assert.equal('/child', expectedURL); - }); - } + assert.equal('/child', expectedURL); + }); + } - ['@test RouterService#urlFor returns URL for simple route with dynamic segments and basic query params']( - assert - ) { - assert.expect(1); + ['@test RouterService#urlFor returns URL for simple route with undefined query params']( + assert + ) { + assert.expect(1); - let queryParams = this.buildQueryParams({ foo: 'bar' }); + let queryParams = this.buildQueryParams({ foo: undefined }); - return this.visit('/').then(() => { - let expectedURL = this.routerService.urlFor('dynamic', { id: 1 }, queryParams); + return this.visit('/').then(() => { + let expectedURL = this.routerService.urlFor('parent.child', queryParams); - assert.equal('/dynamic/1?foo=bar', expectedURL); - }); - } + assert.equal('/child', expectedURL); + }); + } - ['@test RouterService#urlFor returns URL for simple route with dynamic segments and array as query params']( - assert - ) { - assert.expect(1); + ['@test RouterService#urlFor returns URL for simple route with dynamic segments and basic query params']( + assert + ) { + assert.expect(1); - let queryParams = this.buildQueryParams({ - selectedItems: ['a', 'b', 'c'], - }); + let queryParams = this.buildQueryParams({ foo: 'bar' }); - return this.visit('/').then(() => { - let expectedURL = this.routerService.urlFor('dynamic', { id: 1 }, queryParams); + return this.visit('/').then(() => { + let expectedURL = this.routerService.urlFor('dynamic', { id: 1 }, queryParams); - assert.equal( - '/dynamic/1?selectedItems[]=a&selectedItems[]=b&selectedItems[]=c', - expectedURL - ); - }); - } + assert.equal('/dynamic/1?foo=bar', expectedURL); + }); + } - ['@test RouterService#urlFor returns URL for simple route with dynamic segments and null query params']( - assert - ) { - assert.expect(1); + ['@test RouterService#urlFor returns URL for simple route with dynamic segments and array as query params']( + assert + ) { + assert.expect(1); - let queryParams = this.buildQueryParams({ foo: null }); + let queryParams = this.buildQueryParams({ + selectedItems: ['a', 'b', 'c'], + }); - return this.visit('/').then(() => { - let expectedURL = this.routerService.urlFor('dynamic', { id: 1 }, queryParams); + return this.visit('/').then(() => { + let expectedURL = this.routerService.urlFor('dynamic', { id: 1 }, queryParams); - assert.equal('/dynamic/1', expectedURL); - }); - } + assert.equal( + '/dynamic/1?selectedItems[]=a&selectedItems[]=b&selectedItems[]=c', + expectedURL + ); + }); + } + + ['@test RouterService#urlFor returns URL for simple route with dynamic segments and null query params']( + assert + ) { + assert.expect(1); + + let queryParams = this.buildQueryParams({ foo: null }); + + return this.visit('/').then(() => { + let expectedURL = this.routerService.urlFor('dynamic', { id: 1 }, queryParams); + + assert.equal('/dynamic/1', expectedURL); + }); + } + + ['@test RouterService#urlFor returns URL for simple route with dynamic segments and undefined query params']( + assert + ) { + assert.expect(1); + + let queryParams = this.buildQueryParams({ foo: undefined }); + + return this.visit('/').then(() => { + let expectedURL = this.routerService.urlFor('dynamic', { id: 1 }, queryParams); + + assert.equal('/dynamic/1', expectedURL); + }); + } - ['@test RouterService#urlFor returns URL for simple route with dynamic segments and undefined query params']( - assert - ) { - assert.expect(1); + ['@test RouterService#urlFor correctly transitions to route via generated path'](assert) { + assert.expect(1); - let queryParams = this.buildQueryParams({ foo: undefined }); + let expectedURL; - return this.visit('/').then(() => { - let expectedURL = this.routerService.urlFor('dynamic', { id: 1 }, queryParams); + return this.visit('/') + .then(() => { + expectedURL = this.routerService.urlFor('parent.child'); - assert.equal('/dynamic/1', expectedURL); + return this.routerService.transitionTo(expectedURL); + }) + .then(() => { + assert.equal(expectedURL, this.routerService.get('currentURL')); }); - } - - ['@test RouterService#urlFor correctly transitions to route via generated path'](assert) { - assert.expect(1); - - let expectedURL; - - return this.visit('/') - .then(() => { - expectedURL = this.routerService.urlFor('parent.child'); - - return this.routerService.transitionTo(expectedURL); - }) - .then(() => { - assert.equal(expectedURL, this.routerService.get('currentURL')); - }); - } - - ['@test RouterService#urlFor correctly transitions to route via generated path with dynamic segments']( - assert - ) { - assert.expect(1); - - let expectedURL; - let dynamicModel = { id: 1 }; - - this.add( - 'route:dynamic', - Route.extend({ - model() { - return dynamicModel; - }, - }) - ); + } - return this.visit('/') - .then(() => { - expectedURL = this.routerService.urlFor('dynamic', dynamicModel); - - return this.routerService.transitionTo(expectedURL); - }) - .then(() => { - assert.equal(expectedURL, this.routerService.get('currentURL')); - }); - } - - ['@test RouterService#urlFor correctly transitions to route via generated path with query params']( - assert - ) { - assert.expect(1); - - let expectedURL; - let actualURL; - let queryParams = this.buildQueryParams({ foo: 'bar' }); - - return this.visit('/') - .then(() => { - expectedURL = this.routerService.urlFor('parent.child', queryParams); - - return this.routerService.transitionTo(expectedURL); - }) - .then(() => { - actualURL = `${this.routerService.get('currentURL')}?foo=bar`; - - assert.equal(expectedURL, actualURL); - }); - } - - ['@test RouterService#urlFor correctly transitions to route via generated path with dynamic segments and query params']( - assert - ) { - assert.expect(1); - - let expectedURL; - let actualURL; - let queryParams = this.buildQueryParams({ foo: 'bar' }); - let dynamicModel = { id: 1 }; - - this.add( - 'route:dynamic', - Route.extend({ - model() { - return dynamicModel; - }, - }) - ); + ['@test RouterService#urlFor correctly transitions to route via generated path with dynamic segments']( + assert + ) { + assert.expect(1); + + let expectedURL; + let dynamicModel = { id: 1 }; + + this.add( + 'route:dynamic', + Route.extend({ + model() { + return dynamicModel; + }, + }) + ); + + return this.visit('/') + .then(() => { + expectedURL = this.routerService.urlFor('dynamic', dynamicModel); + + return this.routerService.transitionTo(expectedURL); + }) + .then(() => { + assert.equal(expectedURL, this.routerService.get('currentURL')); + }); + } + + ['@test RouterService#urlFor correctly transitions to route via generated path with query params']( + assert + ) { + assert.expect(1); - return this.visit('/') - .then(() => { - expectedURL = this.routerService.urlFor('dynamic', dynamicModel, queryParams); + let expectedURL; + let actualURL; + let queryParams = this.buildQueryParams({ foo: 'bar' }); - return this.routerService.transitionTo(expectedURL); - }) - .then(() => { - actualURL = `${this.routerService.get('currentURL')}?foo=bar`; + return this.visit('/') + .then(() => { + expectedURL = this.routerService.urlFor('parent.child', queryParams); - assert.equal(expectedURL, actualURL); - }); - } + return this.routerService.transitionTo(expectedURL); + }) + .then(() => { + actualURL = `${this.routerService.get('currentURL')}?foo=bar`; + + assert.equal(expectedURL, actualURL); + }); } - ); -} + + ['@test RouterService#urlFor correctly transitions to route via generated path with dynamic segments and query params']( + assert + ) { + assert.expect(1); + + let expectedURL; + let actualURL; + let queryParams = this.buildQueryParams({ foo: 'bar' }); + let dynamicModel = { id: 1 }; + + this.add( + 'route:dynamic', + Route.extend({ + model() { + return dynamicModel; + }, + }) + ); + + return this.visit('/') + .then(() => { + expectedURL = this.routerService.urlFor('dynamic', dynamicModel, queryParams); + + return this.routerService.transitionTo(expectedURL); + }) + .then(() => { + actualURL = `${this.routerService.get('currentURL')}?foo=bar`; + + assert.equal(expectedURL, actualURL); + }); + } + } +);