diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/attrs-lookup-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/attrs-lookup-test.js index 631b532e336..451f7734ecd 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/attrs-lookup-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/attrs-lookup-test.js @@ -171,9 +171,7 @@ moduleFor( } }; - FooBarComponent.reopenClass({ - positionalParams: ['firstPositional'], - }); + FooBarComponent.positionalParams = ['firstPositional']; this.owner.register('component:foo-bar', FooBarComponent); diff --git a/packages/@ember/routing/tests/location/history_location_test.js b/packages/@ember/routing/tests/location/history_location_test.js index 68505a5a3ec..e5b992957fe 100644 --- a/packages/@ember/routing/tests/location/history_location_test.js +++ b/packages/@ember/routing/tests/location/history_location_test.js @@ -68,15 +68,16 @@ moduleFor( ['@test HistoryLocation initState does not get fired on init'](assert) { assert.expect(1); - HistoryTestLocation.reopen({ + HistoryTestLocation = class extends HistoryTestLocation { init() { assert.ok(true, 'init was called'); - this._super(...arguments); - }, + super.init(...arguments); + } + initState() { assert.ok(false, 'initState() should not be called automatically'); - }, - }); + } + }; createLocation(); } @@ -93,7 +94,7 @@ moduleFor( createLocation(); location.initState(); - assert.strictEqual(location.get('baseURL'), '/foo/'); + assert.strictEqual(location.baseURL, '/foo/'); } finally { document.head.removeChild(base); } @@ -111,7 +112,7 @@ moduleFor( createLocation(); location.initState(); - assert.strictEqual(location.get('baseURL'), ''); + assert.strictEqual(location.baseURL, ''); } finally { document.head.removeChild(base); } @@ -120,20 +121,20 @@ moduleFor( ['@test base URL is removed when retrieving the current pathname'](assert) { assert.expect(1); - HistoryTestLocation.reopen({ + HistoryTestLocation = class extends HistoryTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'location', mockBrowserLocation('/base/foo/bar')); set(this, 'baseURL', '/base/'); - }, + } initState() { - this._super(...arguments); + super.initState(...arguments); assert.equal(this.getURL(), '/foo/bar'); - }, - }); + } + }; createLocation(); location.initState(); @@ -142,14 +143,14 @@ moduleFor( ['@test base URL is preserved when moving around'](assert) { assert.expect(2); - HistoryTestLocation.reopen({ + HistoryTestLocation = class extends HistoryTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'location', mockBrowserLocation('/base/foo/bar')); set(this, 'baseURL', '/base/'); - }, - }); + } + }; createLocation(); location.initState(); @@ -184,15 +185,15 @@ moduleFor( ['@test HistoryLocation.getURL() returns the current url, excluding both rootURL and baseURL']( assert ) { - HistoryTestLocation.reopen({ + HistoryTestLocation = class extends HistoryTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'location', mockBrowserLocation('/base/foo/bar')); set(this, 'rootURL', '/app/'); set(this, 'baseURL', '/base/'); - }, - }); + } + }; createLocation(); @@ -202,14 +203,14 @@ moduleFor( ['@test HistoryLocation.getURL() returns the current url, does not remove rootURL if its not at start of url']( assert ) { - HistoryTestLocation.reopen({ + HistoryTestLocation = class extends HistoryTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'location', mockBrowserLocation('/foo/bar/baz')); set(this, 'rootURL', '/bar/'); - }, - }); + } + }; createLocation(); @@ -219,13 +220,13 @@ moduleFor( ['@test HistoryLocation.getURL() will not remove the rootURL when only a partial match']( assert ) { - HistoryTestLocation.reopen({ + HistoryTestLocation = class extends HistoryTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'location', mockBrowserLocation('/bars/baz')); set(this, 'rootURL', '/bar/'); - }, - }); + } + }; createLocation(); @@ -235,14 +236,14 @@ moduleFor( ['@test HistoryLocation.getURL() returns the current url, does not remove baseURL if its not at start of url']( assert ) { - HistoryTestLocation.reopen({ + HistoryTestLocation = class extends HistoryTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'location', mockBrowserLocation('/foo/bar/baz')); set(this, 'baseURL', '/bar/'); - }, - }); + } + }; createLocation(); @@ -252,13 +253,13 @@ moduleFor( ['@test HistoryLocation.getURL() will not remove the baseURL when only a partial match']( assert ) { - HistoryTestLocation.reopen({ + HistoryTestLocation = class extends HistoryTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'location', mockBrowserLocation('/bars/baz')); set(this, 'baseURL', '/bar/'); - }, - }); + } + }; createLocation(); @@ -266,12 +267,12 @@ moduleFor( } ['@test HistoryLocation.getURL() includes location.search'](assert) { - HistoryTestLocation.reopen({ + HistoryTestLocation = class extends HistoryTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'location', mockBrowserLocation('/foo/bar?time=morphin')); - }, - }); + } + }; createLocation(); @@ -279,12 +280,12 @@ moduleFor( } ['@test HistoryLocation.getURL() includes location.hash'](assert) { - HistoryTestLocation.reopen({ + HistoryTestLocation = class extends HistoryTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'location', mockBrowserLocation('/foo/bar#pink-power-ranger')); - }, - }); + } + }; createLocation(); @@ -292,12 +293,12 @@ moduleFor( } ['@test HistoryLocation.getURL() includes location.hash and location.search'](assert) { - HistoryTestLocation.reopen({ + HistoryTestLocation = class extends HistoryTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'location', mockBrowserLocation('/foo/bar?time=morphin#pink-power-ranger')); - }, - }); + } + }; createLocation(); @@ -305,14 +306,14 @@ moduleFor( } ['@test HistoryLocation.getURL() drops duplicate slashes'](assert) { - HistoryTestLocation.reopen({ + HistoryTestLocation = class extends HistoryTestLocation { init() { - this._super(...arguments); + super.init(...arguments); let location = mockBrowserLocation('//admin//profile//'); location.pathname = '//admin//profile//'; // mockBrowserLocation does not allow for `//`, so force it set(this, 'location', location); - }, - }); + } + }; createLocation(); @@ -322,14 +323,14 @@ moduleFor( ['@test HistoryLocation.getURL() treats regex metacharacters in rootURL and baseURL literally']( assert ) { - HistoryTestLocation.reopen({ + HistoryTestLocation = class extends HistoryTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'location', mockBrowserLocation('/axc/secret')); set(this, 'rootURL', '/a.c/'); set(this, 'baseURL', '/a.c/'); - }, - }); + } + }; createLocation(); @@ -344,12 +345,12 @@ moduleFor( FakeHistory.state = existingState; - HistoryTestLocation.reopen({ + HistoryTestLocation = class extends HistoryTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'location', mockBrowserLocation('/route/path')); - }, - }); + } + }; createLocation(); location.initState(); diff --git a/packages/@ember/routing/tests/location/none_location_test.js b/packages/@ember/routing/tests/location/none_location_test.js index 04f77db057b..ca1091f6d89 100644 --- a/packages/@ember/routing/tests/location/none_location_test.js +++ b/packages/@ember/routing/tests/location/none_location_test.js @@ -29,12 +29,12 @@ moduleFor( } ['@test NoneLocation.formatURL() returns the current url always appending rootURL'](assert) { - NoneTestLocation.reopen({ + NoneTestLocation = class extends NoneTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'rootURL', '/en/'); - }, - }); + } + }; createLocation(); @@ -42,13 +42,13 @@ moduleFor( } ['@test NoneLocation.getURL() returns the current path minus rootURL'](assert) { - NoneTestLocation.reopen({ + NoneTestLocation = class extends NoneTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'rootURL', '/foo/'); set(this, 'path', '/foo/bar'); - }, - }); + } + }; createLocation(); @@ -58,13 +58,13 @@ moduleFor( ['@test NoneLocation.getURL() will remove the rootURL only from the beginning of a url']( assert ) { - NoneTestLocation.reopen({ + NoneTestLocation = class extends NoneTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'rootURL', '/bar/'); set(this, 'path', '/foo/bar/baz'); - }, - }); + } + }; createLocation(); @@ -72,13 +72,13 @@ moduleFor( } ['@test NoneLocation.getURL() will not remove the rootURL when only a partial match'](assert) { - NoneTestLocation.reopen({ + NoneTestLocation = class extends NoneTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'rootURL', '/bar/'); set(this, 'path', '/bars/baz'); - }, - }); + } + }; createLocation(); @@ -86,13 +86,13 @@ moduleFor( } ['@test NoneLocation.getURL() treats regex metacharacters in rootURL literally'](assert) { - NoneTestLocation.reopen({ + NoneTestLocation = class extends NoneTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'rootURL', '/a.c/'); set(this, 'path', '/axc/secret'); - }, - }); + } + }; createLocation(); @@ -100,13 +100,13 @@ moduleFor( } ['@test NoneLocation.getURL() strips the rootURL when it has an extra trailing slash'](assert) { - NoneTestLocation.reopen({ + NoneTestLocation = class extends NoneTestLocation { init() { - this._super(...arguments); + super.init(...arguments); set(this, 'rootURL', '/foo//'); set(this, 'path', '/foo//bar'); - }, - }); + } + }; createLocation(); diff --git a/packages/@ember/routing/tests/system/dsl_test.js b/packages/@ember/routing/tests/system/dsl_test.js index 5b7d63df119..1d502629f3c 100644 --- a/packages/@ember/routing/tests/system/dsl_test.js +++ b/packages/@ember/routing/tests/system/dsl_test.js @@ -87,11 +87,7 @@ moduleFor( this.route('blork'); }); - this.routerInstance.reopen({ - _hasModuleBasedResolver() { - return true; - }, - }); + this.routerInstance._hasModuleBasedResolver = () => true; let router = this.routerInstance; router._initRouterJs(); @@ -133,11 +129,7 @@ moduleFor( }); }); - this.routerInstance.reopen({ - _hasModuleBasedResolver() { - return true; - }, - }); + this.routerInstance._hasModuleBasedResolver = () => true; let router = this.routerInstance; router._initRouterJs(); @@ -285,11 +277,7 @@ moduleFor( this.mount('chat'); }); - this.routerInstance.reopen({ - _hasModuleBasedResolver() { - return true; - }, - }); + this.routerInstance._hasModuleBasedResolver = () => true; this.routerInstance._initRouterJs(); let router = this.routerInstance; assert.ok(router._routerMicrolib.recognizer.names['chat'], 'main route was created'); @@ -304,11 +292,7 @@ moduleFor( this.mount('chat', { as: 'shoutbox' }); }); - this.routerInstance.reopen({ - _hasModuleBasedResolver() { - return true; - }, - }); + this.routerInstance._hasModuleBasedResolver = () => true; this.routerInstance._initRouterJs(); let router = this.routerInstance; @@ -351,11 +335,7 @@ moduleFor( }); }); - this.routerInstance.reopen({ - _hasModuleBasedResolver() { - return true; - }, - }); + this.routerInstance._hasModuleBasedResolver = () => true; this.routerInstance._initRouterJs(); let router = this.routerInstance; diff --git a/packages/@ember/utils/tests/compare_test.js b/packages/@ember/utils/tests/compare_test.js index 36c107bd826..9d1ef5be7b7 100644 --- a/packages/@ember/utils/tests/compare_test.js +++ b/packages/@ember/utils/tests/compare_test.js @@ -4,13 +4,11 @@ import { moduleFor, AbstractTestCase, expectDeprecation, testUnless } from 'inte import { DEPRECATIONS } from '@ember/-internals/deprecations'; let data = []; -let Comp = EmberObject.extend(); - -Comp.reopenClass({ - compare(obj) { +class Comp extends EmberObject { + static compare(obj) { return obj.get('val'); - }, -}); + } +} const UTILS = DEPRECATIONS.DEPRECATE_EMBER_UTILS; diff --git a/packages/@ember/utils/tests/type_of_test.js b/packages/@ember/utils/tests/type_of_test.js index c1739a7ae48..7f778b2f7dc 100644 --- a/packages/@ember/utils/tests/type_of_test.js +++ b/packages/@ember/utils/tests/type_of_test.js @@ -46,6 +46,7 @@ moduleFor( assert.equal(typeOf(instance.method), 'function', 'item of type function'); assert.equal(typeOf(instance.asyncMethod), 'function', 'item of type async function'); assert.equal(typeOf(EmberObject.extend()), 'class', 'item of type class'); + assert.equal(typeOf(class extends EmberObject {}), 'class', 'item of type native class'); assert.equal(typeOf(new Error()), 'error', 'item of type error'); } diff --git a/packages/ember/tests/routing/decoupled_basic_test.js b/packages/ember/tests/routing/decoupled_basic_test.js index c404f8dcd88..3fb495f1ce9 100644 --- a/packages/ember/tests/routing/decoupled_basic_test.js +++ b/packages/ember/tests/routing/decoupled_basic_test.js @@ -5,7 +5,7 @@ import { precompileTemplate } from '@ember/template-compilation'; import Route from '@ember/routing/route'; import NoneLocation from '@ember/routing/none-location'; import HistoryLocation from '@ember/routing/history-location'; -import EmberObject, { set } from '@ember/object'; +import { set } from '@ember/object'; import { moduleFor, ApplicationTestCase, @@ -140,9 +140,13 @@ moduleFor( let menuItem, resolve; - let MenuItem = class extends EmberObject { + let MenuItem = class { + constructor(id) { + this.id = id; + } + static find(id) { - menuItem = MenuItem.create({ id: id }); + menuItem = new MenuItem(id); return new RSVP.Promise(function (res) { resolve = res; @@ -185,7 +189,7 @@ moduleFor( this.route('special', { path: '/specials/:menu_item_id' }); }); - let MenuItem = class extends EmberObject { + let MenuItem = class { static find(id) { return { id: id }; } @@ -267,9 +271,13 @@ moduleFor( let menuItem, resolve; - let MenuItem = class extends EmberObject { + let MenuItem = class { + constructor(id) { + this.id = id; + } + static find(id) { - menuItem = MenuItem.create({ id: id }); + menuItem = new MenuItem(id); return new RSVP.Promise((res) => (resolve = res)); } }; @@ -322,7 +330,7 @@ moduleFor( let urlSetCount = 0; let router = this.applicationInstance.lookup('router:main'); - router.get('location').setURL = function (path) { + router.location.setURL = function (path) { urlSetCount++; set(this, 'path', path); }; @@ -335,7 +343,7 @@ moduleFor( }); assert.equal(urlSetCount, 1); - assert.equal(router.get('location').getURL(), '/bar'); + assert.equal(router.location.getURL(), '/bar'); }); } @@ -361,19 +369,23 @@ moduleFor( ['@test using replaceWith calls location.replaceURL if available'](assert) { let setCount = 0; let replaceCount = 0; - this.router.reopen({ - location: NoneLocation.create({ - setURL(path) { - setCount++; - set(this, 'path', path); - }, - - replaceURL(path) { - replaceCount++; - set(this, 'path', path); - }, - }), - }); + this.subclass( + 'router:main', + (Router) => + class extends Router { + location = NoneLocation.create({ + setURL(path) { + setCount++; + set(this, 'path', path); + }, + + replaceURL(path) { + replaceCount++; + set(this, 'path', path); + }, + }); + } + ); this.router.map(function () { this.route('root', { path: '/' }); @@ -389,21 +401,25 @@ moduleFor( assert.equal(setCount, 1, 'should not call setURL'); assert.equal(replaceCount, 1, 'should call replaceURL once'); - assert.equal(router.get('location').getURL(), '/foo'); + assert.equal(router.location.getURL(), '/foo'); }); } ['@test using replaceWith calls setURL if location.replaceURL is not defined'](assert) { let setCount = 0; - this.router.reopen({ - location: NoneLocation.create({ - setURL(path) { - setCount++; - set(this, 'path', path); - }, - }), - }); + this.subclass( + 'router:main', + (Router) => + class extends Router { + location = NoneLocation.create({ + setURL(path) { + setCount++; + set(this, 'path', path); + }, + }); + } + ); this.router.map(function () { this.route('root', { path: '/' }); @@ -416,7 +432,7 @@ moduleFor( assert.equal(setCount, 1); run(() => router.replaceWith('foo')); assert.equal(setCount, 2, 'should call setURL once'); - assert.equal(router.get('location').getURL(), '/foo'); + assert.equal(router.location.getURL(), '/foo'); }); } @@ -501,7 +517,7 @@ moduleFor( let router = this.applicationInstance.lookup('router:main'); this.handleURLAborts(assert, '/foo/bar/baz'); assert.equal(router.currentPath, 'home'); - assert.equal(router.get('location').getURL(), '/home'); + assert.equal(router.location.getURL(), '/home'); }); } @@ -600,7 +616,7 @@ moduleFor( this.handleURLAborts(assert, '/foo/bar/1/baz'); assert.equal(this.appRouter.currentPath, 'foo.bar.baz'); assert.equal( - this.applicationInstance.lookup('router:main').get('location').getURL(), + this.applicationInstance.lookup('router:main').location.getURL(), '/foo/bar/2/baz' ); }); @@ -638,7 +654,7 @@ moduleFor( assert.equal(router.currentPath, 'foo.bar.baz'); run(() => router.send('goToQux')); assert.equal(router.currentPath, 'foo.qux'); - assert.equal(router.get('location').getURL(), '/foo/qux'); + assert.equal(router.location.getURL(), '/foo/qux'); }); } @@ -648,7 +664,7 @@ moduleFor( let setHistory; setHistory = function (obj, path) { - obj.set('history', { state: { path: path } }); + set(obj, 'history', { state: { path: path } }); }; let location = HistoryLocation.create({ @@ -656,7 +672,7 @@ moduleFor( let path = rootURL + '/posts'; setHistory(this, path); - this.set('location', { + set(this, 'location', { pathname: path, href: 'http://localhost/' + path, }); @@ -671,11 +687,15 @@ moduleFor( }, }); - this.router.reopen({ - // location: 'historyTest', - location, - rootURL: rootURL, - }); + this.subclass( + 'router:main', + (Router) => + class extends Router { + location = location; + + rootURL = rootURL; + } + ); this.router.map(function () { this.route('posts', { path: '/posts' }); @@ -711,24 +731,28 @@ moduleFor( pushState() {}, }; initState() { - assert.equal(this.get('rootURL'), rootURL); + assert.equal(this.rootURL, rootURL); } } ); - this.router.reopen({ - location: 'history-test', - rootURL: rootURL, - // if we transition in this test we will receive failures - // if the tests are run from a static file - _doURLTransition() { - return { - followRedirects() { - return RSVP.resolve(''); - }, - }; - }, - }); + this.subclass( + 'router:main', + (Router) => + class extends Router { + location = 'history-test'; + + rootURL = rootURL; + + _doURLTransition() { + return { + followRedirects() { + return RSVP.resolve(''); + }, + }; + } + } + ); return this.visit('/'); } @@ -1105,7 +1129,7 @@ moduleFor( return this.visit('/').then(() => { let router = this.applicationInstance.lookup('router:main'); - assert.equal(router.get('location.path'), '/about/TreeklesMcGeekles'); + assert.equal(router.location.path, '/about/TreeklesMcGeekles'); }); } diff --git a/packages/ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test.js b/packages/ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test.js index c369825e7c9..64246d3bb41 100644 --- a/packages/ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test.js +++ b/packages/ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test.js @@ -1,7 +1,7 @@ import Controller from '@ember/controller'; import { A as emberA } from '@ember/array'; import Route from '@ember/routing/route'; -import { computed } from '@ember/object'; +import { set } from '@ember/object'; import { precompileTemplate } from '@ember/template-compilation'; import { QueryParamTestCase, moduleFor, runLoopSettled } from 'internal-test-helpers'; @@ -18,14 +18,6 @@ class ModelDependentQPTestCase extends QueryParamTestCase { 'there should be no pending expectation of expected model hook params' ); } - - reopenController(name, options) { - this.application.resolveRegistration(`controller:${name}`).reopen(options); - } - - reopenRoute(name, options) { - this.application.resolveRegistration(`route:${name}`).reopen(options); - } } moduleFor( @@ -69,19 +61,22 @@ moduleFor( this.add( 'controller:article', - Controller.extend({ - queryParams: ['q', 'z'], - q: 'wat', - z: 0, - }) + class extends Controller { + queryParams = ['q', 'z']; + + q = 'wat'; + + z = 0; + } ); this.add( 'controller:comments', - Controller.extend({ - queryParams: 'page', - page: 1, - }) + class extends Controller { + queryParams = ['page']; + + page = 1; + } ); this.add( @@ -133,9 +128,9 @@ moduleFor( this.$link2.click(); await runLoopSettled(); - assert.equal(this.controller.get('q'), 'wat'); - assert.equal(this.controller.get('z'), 0); - assert.deepEqual(this.controller.get('model'), { id: 'a-2' }); + assert.equal(this.controller.q, 'wat'); + assert.equal(this.controller.z, 0); + assert.deepEqual(this.controller.model, { id: 'a-2' }); assert.equal(this.$link1.getAttribute('href'), '/a/a-1?q=lol'); assert.equal(this.$link2.getAttribute('href'), '/a/a-2'); assert.equal(this.$link3.getAttribute('href'), '/a/a-3'); @@ -151,9 +146,9 @@ moduleFor( await this.transitionTo('/a/a-1?q=lol'); - assert.deepEqual(this.controller.get('model'), { id: 'a-1' }); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 0); + assert.deepEqual(this.controller.model, { id: 'a-1' }); + assert.equal(this.controller.q, 'lol'); + assert.equal(this.controller.z, 0); assert.equal(this.$link1.getAttribute('href'), '/a/a-1?q=lol'); assert.equal(this.$link2.getAttribute('href'), '/a/a-2'); assert.equal(this.$link3.getAttribute('href'), '/a/a-3'); @@ -162,13 +157,9 @@ moduleFor( await this.transitionTo('/a/a-2?q=lol'); - assert.deepEqual( - this.controller.get('model'), - { id: 'a-2' }, - "controller's model changed to a-2" - ); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 0); + assert.deepEqual(this.controller.model, { id: 'a-2' }, "controller's model changed to a-2"); + assert.equal(this.controller.q, 'lol'); + assert.equal(this.controller.z, 0); assert.equal(this.$link1.getAttribute('href'), '/a/a-1?q=lol'); assert.equal(this.$link2.getAttribute('href'), '/a/a-2?q=lol'); assert.equal(this.$link3.getAttribute('href'), '/a/a-3'); @@ -177,8 +168,8 @@ moduleFor( await this.transitionTo('/a/a-3?q=lol&z=123'); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 123); + assert.equal(this.controller.q, 'lol'); + assert.equal(this.controller.z, 123); assert.equal(this.$link1.getAttribute('href'), '/a/a-1?q=lol'); assert.equal(this.$link2.getAttribute('href'), '/a/a-2?q=lol'); assert.equal(this.$link3.getAttribute('href'), '/a/a-3?q=lol&z=123'); @@ -204,9 +195,9 @@ moduleFor( this.expectedModelHookParams = { id: 'a-1', q: 'wat', z: 0 }; await this.transitionTo('article', 'a-1'); - assert.deepEqual(this.controller.get('model'), { id: 'a-1' }); - assert.equal(this.controller.get('q'), 'wat'); - assert.equal(this.controller.get('z'), 0); + assert.deepEqual(this.controller.model, { id: 'a-1' }); + assert.equal(this.controller.q, 'wat'); + assert.equal(this.controller.z, 0); assert.equal(this.$link1.getAttribute('href'), '/a/a-1'); assert.equal(this.$link2.getAttribute('href'), '/a/a-2'); assert.equal(this.$link3.getAttribute('href'), '/a/a-3'); @@ -214,9 +205,9 @@ moduleFor( this.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 0 }; await this.transitionTo('article', 'a-2', { queryParams: { q: 'lol' } }); - assert.deepEqual(this.controller.get('model'), { id: 'a-2' }); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 0); + assert.deepEqual(this.controller.model, { id: 'a-2' }); + assert.equal(this.controller.q, 'lol'); + assert.equal(this.controller.z, 0); assert.equal(this.$link1.getAttribute('href'), '/a/a-1'); assert.equal(this.$link2.getAttribute('href'), '/a/a-2?q=lol'); assert.equal(this.$link3.getAttribute('href'), '/a/a-3'); @@ -224,9 +215,9 @@ moduleFor( this.expectedModelHookParams = { id: 'a-3', q: 'hay', z: 0 }; await this.transitionTo('article', 'a-3', { queryParams: { q: 'hay' } }); - assert.deepEqual(this.controller.get('model'), { id: 'a-3' }); - assert.equal(this.controller.get('q'), 'hay'); - assert.equal(this.controller.get('z'), 0); + assert.deepEqual(this.controller.model, { id: 'a-3' }); + assert.equal(this.controller.q, 'hay'); + assert.equal(this.controller.z, 0); assert.equal(this.$link1.getAttribute('href'), '/a/a-1'); assert.equal(this.$link2.getAttribute('href'), '/a/a-2?q=lol'); assert.equal(this.$link3.getAttribute('href'), '/a/a-3?q=hay'); @@ -234,9 +225,9 @@ moduleFor( this.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 1 }; await this.transitionTo('article', 'a-2', { queryParams: { z: 1 } }); - assert.deepEqual(this.controller.get('model'), { id: 'a-2' }); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 1); + assert.deepEqual(this.controller.model, { id: 'a-2' }); + assert.equal(this.controller.q, 'lol'); + assert.equal(this.controller.z, 1); assert.equal(this.$link1.getAttribute('href'), '/a/a-1'); assert.equal(this.$link2.getAttribute('href'), '/a/a-2?q=lol&z=1'); assert.equal(this.$link3.getAttribute('href'), '/a/a-3?q=hay'); @@ -249,9 +240,13 @@ moduleFor( this.setupApplication(); - this.reopenController('article', { - queryParams: { q: { scope: 'controller' } }, - }); + this.subclass( + 'controller:article', + (ArticleController) => + class extends ArticleController { + queryParams = ['q', 'z', { q: { scope: 'controller' } }]; + } + ); await this.visitApplication(); this.$link1.click(); @@ -268,9 +263,9 @@ moduleFor( this.$link2.click(); await runLoopSettled(); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 0); - assert.deepEqual(this.controller.get('model'), { id: 'a-2' }); + assert.equal(this.controller.q, 'lol'); + assert.equal(this.controller.z, 0); + assert.deepEqual(this.controller.model, { id: 'a-2' }); assert.equal(this.$link1.getAttribute('href'), '/a/a-1?q=lol'); assert.equal(this.$link2.getAttribute('href'), '/a/a-2?q=lol'); @@ -279,9 +274,9 @@ moduleFor( this.expectedModelHookParams = { id: 'a-3', q: 'haha', z: 123 }; await this.transitionTo('/a/a-3?q=haha&z=123'); - assert.deepEqual(this.controller.get('model'), { id: 'a-3' }); - assert.equal(this.controller.get('q'), 'haha'); - assert.equal(this.controller.get('z'), 123); + assert.deepEqual(this.controller.model, { id: 'a-3' }); + assert.equal(this.controller.q, 'haha'); + assert.equal(this.controller.z, 123); assert.equal(this.$link1.getAttribute('href'), '/a/a-1?q=haha'); assert.equal(this.$link2.getAttribute('href'), '/a/a-2?q=haha'); @@ -303,7 +298,7 @@ moduleFor( await this.transitionTo('comments', 'a-1'); let commentsCtrl = this.getController('comments'); - assert.equal(commentsCtrl.get('page'), 1); + assert.equal(commentsCtrl.page, 1); this.assertCurrentPath('/a/a-1/comments'); await this.setAndFlush(commentsCtrl, 'page', 2); @@ -313,11 +308,11 @@ moduleFor( this.assertCurrentPath('/a/a-1/comments?page=3'); await this.transitionTo('comments', 'a-2'); - assert.equal(commentsCtrl.get('page'), 1); + assert.equal(commentsCtrl.page, 1); this.assertCurrentPath('/a/a-2/comments'); await this.transitionTo('comments', 'a-1'); - assert.equal(commentsCtrl.get('page'), 3); + assert.equal(commentsCtrl.page, 3); this.assertCurrentPath('/a/a-1/comments?page=3'); } @@ -328,14 +323,18 @@ moduleFor( this.setupApplication(); - this.reopenRoute('article', { - resetController(controller, isExiting) { - this.controllerFor('comments').set('page', 1); - if (isExiting) { - controller.set('q', 'imdone'); + this.subclass( + 'route:article', + (ArticleRoute) => + class extends ArticleRoute { + resetController(controller, isExiting) { + set(this.controllerFor('comments'), 'page', 1); + if (isExiting) { + set(controller, 'q', 'imdone'); + } + } } - }, - }); + ); this.add( 'template:about', @@ -351,19 +350,19 @@ moduleFor( await this.transitionTo('comments', 'a-1'); let commentsCtrl = this.getController('comments'); - assert.equal(commentsCtrl.get('page'), 1); + assert.equal(commentsCtrl.page, 1); this.assertCurrentPath('/a/a-1/comments'); await this.setAndFlush(commentsCtrl, 'page', 2); this.assertCurrentPath('/a/a-1/comments?page=2'); await this.transitionTo('comments', 'a-2'); - assert.equal(commentsCtrl.get('page'), 1); - assert.equal(this.controller.get('q'), 'wat'); + assert.equal(commentsCtrl.page, 1); + assert.equal(this.controller.q, 'wat'); await this.transitionTo('comments', 'a-1'); this.assertCurrentPath('/a/a-1/comments'); - assert.equal(commentsCtrl.get('page'), 1); + assert.equal(commentsCtrl.page, 1); await this.transitionTo('about'); assert.equal(document.getElementById('one').getAttribute('href'), '/a/a-1/comments?q=imdone'); @@ -415,19 +414,22 @@ moduleFor( this.add( 'controller:site.article', - Controller.extend({ - queryParams: ['q', 'z'], - q: 'wat', - z: 0, - }) + class extends Controller { + queryParams = ['q', 'z']; + + q = 'wat'; + + z = 0; + } ); this.add( 'controller:site.article.comments', - Controller.extend({ - queryParams: 'page', - page: 1, - }) + class extends Controller { + queryParams = ['page']; + + page = 1; + } ); this.add( @@ -479,9 +481,9 @@ moduleFor( this.$link2.click(); await runLoopSettled(); - assert.equal(this.controller.get('q'), 'wat'); - assert.equal(this.controller.get('z'), 0); - assert.deepEqual(this.controller.get('model'), { id: 'a-2' }); + assert.equal(this.controller.q, 'wat'); + assert.equal(this.controller.z, 0); + assert.deepEqual(this.controller.model, { id: 'a-2' }); assert.equal(this.$link1.getAttribute('href'), '/site/a/a-1?q=lol'); assert.equal(this.$link2.getAttribute('href'), '/site/a/a-2'); assert.equal(this.$link3.getAttribute('href'), '/site/a/a-3'); @@ -497,9 +499,9 @@ moduleFor( await this.transitionTo('/site/a/a-1?q=lol'); - assert.deepEqual(this.controller.get('model'), { id: 'a-1' }); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 0); + assert.deepEqual(this.controller.model, { id: 'a-1' }); + assert.equal(this.controller.q, 'lol'); + assert.equal(this.controller.z, 0); assert.equal(this.$link1.getAttribute('href'), '/site/a/a-1?q=lol'); assert.equal(this.$link2.getAttribute('href'), '/site/a/a-2'); assert.equal(this.$link3.getAttribute('href'), '/site/a/a-3'); @@ -508,13 +510,9 @@ moduleFor( await this.transitionTo('/site/a/a-2?q=lol'); - assert.deepEqual( - this.controller.get('model'), - { id: 'a-2' }, - "controller's model changed to a-2" - ); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 0); + assert.deepEqual(this.controller.model, { id: 'a-2' }, "controller's model changed to a-2"); + assert.equal(this.controller.q, 'lol'); + assert.equal(this.controller.z, 0); assert.equal(this.$link1.getAttribute('href'), '/site/a/a-1?q=lol'); assert.equal(this.$link2.getAttribute('href'), '/site/a/a-2?q=lol'); assert.equal(this.$link3.getAttribute('href'), '/site/a/a-3'); @@ -523,8 +521,8 @@ moduleFor( await this.transitionTo('/site/a/a-3?q=lol&z=123'); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 123); + assert.equal(this.controller.q, 'lol'); + assert.equal(this.controller.z, 123); assert.equal(this.$link1.getAttribute('href'), '/site/a/a-1?q=lol'); assert.equal(this.$link2.getAttribute('href'), '/site/a/a-2?q=lol'); assert.equal(this.$link3.getAttribute('href'), '/site/a/a-3?q=lol&z=123'); @@ -550,9 +548,9 @@ moduleFor( this.expectedModelHookParams = { id: 'a-1', q: 'wat', z: 0 }; await this.transitionTo('site.article', 'a-1'); - assert.deepEqual(this.controller.get('model'), { id: 'a-1' }); - assert.equal(this.controller.get('q'), 'wat'); - assert.equal(this.controller.get('z'), 0); + assert.deepEqual(this.controller.model, { id: 'a-1' }); + assert.equal(this.controller.q, 'wat'); + assert.equal(this.controller.z, 0); assert.equal(this.$link1.getAttribute('href'), '/site/a/a-1'); assert.equal(this.$link2.getAttribute('href'), '/site/a/a-2'); assert.equal(this.$link3.getAttribute('href'), '/site/a/a-3'); @@ -560,9 +558,9 @@ moduleFor( this.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 0 }; await this.transitionTo('site.article', 'a-2', { queryParams: { q: 'lol' } }); - assert.deepEqual(this.controller.get('model'), { id: 'a-2' }); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 0); + assert.deepEqual(this.controller.model, { id: 'a-2' }); + assert.equal(this.controller.q, 'lol'); + assert.equal(this.controller.z, 0); assert.equal(this.$link1.getAttribute('href'), '/site/a/a-1'); assert.equal(this.$link2.getAttribute('href'), '/site/a/a-2?q=lol'); assert.equal(this.$link3.getAttribute('href'), '/site/a/a-3'); @@ -570,9 +568,9 @@ moduleFor( this.expectedModelHookParams = { id: 'a-3', q: 'hay', z: 0 }; await this.transitionTo('site.article', 'a-3', { queryParams: { q: 'hay' } }); - assert.deepEqual(this.controller.get('model'), { id: 'a-3' }); - assert.equal(this.controller.get('q'), 'hay'); - assert.equal(this.controller.get('z'), 0); + assert.deepEqual(this.controller.model, { id: 'a-3' }); + assert.equal(this.controller.q, 'hay'); + assert.equal(this.controller.z, 0); assert.equal(this.$link1.getAttribute('href'), '/site/a/a-1'); assert.equal(this.$link2.getAttribute('href'), '/site/a/a-2?q=lol'); assert.equal(this.$link3.getAttribute('href'), '/site/a/a-3?q=hay'); @@ -580,9 +578,9 @@ moduleFor( this.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 1 }; await this.transitionTo('site.article', 'a-2', { queryParams: { z: 1 } }); - assert.deepEqual(this.controller.get('model'), { id: 'a-2' }); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 1); + assert.deepEqual(this.controller.model, { id: 'a-2' }); + assert.equal(this.controller.q, 'lol'); + assert.equal(this.controller.z, 1); assert.equal(this.$link1.getAttribute('href'), '/site/a/a-1'); assert.equal(this.$link2.getAttribute('href'), '/site/a/a-2?q=lol&z=1'); assert.equal(this.$link3.getAttribute('href'), '/site/a/a-3?q=hay'); @@ -595,9 +593,13 @@ moduleFor( this.setupApplication(); - this.reopenController('site.article', { - queryParams: { q: { scope: 'controller' } }, - }); + this.subclass( + 'controller:site.article', + (ArticleController) => + class extends ArticleController { + queryParams = ['q', 'z', { q: { scope: 'controller' } }]; + } + ); await this.visitApplication(); this.$link1.click(); @@ -614,9 +616,9 @@ moduleFor( this.$link2.click(); await runLoopSettled(); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 0); - assert.deepEqual(this.controller.get('model'), { id: 'a-2' }); + assert.equal(this.controller.q, 'lol'); + assert.equal(this.controller.z, 0); + assert.deepEqual(this.controller.model, { id: 'a-2' }); assert.equal(this.$link1.getAttribute('href'), '/site/a/a-1?q=lol'); assert.equal(this.$link2.getAttribute('href'), '/site/a/a-2?q=lol'); @@ -625,9 +627,9 @@ moduleFor( this.expectedModelHookParams = { id: 'a-3', q: 'haha', z: 123 }; await this.transitionTo('/site/a/a-3?q=haha&z=123'); - assert.deepEqual(this.controller.get('model'), { id: 'a-3' }); - assert.equal(this.controller.get('q'), 'haha'); - assert.equal(this.controller.get('z'), 123); + assert.deepEqual(this.controller.model, { id: 'a-3' }); + assert.equal(this.controller.q, 'haha'); + assert.equal(this.controller.z, 123); assert.equal(this.$link1.getAttribute('href'), '/site/a/a-1?q=haha'); assert.equal(this.$link2.getAttribute('href'), '/site/a/a-2?q=haha'); @@ -649,7 +651,7 @@ moduleFor( await this.transitionTo('site.article.comments', 'a-1'); let commentsCtrl = this.getController('site.article.comments'); - assert.equal(commentsCtrl.get('page'), 1); + assert.equal(commentsCtrl.page, 1); this.assertCurrentPath('/site/a/a-1/comments'); await this.setAndFlush(commentsCtrl, 'page', 2); @@ -659,11 +661,11 @@ moduleFor( this.assertCurrentPath('/site/a/a-1/comments?page=3'); await this.transitionTo('site.article.comments', 'a-2'); - assert.equal(commentsCtrl.get('page'), 1); + assert.equal(commentsCtrl.page, 1); this.assertCurrentPath('/site/a/a-2/comments'); await this.transitionTo('site.article.comments', 'a-1'); - assert.equal(commentsCtrl.get('page'), 3); + assert.equal(commentsCtrl.page, 3); this.assertCurrentPath('/site/a/a-1/comments?page=3'); } @@ -674,14 +676,18 @@ moduleFor( this.setupApplication(); - this.reopenRoute('site.article', { - resetController(controller, isExiting) { - this.controllerFor('site.article.comments').set('page', 1); - if (isExiting) { - controller.set('q', 'imdone'); + this.subclass( + 'route:site.article', + (ArticleRoute) => + class extends ArticleRoute { + resetController(controller, isExiting) { + set(this.controllerFor('site.article.comments'), 'page', 1); + if (isExiting) { + set(controller, 'q', 'imdone'); + } + } } - }, - }); + ); this.add( 'template:about', @@ -697,19 +703,19 @@ moduleFor( await this.transitionTo('site.article.comments', 'a-1'); let commentsCtrl = this.getController('site.article.comments'); - assert.equal(commentsCtrl.get('page'), 1); + assert.equal(commentsCtrl.page, 1); this.assertCurrentPath('/site/a/a-1/comments'); await this.setAndFlush(commentsCtrl, 'page', 2); this.assertCurrentPath('/site/a/a-1/comments?page=2'); await this.transitionTo('site.article.comments', 'a-2'); - assert.equal(commentsCtrl.get('page'), 1); - assert.equal(this.controller.get('q'), 'wat'); + assert.equal(commentsCtrl.page, 1); + assert.equal(this.controller.q, 'wat'); await this.transitionTo('site.article.comments', 'a-1'); this.assertCurrentPath('/site/a/a-1/comments'); - assert.equal(commentsCtrl.get('page'), 1); + assert.equal(commentsCtrl.page, 1); await this.transitionTo('about'); assert.equal( @@ -741,7 +747,7 @@ moduleFor( class extends Controller { siteArticles = site_articles; sites = sites; - @computed + get allSitesAllArticles() { let ret = []; let siteArticles = this.siteArticles; @@ -800,27 +806,31 @@ moduleFor( this.add( 'controller:site', - Controller.extend({ - queryParams: ['country'], - country: 'au', - }) + class extends Controller { + queryParams = ['country']; + + country = 'au'; + } ); this.add( 'controller:site.article', - Controller.extend({ - queryParams: ['q', 'z'], - q: 'wat', - z: 0, - }) + class extends Controller { + queryParams = ['q', 'z']; + + q = 'wat'; + + z = 0; + } ); this.add( 'controller:site.article.comments', - Controller.extend({ - queryParams: ['page'], - page: 1, - }) + class extends Controller { + queryParams = ['page']; + + page = 1; + } ); this.add( @@ -874,8 +884,8 @@ moduleFor( await this.boot(); this.links['s-1-a-1'].click(); await runLoopSettled(); - assert.deepEqual(this.site_controller.get('model'), { id: 's-1' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-1' }); + assert.deepEqual(this.site_controller.model, { id: 's-1' }); + assert.deepEqual(this.article_controller.model, { id: 'a-1' }); this.assertCurrentPath('/site/s-1/a/a-1'); await this.setAndFlush(this.article_controller, 'q', 'lol'); @@ -905,11 +915,11 @@ moduleFor( this.links['s-1-a-2'].click(); await runLoopSettled(); - assert.equal(this.site_controller.get('country'), 'us'); - assert.equal(this.article_controller.get('q'), 'wat'); - assert.equal(this.article_controller.get('z'), 0); - assert.deepEqual(this.site_controller.get('model'), { id: 's-1' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-2' }); + assert.equal(this.site_controller.country, 'us'); + assert.equal(this.article_controller.q, 'wat'); + assert.equal(this.article_controller.z, 0); + assert.deepEqual(this.site_controller.model, { id: 's-1' }); + assert.deepEqual(this.article_controller.model, { id: 'a-2' }); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?country=us&q=lol'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?country=us'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?country=us'); @@ -923,11 +933,11 @@ moduleFor( this.links['s-2-a-2'].click(); await runLoopSettled(); - assert.equal(this.site_controller.get('country'), 'au'); - assert.equal(this.article_controller.get('q'), 'wat'); - assert.equal(this.article_controller.get('z'), 0); - assert.deepEqual(this.site_controller.get('model'), { id: 's-2' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-2' }); + assert.equal(this.site_controller.country, 'au'); + assert.equal(this.article_controller.q, 'wat'); + assert.equal(this.article_controller.z, 0); + assert.deepEqual(this.site_controller.model, { id: 's-2' }); + assert.deepEqual(this.article_controller.model, { id: 'a-2' }); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?country=us&q=lol'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?country=us'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?country=us'); @@ -951,19 +961,15 @@ moduleFor( }; await this.transitionTo('/site/s-1/a/a-1?q=lol'); + assert.deepEqual(this.site_controller.model, { id: 's-1' }, "site controller's model is s-1"); assert.deepEqual( - this.site_controller.get('model'), - { id: 's-1' }, - "site controller's model is s-1" - ); - assert.deepEqual( - this.article_controller.get('model'), + this.article_controller.model, { id: 'a-1' }, "article controller's model is a-1" ); - assert.equal(this.site_controller.get('country'), 'au'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 0); + assert.equal(this.site_controller.country, 'au'); + assert.equal(this.article_controller.q, 'lol'); + assert.equal(this.article_controller.z, 0); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3'); @@ -982,19 +988,15 @@ moduleFor( }; await this.transitionTo('/site/s-2/a/a-1?country=us&q=lol'); + assert.deepEqual(this.site_controller.model, { id: 's-2' }, "site controller's model is s-2"); assert.deepEqual( - this.site_controller.get('model'), - { id: 's-2' }, - "site controller's model is s-2" - ); - assert.deepEqual( - this.article_controller.get('model'), + this.article_controller.model, { id: 'a-1' }, "article controller's model is a-1" ); - assert.equal(this.site_controller.get('country'), 'us'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 0); + assert.equal(this.site_controller.country, 'us'); + assert.equal(this.article_controller.q, 'lol'); + assert.equal(this.article_controller.z, 0); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3'); @@ -1013,19 +1015,15 @@ moduleFor( }; await this.transitionTo('/site/s-2/a/a-2?country=us&q=lol'); + assert.deepEqual(this.site_controller.model, { id: 's-2' }, "site controller's model is s-2"); assert.deepEqual( - this.site_controller.get('model'), - { id: 's-2' }, - "site controller's model is s-2" - ); - assert.deepEqual( - this.article_controller.get('model'), + this.article_controller.model, { id: 'a-2' }, "article controller's model is a-2" ); - assert.equal(this.site_controller.get('country'), 'us'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 0); + assert.equal(this.site_controller.country, 'us'); + assert.equal(this.article_controller.q, 'lol'); + assert.equal(this.article_controller.z, 0); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3'); @@ -1044,19 +1042,15 @@ moduleFor( }; await this.transitionTo('/site/s-2/a/a-3?country=us&q=lol&z=123'); + assert.deepEqual(this.site_controller.model, { id: 's-2' }, "site controller's model is s-2"); assert.deepEqual( - this.site_controller.get('model'), - { id: 's-2' }, - "site controller's model is s-2" - ); - assert.deepEqual( - this.article_controller.get('model'), + this.article_controller.model, { id: 'a-3' }, "article controller's model is a-3" ); - assert.equal(this.site_controller.get('country'), 'us'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 123); + assert.equal(this.site_controller.country, 'us'); + assert.equal(this.article_controller.q, 'lol'); + assert.equal(this.article_controller.z, 123); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?q=lol&z=123'); @@ -1078,19 +1072,15 @@ moduleFor( }; await this.transitionTo('/site/s-3/a/a-3?country=nz&q=lol&z=123'); + assert.deepEqual(this.site_controller.model, { id: 's-3' }, "site controller's model is s-3"); assert.deepEqual( - this.site_controller.get('model'), - { id: 's-3' }, - "site controller's model is s-3" - ); - assert.deepEqual( - this.article_controller.get('model'), + this.article_controller.model, { id: 'a-3' }, "article controller's model is a-3" ); - assert.equal(this.site_controller.get('country'), 'nz'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 123); + assert.equal(this.site_controller.country, 'nz'); + assert.equal(this.article_controller.q, 'lol'); + assert.equal(this.article_controller.z, 123); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?q=lol&z=123'); @@ -1122,11 +1112,11 @@ moduleFor( }; await this.transitionTo('site.article', 's-1', 'a-1'); - assert.deepEqual(this.site_controller.get('model'), { id: 's-1' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-1' }); - assert.equal(this.site_controller.get('country'), 'au'); - assert.equal(this.article_controller.get('q'), 'wat'); - assert.equal(this.article_controller.get('z'), 0); + assert.deepEqual(this.site_controller.model, { id: 's-1' }); + assert.deepEqual(this.article_controller.model, { id: 'a-1' }); + assert.equal(this.site_controller.country, 'au'); + assert.equal(this.article_controller.q, 'wat'); + assert.equal(this.article_controller.z, 0); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3'); @@ -1147,11 +1137,11 @@ moduleFor( queryParams: { q: 'lol' }, }); - assert.deepEqual(this.site_controller.get('model'), { id: 's-1' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-2' }); - assert.equal(this.site_controller.get('country'), 'au'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 0); + assert.deepEqual(this.site_controller.model, { id: 's-1' }); + assert.deepEqual(this.article_controller.model, { id: 'a-2' }); + assert.equal(this.site_controller.country, 'au'); + assert.equal(this.article_controller.q, 'lol'); + assert.equal(this.article_controller.z, 0); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3'); @@ -1172,11 +1162,11 @@ moduleFor( queryParams: { q: 'hay' }, }); - assert.deepEqual(this.site_controller.get('model'), { id: 's-1' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-3' }); - assert.equal(this.site_controller.get('country'), 'au'); - assert.equal(this.article_controller.get('q'), 'hay'); - assert.equal(this.article_controller.get('z'), 0); + assert.deepEqual(this.site_controller.model, { id: 's-1' }); + assert.deepEqual(this.article_controller.model, { id: 'a-3' }); + assert.equal(this.site_controller.country, 'au'); + assert.equal(this.article_controller.q, 'hay'); + assert.equal(this.article_controller.z, 0); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?q=hay'); @@ -1197,11 +1187,11 @@ moduleFor( queryParams: { z: 1 }, }); - assert.deepEqual(this.site_controller.get('model'), { id: 's-1' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-2' }); - assert.equal(this.site_controller.get('country'), 'au'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 1); + assert.deepEqual(this.site_controller.model, { id: 's-1' }); + assert.deepEqual(this.article_controller.model, { id: 'a-2' }); + assert.equal(this.site_controller.country, 'au'); + assert.equal(this.article_controller.q, 'lol'); + assert.equal(this.article_controller.z, 1); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol&z=1'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?q=hay'); @@ -1222,11 +1212,11 @@ moduleFor( queryParams: { country: 'us' }, }); - assert.deepEqual(this.site_controller.get('model'), { id: 's-2' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-2' }); - assert.equal(this.site_controller.get('country'), 'us'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 1); + assert.deepEqual(this.site_controller.model, { id: 's-2' }); + assert.deepEqual(this.article_controller.model, { id: 'a-2' }); + assert.equal(this.site_controller.country, 'us'); + assert.equal(this.article_controller.q, 'lol'); + assert.equal(this.article_controller.z, 1); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol&z=1'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?q=hay'); @@ -1250,11 +1240,11 @@ moduleFor( queryParams: { q: 'yeah' }, }); - assert.deepEqual(this.site_controller.get('model'), { id: 's-2' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-1' }); - assert.equal(this.site_controller.get('country'), 'us'); - assert.equal(this.article_controller.get('q'), 'yeah'); - assert.equal(this.article_controller.get('z'), 0); + assert.deepEqual(this.site_controller.model, { id: 's-2' }); + assert.deepEqual(this.article_controller.model, { id: 'a-1' }); + assert.equal(this.site_controller.country, 'us'); + assert.equal(this.article_controller.q, 'yeah'); + assert.equal(this.article_controller.z, 0); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?q=yeah'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol&z=1'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?q=hay'); @@ -1278,11 +1268,11 @@ moduleFor( queryParams: { country: 'nz', z: 3 }, }); - assert.deepEqual(this.site_controller.get('model'), { id: 's-3' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-3' }); - assert.equal(this.site_controller.get('country'), 'nz'); - assert.equal(this.article_controller.get('q'), 'hay'); - assert.equal(this.article_controller.get('z'), 3); + assert.deepEqual(this.site_controller.model, { id: 's-3' }); + assert.deepEqual(this.article_controller.model, { id: 'a-3' }); + assert.equal(this.site_controller.country, 'nz'); + assert.equal(this.article_controller.q, 'hay'); + assert.equal(this.article_controller.z, 3); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?q=yeah'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol&z=1'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?q=hay&z=3'); diff --git a/packages/ember/tests/routing/query_params_test/overlapping_query_params_test.js b/packages/ember/tests/routing/query_params_test/overlapping_query_params_test.js index 3843cde3489..3ac00725bbd 100644 --- a/packages/ember/tests/routing/query_params_test/overlapping_query_params_test.js +++ b/packages/ember/tests/routing/query_params_test/overlapping_query_params_test.js @@ -1,4 +1,5 @@ import Controller from '@ember/controller'; +import { set } from '@ember/object'; import Route from '@ember/routing/route'; import { QueryParamTestCase, moduleFor, runLoopSettled } from 'internal-test-helpers'; @@ -37,14 +38,14 @@ moduleFor( await this.setAndFlush(parentChildController, 'page', 1); this.assertCurrentPath('/parent/child'); - parentController.set('page', 2); - parentChildController.set('page', 2); + set(parentController, 'page', 2); + set(parentChildController, 'page', 2); await runLoopSettled(); this.assertCurrentPath('/parent/child?childPage=2&parentPage=2'); - parentController.set('page', 1); - parentChildController.set('page', 1); + set(parentController, 'page', 1); + set(parentChildController, 'page', 1); await runLoopSettled(); this.assertCurrentPath('/parent/child'); @@ -115,9 +116,9 @@ moduleFor( ) { assert.expect(1); - let parentController = Controller.extend({ - queryParams: { page: 'page' }, - }); + let parentController = class extends Controller { + queryParams = [{ page: 'page' }]; + }; this.add('controller:parent', parentController); this.add( 'route:parent.child', @@ -149,19 +150,21 @@ moduleFor( async ['@test Support shared but overridable query param defaults'](assert) { assert.expect(7); - let hasPage = { - queryParams: 'page', - page: 1, - }; - this.add( 'controller:parent', - Controller.extend(hasPage, { - queryParams: { page: 'yespage' }, - }) + class extends Controller { + queryParams = ['page', { page: 'yespage' }]; + page = 1; + } ); - this.add('controller:parent.child', Controller.extend(hasPage)); + this.add( + 'controller:parent.child', + class extends Controller { + queryParams = ['page']; + page = 1; + } + ); await this.setupBase(); this.assertCurrentPath('/parent/child'); @@ -171,13 +174,13 @@ moduleFor( await this.setAndFlush(parentChildController, 'page', 2); this.assertCurrentPath('/parent/child?page=2'); - assert.equal(parentController.get('page'), 1); - assert.equal(parentChildController.get('page'), 2); + assert.equal(parentController.page, 1); + assert.equal(parentChildController.page, 2); await this.setAndFlush(parentController, 'page', 2); this.assertCurrentPath('/parent/child?page=2&yespage=2'); - assert.equal(parentController.get('page'), 2); - assert.equal(parentChildController.get('page'), 2); + assert.equal(parentController.page, 2); + assert.equal(parentChildController.page, 2); } } ); 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 aa5cc812eea..a2f20bef83b 100644 --- a/packages/ember/tests/routing/router_service_test/basic_test.js +++ b/packages/ember/tests/routing/router_service_test/basic_test.js @@ -19,7 +19,7 @@ moduleFor( assert.deepEqual(queryParams, {}); assert.deepEqual(paramNames, []); - assert.equal(this.routerService.get('currentRouteName'), 'parent.index'); + assert.equal(this.routerService.currentRouteName, 'parent.index'); }); } @@ -35,7 +35,7 @@ moduleFor( assert.deepEqual(queryParams, {}); assert.deepEqual(paramNames, []); - assert.equal(this.routerService.get('currentRouteName'), 'parent.child'); + assert.equal(this.routerService.currentRouteName, 'parent.child'); }); } @@ -57,7 +57,7 @@ moduleFor( assert.equal(name, 'parent.sister'); assert.equal(localName, 'sister'); - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); + assert.equal(this.routerService.currentRouteName, 'parent.sister'); }); } @@ -93,7 +93,7 @@ moduleFor( assert.equal(name, 'parent.child'); assert.equal(localName, 'child'); - assert.equal(this.routerService.get('currentRouteName'), 'parent.child'); + assert.equal(this.routerService.currentRouteName, 'parent.child'); return this.visit('/sister'); }) @@ -103,7 +103,7 @@ moduleFor( assert.equal(name, 'parent.sister'); assert.equal(localName, 'sister'); - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); + assert.equal(this.routerService.currentRouteName, 'parent.sister'); return this.visit('/brother'); }) @@ -113,7 +113,7 @@ moduleFor( assert.equal(name, 'parent.brother'); assert.equal(localName, 'brother'); - assert.equal(this.routerService.get('currentRouteName'), 'parent.brother'); + assert.equal(this.routerService.currentRouteName, 'parent.brother'); }); } @@ -121,7 +121,7 @@ moduleFor( assert.expect(1); return this.visit('/').then(() => { - assert.equal(this.routerService.get('rootURL'), '/'); + assert.equal(this.routerService.rootURL, '/'); }); } @@ -139,7 +139,7 @@ moduleFor( ); return this.visit('/').then(() => { - assert.equal(this.routerService.get('rootURL'), '/homepage'); + assert.equal(this.routerService.rootURL, '/homepage'); }); } @@ -147,7 +147,7 @@ moduleFor( assert.expect(2); return this.visit('/').then(() => { - let location = this.routerService.get('location'); + let location = this.routerService.location; assert.ok(location); assert.ok(location instanceof NoneLocation); }); @@ -156,14 +156,19 @@ moduleFor( ['@test RouterService can be injected into router and accessed on init'](assert) { assert.expect(1); - this.router.reopen({ - routerService: service('router'), - init() { - this.routerService.one('routeDidChange', () => { - assert.ok(true, 'routeDidChange event listener called'); - }); - }, - }); + this.subclass( + 'router:main', + (Router) => + class extends Router { + @service('router') routerService; + + init() { + this.routerService.one('routeDidChange', () => { + assert.ok(true, 'routeDidChange event listener called'); + }); + } + } + ); return this.visit('/'); } diff --git a/packages/ember/tests/routing/router_service_test/recognize_test.js b/packages/ember/tests/routing/router_service_test/recognize_test.js index 19674c280dd..03884bcf61d 100644 --- a/packages/ember/tests/routing/router_service_test/recognize_test.js +++ b/packages/ember/tests/routing/router_service_test/recognize_test.js @@ -33,9 +33,13 @@ moduleFor( } '@test respects the usage of a different rootURL'(assert) { - this.router.reopen({ - rootURL: '/app/', - }); + this.subclass( + 'router:main', + (Router) => + class extends Router { + rootURL = '/app/'; + } + ); return this.visit('/app').then(() => { let routeInfo = this.routerService.recognize('/app/child/'); @@ -51,9 +55,13 @@ moduleFor( this.add('template:parent', precompileTemplate('Parent')); this.add('template:dynamic-with-child.child', precompileTemplate('Dynamic Child')); - this.router.reopen({ - rootURL: '/app/', - }); + this.subclass( + 'router:main', + (Router) => + class extends Router { + rootURL = '/app/'; + } + ); return this.visit('/app').then(() => { expectAssertion(() => { @@ -138,9 +146,13 @@ moduleFor( } '@test respects the usage of a different rootURL'(assert) { - this.router.reopen({ - rootURL: '/app/', - }); + this.subclass( + 'router:main', + (Router) => + class extends Router { + rootURL = '/app/'; + } + ); return this.visit('/app') .then(() => { @@ -156,9 +168,13 @@ moduleFor( } '@test must include rootURL'() { - this.router.reopen({ - rootURL: '/app/', - }); + this.subclass( + 'router:main', + (Router) => + class extends Router { + rootURL = '/app/'; + } + ); return this.visit('/app').then(() => { expectAssertion(() => { 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 2378177d65d..af7776804ba 100644 --- a/packages/ember/tests/routing/router_service_test/transitionTo_test.js +++ b/packages/ember/tests/routing/router_service_test/transitionTo_test.js @@ -3,7 +3,7 @@ import Component from '@glimmer/component'; import Route from '@ember/routing/route'; import NoneLocation from '@ember/routing/none-location'; import Controller from '@ember/controller'; -import { action, get } from '@ember/object'; +import { action, get, set } from '@ember/object'; import { precompileTemplate } from '@ember/template-compilation'; import { setComponentTemplate } from '@glimmer/manager'; import { RouterTestCase, moduleFor } from 'internal-test-helpers'; @@ -24,12 +24,12 @@ moduleFor( class extends NoneLocation { setURL(path) { testCase.state.push(path); - this.set('path', path); + set(this, 'path', path); } replaceURL(path) { testCase.state.splice(testCase.state.length - 1, 1, path); - this.set('path', path); + set(this, 'path', path); } } ); @@ -127,7 +127,7 @@ moduleFor( componentInstance.transitionToSister(); await settled(); - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); + assert.equal(this.routerService.currentRouteName, 'parent.sister'); } async ['@test RouterService#transitionTo with basic route using URL'](assert) { @@ -161,7 +161,7 @@ moduleFor( componentInstance.transitionToSister(); await settled(); - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); + assert.equal(this.routerService.currentRouteName, 'parent.sister'); } async ['@test RouterService#transitionTo with dynamic segment'](assert) { @@ -197,8 +197,8 @@ moduleFor( componentInstance.transitionToDynamic(); await settled(); - assert.equal(this.routerService.get('currentRouteName'), 'dynamic'); - assert.equal(this.routerService.get('currentURL'), '/dynamic/1'); + assert.equal(this.routerService.currentRouteName, 'dynamic'); + assert.equal(this.routerService.currentURL, '/dynamic/1'); this.assertText('much dynamicism'); } @@ -244,8 +244,8 @@ moduleFor( componentInstance.transitionToDynamic(); await settled(); - assert.equal(this.routerService.get('currentRouteName'), 'dynamic'); - assert.equal(this.routerService.get('currentURL'), '/dynamic/1'); + assert.equal(this.routerService.currentRouteName, 'dynamic'); + assert.equal(this.routerService.currentURL, '/dynamic/1'); this.assertText('much dynamicism'); } @@ -256,10 +256,11 @@ moduleFor( this.add( 'controller:parent.child', - Controller.extend({ - queryParams: ['sort'], - sort: 'ASC', - }) + class extends Controller { + queryParams = ['sort']; + + sort = 'ASC'; + } ); let queryParams = this.buildQueryParams({ sort: 'ASC' }); @@ -269,7 +270,7 @@ moduleFor( return this.routerService.transitionTo('parent.child', queryParams); }) .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child'); + assert.equal(this.routerService.currentURL, '/child'); }); } @@ -278,9 +279,9 @@ moduleFor( this.add( 'controller:parent.child', - Controller.extend({ - queryParams: ['sort'], - }) + class extends Controller { + queryParams = ['sort']; + } ); let queryParams = this.buildQueryParams({ sort: 'DESC' }); @@ -290,13 +291,13 @@ moduleFor( return this.routerService.transitionTo('parent.child'); }) .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child'); + assert.equal(this.routerService.currentURL, '/child'); }) .then(() => { return this.routerService.transitionTo(queryParams); }) .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child?sort=DESC'); + assert.equal(this.routerService.currentURL, '/child?sort=DESC'); }); } @@ -305,12 +306,15 @@ moduleFor( this.add( 'controller:parent.child', - Controller.extend({ - queryParams: ['sort', 'page', 'category', 'extra'], - sort: 'ASC', - page: null, - category: undefined, - }) + class extends Controller { + queryParams = ['sort', 'page', 'category', 'extra']; + + sort = 'ASC'; + + page = null; + + category = undefined; + } ); let queryParams = this.buildQueryParams({ sort: 'DESC' }); @@ -320,7 +324,7 @@ moduleFor( return this.routerService.transitionTo('parent.child', queryParams); }) .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child?sort=DESC'); + assert.equal(this.routerService.currentURL, '/child?sort=DESC'); }); } @@ -331,12 +335,15 @@ moduleFor( this.add( 'controller:parent.child', - Controller.extend({ - queryParams: { - cont_sort: 'url_sort', - }, - cont_sort: 'ASC', - }) + class extends Controller { + queryParams = [ + { + cont_sort: 'url_sort', + }, + ]; + + cont_sort = 'ASC'; + } ); let queryParams = this.buildQueryParams({ url_sort: 'DESC' }); @@ -346,7 +353,7 @@ moduleFor( return this.routerService.transitionTo('parent.child', queryParams); }) .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child?url_sort=DESC'); + assert.equal(this.routerService.currentURL, '/child?url_sort=DESC'); }); } @@ -357,12 +364,15 @@ moduleFor( this.add( 'controller:parent.child', - Controller.extend({ - queryParams: { - cont_sort: 'url_sort', - }, - cont_sort: 'ASC', - }) + class extends Controller { + queryParams = [ + { + cont_sort: 'url_sort', + }, + ]; + + cont_sort = 'ASC'; + } ); let queryParams = this.buildQueryParams({ cont_sort: 'ASC' }); @@ -396,16 +406,17 @@ moduleFor( this.add( 'route:parent.child', - Route.extend({ - queryParams: { + class extends Route { + queryParams = { cont_sort: { as: 'url_sort' }, - }, - cont_sort: 'ASC', - }) + }; + + cont_sort = 'ASC'; + } ); return this.visit('/').then(() => { - assert.equal(this.routerService.get('currentURL'), '/child?url_sort=ASC'); + assert.equal(this.routerService.currentURL, '/child?url_sort=ASC'); }); } @@ -426,13 +437,13 @@ moduleFor( ); this.add( 'controller:parent', - Controller.extend({ - queryParams: ['url_sort'], - }) + class extends Controller { + queryParams = ['url_sort']; + } ); return this.visit('/child?url_sort=a').then(() => { - assert.equal(this.routerService.get('currentURL'), '/?url_sort=a'); + assert.equal(this.routerService.currentURL, '/?url_sort=a'); }); } @@ -459,22 +470,23 @@ moduleFor( this.add( 'controller:parent.child', - Controller.extend({ - queryParams: ['bar'], - bar: null, - }) + class extends Controller { + queryParams = ['bar']; + + bar = null; + } ); await this.visit('/'); await this.routerService.transitionTo('parent.child').followRedirects(); assert.equal( - this.routerService.get('currentURL'), + this.routerService.currentURL, '/child?bar=1', 'redirected to self with query param' ); - assert.equal(this.routerService.get('currentRouteName'), 'parent.child'); + assert.equal(this.routerService.currentRouteName, 'parent.child'); } async ['@test Redirecting to same route with query params from beforeModel works via direct visit']( @@ -500,21 +512,22 @@ moduleFor( this.add( 'controller:parent.child', - Controller.extend({ - queryParams: ['bar'], - bar: null, - }) + class extends Controller { + queryParams = ['bar']; + + bar = null; + } ); await this.visit('/child'); assert.equal( - this.routerService.get('currentURL'), + this.routerService.currentURL, '/child?bar=1', 'redirected to self with query param' ); - assert.equal(this.routerService.get('currentRouteName'), 'parent.child'); + assert.equal(this.routerService.currentRouteName, 'parent.child'); } async ['@test RouterService#transitionTo supports query params from a service during beforeModel']( @@ -568,19 +581,15 @@ moduleFor( await this.visit('/child'); - assert.equal( - this.routerService.get('currentRouteName'), - 'parent', - 'redirects to the target route' - ); + assert.equal(this.routerService.currentRouteName, 'parent', 'redirects to the target route'); - let currentURL = this.routerService.get('currentURL'); + let currentURL = this.routerService.currentURL; assert.equal(currentURL, '/parent?foo=bar', 'uses the query param in the final URL'); let controller = this.controllerFor('parent'); - assert.equal(controller.get('foo'), 'bar', 'sets the controller query param'); + assert.equal(controller.foo, 'bar', 'sets the controller query param'); } async ['@test RouterService#transitionTo with route name and unchanged application query params does not abort or re-run application model hook']( @@ -611,11 +620,13 @@ moduleFor( this.add( 'controller:application', - Controller.extend({ - queryParams: ['filter', 'sort'], - filter: '', - sort: '', - }) + class extends Controller { + queryParams = ['filter', 'sort']; + + filter = ''; + + sort = ''; + } ); await this.visit('/?filter=&sort='); @@ -629,7 +640,7 @@ moduleFor( await this.routerService.transitionTo('parent.child'); assert.equal( - this.routerService.get('currentRouteName'), + this.routerService.currentRouteName, 'parent.child', 'transitioned to child route' ); @@ -669,11 +680,13 @@ moduleFor( this.add( 'controller:application', - Controller.extend({ - queryParams: ['filter', 'sort'], - filter: '', - sort: '', - }) + class extends Controller { + queryParams = ['filter', 'sort']; + + filter = ''; + + sort = ''; + } ); await this.visit('/?filter=&sort='); @@ -687,7 +700,7 @@ moduleFor( await this.routerService.transitionTo('/child?filter=&sort='); assert.equal( - this.routerService.get('currentRouteName'), + this.routerService.currentRouteName, 'parent.child', 'transitioned to child route' ); diff --git a/packages/internal-test-helpers/lib/test-cases/test-resolver-application.ts b/packages/internal-test-helpers/lib/test-cases/test-resolver-application.ts index 199a996607c..13733e39be8 100644 --- a/packages/internal-test-helpers/lib/test-cases/test-resolver-application.ts +++ b/packages/internal-test-helpers/lib/test-cases/test-resolver-application.ts @@ -15,4 +15,17 @@ export default abstract class TestResolverApplicationTestCase extends AbstractAp add(specifier: string, factory: InternalFactory | object) { this.resolver!.add(specifier, factory); } + + /** + Replaces a registration with a subclass of it. + + The registry caches a class after the first lookup, so the old + registration must go before the resolver can supply the subclass. + */ + subclass(specifier: `${string}:${string}`, build: (Base: T) => T) { + let Base = this.application.resolveRegistration(specifier) as T; + + this.application.unregister(specifier); + this.add(specifier, build(Base)); + } }