diff --git a/.eslintrc.js b/.eslintrc.js index 391c36de..49cd4047 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -4,5 +4,6 @@ module.exports = { ], env: { browser: true - } + }, + root: true }; diff --git a/.travis.yml b/.travis.yml index 88d299ac..79a51a76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,7 @@ install: - yarn install --no-lockfile --non-interactive script: - - yarn eslint:ci + - yarn lint:js # Usually, it's ok to finish the test scenario without reverting # to the addon's original dependency state, skipping "cleanup". - node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO --skip-cleanup diff --git a/addon/index.js b/addon/index.js index 2b0acde5..be5505fd 100644 --- a/addon/index.js +++ b/addon/index.js @@ -1,62 +1,62 @@ -import Mixin from '@ember/object/mixin'; -import { get, computed } from '@ember/object'; -import { inject } from '@ember/service'; -import { getOwner } from '@ember/application'; +import Mixin from '@ember/object/mixin' +import { get, computed } from '@ember/object' +import { inject } from '@ember/service' +import { getOwner } from '@ember/application' export default Mixin.create({ scheduler: inject('scheduler'), service: inject('router-scroll'), - isFastBoot: computed(function() { - const fastboot = getOwner(this).lookup('service:fastboot'); - return fastboot ? fastboot.get('isFastBoot') : false; + isFastBoot: computed(function () { + const fastboot = getOwner(this).lookup('service:fastboot') + return fastboot ? fastboot.get('isFastBoot') : false }), - willTransition(...args) { - this._super(...args); + willTransition (...args) { + this._super(...args) - if (get(this, 'isFastBoot')) { return; } + if (get(this, 'isFastBoot')) { return } - get(this, 'service').update(); + get(this, 'service').update() }, - didTransition(transitions, ...args) { - this._super(transitions, ...args); + didTransition (transitions, ...args) { + this._super(transitions, ...args) - if (get(this, 'isFastBoot')) { return; } + if (get(this, 'isFastBoot')) { return } this.get('scheduler').scheduleWork('afterContentPaint', () => { - this.updateScrollPosition(transitions); - }); + this.updateScrollPosition(transitions) + }) }, - updateScrollPosition(transitions) { - const lastTransition = transitions[transitions.length - 1]; - const url = get(lastTransition, 'handler.router.currentURL'); - const hashElement = url ? document.getElementById(url.split('#').pop()) : null; + updateScrollPosition (transitions) { + const lastTransition = transitions[transitions.length - 1] + const url = get(lastTransition, 'handler.router.currentURL') + const hashElement = url ? document.getElementById(url.split('#').pop()) : null - let scrollPosition; + let scrollPosition - if(url && url.indexOf('#') > -1 && hashElement) { - scrollPosition = { x: hashElement.offsetLeft, y: hashElement.offsetTop }; + if (url && url.indexOf('#') > -1 && hashElement) { + scrollPosition = { x: hashElement.offsetLeft, y: hashElement.offsetTop } } else { - scrollPosition = get(this, 'service.position'); + scrollPosition = get(this, 'service.position') } - const scrollElement = get(this, 'service.scrollElement'); + const scrollElement = get(this, 'service.scrollElement') - const preserveScrollPosition = get(lastTransition, 'handler.controller.preserveScrollPosition'); + const preserveScrollPosition = get(lastTransition, 'handler.controller.preserveScrollPosition') if (!preserveScrollPosition) { - if ('window' === scrollElement) { - window.scrollTo(scrollPosition.x, scrollPosition.y); - } else if ('#' === scrollElement.charAt(0)) { - const element = document.getElementById(scrollElement.substring(1)); + if (scrollElement === 'window') { + window.scrollTo(scrollPosition.x, scrollPosition.y) + } else if (scrollElement.charAt(0) === '#') { + const element = document.getElementById(scrollElement.substring(1)) if (element) { - element.scrollLeft = scrollPosition.x; - element.scrollTop = scrollPosition.y; + element.scrollLeft = scrollPosition.x + element.scrollTop = scrollPosition.y } } } - } -}); + }, +}) diff --git a/config/ember-try.js b/config/ember-try.js index 6c7a816e..e47111b7 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -1,8 +1,8 @@ -'use strict'; +'use strict' -const getChannelURL = require('ember-source-channel-url'); +const getChannelURL = require('ember-source-channel-url') -module.exports = function() { +module.exports = function () { return Promise.all([ getChannelURL('release'), getChannelURL('beta'), @@ -15,57 +15,57 @@ module.exports = function() { name: 'ember-lts-2.12', npm: { devDependencies: { - 'ember-source': '~2.12.0' - } - } + 'ember-source': '~2.12.0', + }, + }, }, { name: 'ember-lts-2.16', npm: { devDependencies: { - 'ember-source': '~2.16.0' - } - } + 'ember-source': '~2.16.0', + }, + }, }, { name: 'ember-lts-2.18', npm: { devDependencies: { - 'ember-source': '~2.18.0' - } - } + 'ember-source': '~2.18.0', + }, + }, }, { name: 'ember-release', npm: { devDependencies: { - 'ember-source': urls[0] - } - } + 'ember-source': urls[0], + }, + }, }, { name: 'ember-beta', npm: { devDependencies: { - 'ember-source': urls[1] - } - } + 'ember-source': urls[1], + }, + }, }, { name: 'ember-canary', npm: { devDependencies: { - 'ember-source': urls[2] - } - } + 'ember-source': urls[2], + }, + }, }, { name: 'ember-default', npm: { - devDependencies: {} - } - } - ] - }; - }); -}; + devDependencies: {}, + }, + }, + ], + } + }) +} diff --git a/config/environment.js b/config/environment.js index 0dfaed47..b792ac26 100644 --- a/config/environment.js +++ b/config/environment.js @@ -1,5 +1,5 @@ -'use strict'; +'use strict' -module.exports = function(/* environment, appConfig */) { - return { }; -}; +module.exports = function (/* environment, appConfig */) { + return { } +} diff --git a/ember-cli-build.js b/ember-cli-build.js index dc5a39e1..7546d6c3 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -1,11 +1,11 @@ -'use strict'; +'use strict' -const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); +const EmberAddon = require('ember-cli/lib/broccoli/ember-addon') -module.exports = function(defaults) { - let app = new EmberAddon(defaults, { +module.exports = function (defaults) { + const app = new EmberAddon(defaults, { // Add options here - }); + }) /* This build file specifies the options for the dummy test app of this @@ -14,5 +14,5 @@ module.exports = function(defaults) { behave. You most likely want to be modifying `./index.js` or app's build file */ - return app.toTree(); -}; + return app.toTree() +} diff --git a/index.js b/index.js index a9c9d61d..51e75357 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ -'use strict'; +'use strict' module.exports = { - name: 'ember-router-scroll' -}; + name: 'ember-router-scroll', +} diff --git a/package.json b/package.json index 196e1885..26dd65cd 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "build": "ember build", "eslint": "eslint . --fix", - "lint:ci": "eslint .", + "lint:js": "eslint .", "start": "ember serve", "test": "ember try:each", "changelog": "lerna-changelog", diff --git a/testem.js b/testem.js index d1755a4e..50828ea3 100644 --- a/testem.js +++ b/testem.js @@ -1,12 +1,8 @@ module.exports = { test_page: 'tests/index.html?hidepassed', disable_watching: true, - launch_in_ci: [ - 'Chrome' - ], - launch_in_dev: [ - 'Chrome' - ], + launch_in_ci: ['Chrome'], + launch_in_dev: ['Chrome'], browser_args: { Chrome: { mode: 'ci', @@ -17,8 +13,8 @@ module.exports = { '--disable-gpu', '--headless', '--remote-debugging-port=0', - '--window-size=1440,900' - ].filter(Boolean) - } - } -}; + '--window-size=1440,900', + ].filter(Boolean), + }, + }, +} diff --git a/tests/acceptance/basic-functionality-test.js b/tests/acceptance/basic-functionality-test.js index bccf1d74..ba79f32e 100644 --- a/tests/acceptance/basic-functionality-test.js +++ b/tests/acceptance/basic-functionality-test.js @@ -1,15 +1,15 @@ -import { module, test } from 'qunit'; -import { setupApplicationTest } from 'ember-qunit'; -import { visit, click, currentURL } from '@ember/test-helpers'; +import { module, test } from 'qunit' +import { setupApplicationTest } from 'ember-qunit' +import { visit, click, currentURL } from '@ember/test-helpers' -module('Acceptance | basic functionality', function(hooks) { - setupApplicationTest(hooks); +module('Acceptance | basic functionality', function (hooks) { + setupApplicationTest(hooks) - test('The application should work when loading a page and clicking a link', async function(assert) { - await visit('/'); + test('The application should work when loading a page and clicking a link', async function (assert) { + await visit('/') - await click('a[href="/next-page"]'); + await click('a[href="/next-page"]') - assert.equal(currentURL(), '/next-page'); - }); -}); + assert.equal(currentURL(), '/next-page') + }) +}) diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js index b3b2bd67..772b3cb3 100644 --- a/tests/dummy/app/app.js +++ b/tests/dummy/app/app.js @@ -1,14 +1,14 @@ -import Application from '@ember/application'; -import Resolver from './resolver'; -import loadInitializers from 'ember-load-initializers'; -import config from './config/environment'; +import Application from '@ember/application' +import Resolver from './resolver' +import loadInitializers from 'ember-load-initializers' +import config from './config/environment' const App = Application.extend({ modulePrefix: config.modulePrefix, podModulePrefix: config.podModulePrefix, - Resolver -}); + Resolver, +}) -loadInitializers(App, config.modulePrefix); +loadInitializers(App, config.modulePrefix) -export default App; +export default App diff --git a/tests/dummy/app/resolver.js b/tests/dummy/app/resolver.js index 2fb563d6..02d98b04 100644 --- a/tests/dummy/app/resolver.js +++ b/tests/dummy/app/resolver.js @@ -1,3 +1,3 @@ -import Resolver from 'ember-resolver'; +import Resolver from 'ember-resolver' -export default Resolver; +export default Resolver diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 01edfcb0..1358bf2e 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -1,14 +1,14 @@ -import EmberRouter from '@ember/routing/router'; -import RouterScroll from 'ember-router-scroll'; -import config from './config/environment'; +import EmberRouter from '@ember/routing/router' +import RouterScroll from 'ember-router-scroll' +import config from './config/environment' const Router = EmberRouter.extend(RouterScroll, { location: config.locationType, - rootURL: config.rootURL -}); + rootURL: config.rootURL, +}) Router.map(function () { - this.route('next-page'); -}); + this.route('next-page') +}) -export default Router; +export default Router diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index f427ffae..52de92a3 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -1,7 +1,7 @@ -'use strict'; +'use strict' -module.exports = function(environment) { - let ENV = { +module.exports = function (environment) { + const ENV = { modulePrefix: 'dummy', environment, rootURL: '/', @@ -11,14 +11,14 @@ module.exports = function(environment) { FEATURES: { // Here you can enable experimental features on an ember canary build // e.g. 'with-controller': true - } + }, }, APP: { // Here you can pass flags/options to your application instance // when it is created - } - }; + }, + } if (environment === 'development') { // ENV.APP.LOG_RESOLVER = true; @@ -30,20 +30,19 @@ module.exports = function(environment) { if (environment === 'test') { // Testem prefers this... - ENV.locationType = 'none'; + ENV.locationType = 'none' // keep test console output quieter - ENV.APP.LOG_ACTIVE_GENERATION = false; - ENV.APP.LOG_VIEW_LOOKUPS = false; + ENV.APP.LOG_ACTIVE_GENERATION = false + ENV.APP.LOG_VIEW_LOOKUPS = false - ENV.APP.rootElement = '#ember-testing'; - ENV.APP.autoboot = false; + ENV.APP.rootElement = '#ember-testing' + ENV.APP.autoboot = false } if (environment === 'production') { - ENV.rootURL = '/ember-router-scroll/'; - + ENV.rootURL = '/ember-router-scroll/' } - return ENV; -}; + return ENV +} diff --git a/tests/dummy/config/targets.js b/tests/dummy/config/targets.js index 8ffae363..3f5067cb 100644 --- a/tests/dummy/config/targets.js +++ b/tests/dummy/config/targets.js @@ -1,18 +1,18 @@ -'use strict'; +'use strict' const browsers = [ 'last 1 Chrome versions', 'last 1 Firefox versions', - 'last 1 Safari versions' -]; + 'last 1 Safari versions', +] -const isCI = !!process.env.CI; -const isProduction = process.env.EMBER_ENV === 'production'; +const isCI = !!process.env.CI +const isProduction = process.env.EMBER_ENV === 'production' if (isCI || isProduction) { - browsers.push('ie 11'); + browsers.push('ie 11') } module.exports = { - browsers -}; + browsers, +} diff --git a/tests/helpers/resolver.js b/tests/helpers/resolver.js index b208d38d..d8532144 100644 --- a/tests/helpers/resolver.js +++ b/tests/helpers/resolver.js @@ -1,11 +1,11 @@ -import Resolver from '../../resolver'; -import config from '../../config/environment'; +import Resolver from '../../resolver' +import config from '../../config/environment' -const resolver = Resolver.create(); +const resolver = Resolver.create() resolver.namespace = { modulePrefix: config.modulePrefix, - podModulePrefix: config.podModulePrefix -}; + podModulePrefix: config.podModulePrefix, +} -export default resolver; +export default resolver diff --git a/tests/helpers/start-app.js b/tests/helpers/start-app.js index 37db37f5..33a3035f 100644 --- a/tests/helpers/start-app.js +++ b/tests/helpers/start-app.js @@ -1,19 +1,19 @@ -import { run } from '@ember/runloop'; -import { merge } from '@ember/polyfills'; -import Application from '../../app'; -import config from '../../config/environment'; +import { run } from '@ember/runloop' +import { merge } from '@ember/polyfills' +import Application from '../../app' +import config from '../../config/environment' -export default function startApp(attrs) { - let application; +export default function startApp (attrs) { + let application - let attributes = merge({}, config.APP); - attributes = merge(attributes, attrs); // use defaults, but you can override; + let attributes = merge({}, config.APP) + attributes = merge(attributes, attrs) // use defaults, but you can override; run(() => { - application = Application.create(attributes); - application.setupForTesting(); - application.injectTestHelpers(); - }); + application = Application.create(attributes) + application.setupForTesting() + application.injectTestHelpers() + }) - return application; + return application } diff --git a/tests/test-helper.js b/tests/test-helper.js index 0382a848..0828b2d8 100644 --- a/tests/test-helper.js +++ b/tests/test-helper.js @@ -1,8 +1,8 @@ -import Application from '../app'; -import config from '../config/environment'; -import { setApplication } from '@ember/test-helpers'; -import { start } from 'ember-qunit'; +import Application from '../app' +import config from '../config/environment' +import { setApplication } from '@ember/test-helpers' +import { start } from 'ember-qunit' -setApplication(Application.create(config.APP)); +setApplication(Application.create(config.APP)) -start(); +start() diff --git a/tests/unit/mixins/router-scroll-test.js b/tests/unit/mixins/router-scroll-test.js index af930406..33696ed6 100644 --- a/tests/unit/mixins/router-scroll-test.js +++ b/tests/unit/mixins/router-scroll-test.js @@ -1,28 +1,28 @@ -import { run, next } from '@ember/runloop'; -import EmberObject from '@ember/object'; -import RouterScroll from 'ember-router-scroll'; -import { module, test } from 'qunit'; +import { run, next } from '@ember/runloop' +import EmberObject from '@ember/object' +import RouterScroll from 'ember-router-scroll' +import { module, test } from 'qunit' -let scrollTo; +let scrollTo -module('mixin:router-scroll', function(hooks) { - hooks.beforeEach(function() { - scrollTo = window.scrollTo; - }); +module('mixin:router-scroll', function (hooks) { + hooks.beforeEach(function () { + scrollTo = window.scrollTo + }) - hooks.afterEach(function() { - window.scrollTo = scrollTo; - }); + hooks.afterEach(function () { + window.scrollTo = scrollTo + }) - function getSchedulerMock() { + function getSchedulerMock () { return { scheduleWork: (eventName, callback) => { - callback(); + callback() }, - }; + } } - function getTransitionsMock(URL, isPreserveScroll) { + function getTransitionsMock (URL, isPreserveScroll) { return [ { handler: { @@ -34,58 +34,58 @@ module('mixin:router-scroll', function(hooks) { }, }, }, - ]; + ] } test('when the application is FastBooted', (assert) => { - assert.expect(1); + assert.expect(1) - const done = assert.async(); - const RouterScrollObject = EmberObject.extend(RouterScroll); + const done = assert.async() + const RouterScrollObject = EmberObject.extend(RouterScroll) const subject = RouterScrollObject.create({ isFastBoot: true, scheduler: getSchedulerMock(), - updateScrollPosition() { - assert.notOk(true, 'it should not call updateScrollPosition.'); - done(); + updateScrollPosition () { + assert.notOk(true, 'it should not call updateScrollPosition.') + done() }, - }); + }) run(() => { - subject.didTransition(); + subject.didTransition() next(() => { - assert.ok(true, 'it should not call updateScrollPosition.'); - done(); - }); - }); - }); + assert.ok(true, 'it should not call updateScrollPosition.') + done() + }) + }) + }) test('when the application is not FastBooted', (assert) => { - assert.expect(1); + assert.expect(1) - const done = assert.async(); - const RouterScrollObject = EmberObject.extend(RouterScroll); + const done = assert.async() + const RouterScrollObject = EmberObject.extend(RouterScroll) const subject = RouterScrollObject.create({ isFastBoot: false, scheduler: getSchedulerMock(), - updateScrollPosition() { - assert.ok(true, 'it should call updateScrollPosition.'); - done(); + updateScrollPosition () { + assert.ok(true, 'it should call updateScrollPosition.') + done() }, - }); + }) run(() => { - subject.didTransition(); - }); - }); + subject.didTransition() + }) + }) test('Update Scroll Position: Position is preserved', (assert) => { - assert.expect(0); - const done = assert.async(); + assert.expect(0) + const done = assert.async() - window.scrollTo = () => assert.ok(false, 'Scroll To should not be called'); + window.scrollTo = () => assert.ok(false, 'Scroll To should not be called') - const RouterScrollObject = EmberObject.extend(RouterScroll); + const RouterScrollObject = EmberObject.extend(RouterScroll) const subject = RouterScrollObject.create({ isFastBoot: false, scheduler: getSchedulerMock(), @@ -93,25 +93,25 @@ module('mixin:router-scroll', function(hooks) { position: null, scrollElement: 'window', }, - }); + }) run(() => { - subject.didTransition(getTransitionsMock('Hello/World', true)); - done(); - }); - }); + subject.didTransition(getTransitionsMock('Hello/World', true)) + done() + }) + }) test('Update Scroll Position: URL is an anchor', (assert) => { - assert.expect(1); - const done = assert.async(); + assert.expect(1) + const done = assert.async() - const elem = document.createElement('div'); - elem.id = 'World'; - document.body.insertBefore(elem, null); + const elem = document.createElement('div') + elem.id = 'World' + document.body.insertBefore(elem, null) window.scrollTo = (x, y) => - assert.ok(x === elem.offsetLeft && y === elem.offsetTop, 'Scroll to called with correct offsets'); + assert.ok(x === elem.offsetLeft && y === elem.offsetTop, 'Scroll to called with correct offsets') - const RouterScrollObject = EmberObject.extend(RouterScroll); + const RouterScrollObject = EmberObject.extend(RouterScroll) const subject = RouterScrollObject.create({ isFastBoot: false, scheduler: getSchedulerMock(), @@ -119,22 +119,22 @@ module('mixin:router-scroll', function(hooks) { position: null, scrollElement: 'window', }, - }); + }) run(() => { - subject.didTransition(getTransitionsMock('Hello/#World')); - done(); - }); - }); + subject.didTransition(getTransitionsMock('Hello/#World')) + done() + }) + }) test('Update Scroll Position: URL has nothing after an anchor', (assert) => { - assert.expect(1); - const done = assert.async(); + assert.expect(1) + const done = assert.async() window.scrollTo = (x, y) => - assert.ok(x === 1 && y === 2, 'Scroll to called with correct offsets'); + assert.ok(x === 1 && y === 2, 'Scroll to called with correct offsets') - const RouterScrollObject = EmberObject.extend(RouterScroll); + const RouterScrollObject = EmberObject.extend(RouterScroll) const subject = RouterScrollObject.create({ isFastBoot: false, scheduler: getSchedulerMock(), @@ -142,25 +142,25 @@ module('mixin:router-scroll', function(hooks) { position: { x: 1, y: 2 }, scrollElement: 'window', }, - }); + }) run(() => { - subject.didTransition(getTransitionsMock('Hello/#')); - done(); - }); - }); + subject.didTransition(getTransitionsMock('Hello/#')) + done() + }) + }) test('Update Scroll Position: URL has nonexistent element after anchor', (assert) => { - assert.expect(1); - const done = assert.async(); + assert.expect(1) + const done = assert.async() - const elem = document.createElement('div'); - elem.id = 'World'; - document.body.insertBefore(elem, null); + const elem = document.createElement('div') + elem.id = 'World' + document.body.insertBefore(elem, null) window.scrollTo = (x, y) => - assert.ok(x === 1 && y === 2, 'Scroll to called with correct offsets'); + assert.ok(x === 1 && y === 2, 'Scroll to called with correct offsets') - const RouterScrollObject = EmberObject.extend(RouterScroll); + const RouterScrollObject = EmberObject.extend(RouterScroll) const subject = RouterScrollObject.create({ isFastBoot: false, scheduler: getSchedulerMock(), @@ -168,22 +168,22 @@ module('mixin:router-scroll', function(hooks) { position: { x: 1, y: 2 }, scrollElement: 'window', }, - }); + }) run(() => { - subject.didTransition(getTransitionsMock('Hello/#Bar')); - done(); - }); - }); + subject.didTransition(getTransitionsMock('Hello/#Bar')) + done() + }) + }) test('Update Scroll Position: Scroll Position is set by service', (assert) => { - assert.expect(1); - const done = assert.async(); + assert.expect(1) + const done = assert.async() window.scrollTo = (x, y) => - assert.ok(x === 1 && y === 2, 'Scroll to was called with correct offsets'); + assert.ok(x === 1 && y === 2, 'Scroll to was called with correct offsets') - const RouterScrollObject = EmberObject.extend(RouterScroll); + const RouterScrollObject = EmberObject.extend(RouterScroll) const subject = RouterScrollObject.create({ isFastBoot: false, scheduler: getSchedulerMock(), @@ -191,13 +191,13 @@ module('mixin:router-scroll', function(hooks) { position: { x: 1, y: 2 }, scrollElement: 'window', }, - }); + }) run(() => { - subject.didTransition(getTransitionsMock('Hello/World')); + subject.didTransition(getTransitionsMock('Hello/World')) next(() => { - done(); - }); - }); - }); -}); \ No newline at end of file + done() + }) + }) + }) +}) diff --git a/tests/unit/services/router-scroll-test.js b/tests/unit/services/router-scroll-test.js index 00264779..79568347 100644 --- a/tests/unit/services/router-scroll-test.js +++ b/tests/unit/services/router-scroll-test.js @@ -1,105 +1,105 @@ -import { set, get } from '@ember/object'; -import { module, test } from 'qunit'; -import { setupTest } from 'ember-qunit'; +import { set, get } from '@ember/object' +import { module, test } from 'qunit' +import { setupTest } from 'ember-qunit' module('service:router-scroll', (hooks) => { - setupTest(hooks); + setupTest(hooks) test('it inits `scrollMap` and `key`', function init (assert) { - const service = this.owner.lookup('service:router-scroll'); - assert.deepEqual(get(service, 'scrollMap'), {}); - assert.deepEqual(get(service, 'key'), null); - }); + const service = this.owner.lookup('service:router-scroll') + assert.deepEqual(get(service, 'scrollMap'), {}) + assert.deepEqual(get(service, 'key'), null) + }) test('it inits `scrollMap` and `key` with scrollElement other than window', function init (assert) { - const service = this.owner.factoryFor('service:router-scroll').create({ scrollElement: '#other-elem' }); - assert.deepEqual(get(service, 'scrollMap'), {}); - assert.deepEqual(get(service, 'key'), null); - }); + const service = this.owner.factoryFor('service:router-scroll').create({ scrollElement: '#other-elem' }) + assert.deepEqual(get(service, 'scrollMap'), {}) + assert.deepEqual(get(service, 'key'), null) + }) test('updating will not set `scrollMap` to the current scroll position if `key` is not yet set', - function scrollMapCurrentPos (assert) { - const service = this.owner.lookup('service:router-scroll'); + function scrollMapCurrentPos (assert) { + const service = this.owner.lookup('service:router-scroll') - service.update(); - assert.deepEqual(get(service, 'scrollMap'), { }); - }); + service.update() + assert.deepEqual(get(service, 'scrollMap'), { }) + }) test('updating will set `scrollMap` to the current scroll position', function scrollMap (assert) { - const service = this.owner.lookup('service:router-scroll'); + const service = this.owner.lookup('service:router-scroll') - const expected = { x: window.scrollX, y: window.scrollY }; - set(service, 'key', '123'); - service.update(); - assert.deepEqual(get(service, 'scrollMap'), { 123: expected }); - }); + const expected = { x: window.scrollX, y: window.scrollY } + set(service, 'key', '123') + service.update() + assert.deepEqual(get(service, 'scrollMap'), { 123: expected }) + }) test('updating will not set `scrollMap` if scrollElement is defined', - function scrollMapCurrentPos (assert) { - const service = this.owner.factoryFor('service:router-scroll').create({ scrollElement: '#other-elem' }); + function scrollMapCurrentPos (assert) { + const service = this.owner.factoryFor('service:router-scroll').create({ scrollElement: '#other-elem' }) - service.update(); - const expected = { x: 0, y: 0 }; - assert.deepEqual(get(service, 'position'), expected); - assert.deepEqual(get(service, 'scrollMap'), { }); - }); + service.update() + const expected = { x: 0, y: 0 } + assert.deepEqual(get(service, 'position'), expected) + assert.deepEqual(get(service, 'scrollMap'), { }) + }) test('updating will not set `scrollMap` if scrollElement is defined and in fastboot', - function scrollMapCurrentPos (assert) { - const otherElem = document.createElement('div'); - otherElem.setAttribute('id', 'other-elem'); - const testing = document.querySelector('#ember-testing'); - testing.appendChild(otherElem); - const service = this.owner.factoryFor('service:router-scroll').create({ scrollElement: '#other-elem', isFastBoot: true }); - window.history.replaceState({ uuid: '123' }, null); - - let expected = { x: 0, y: 0 }; - assert.deepEqual(get(service, 'position'), expected, 'position is defaulted'); - service.update(); - assert.deepEqual(get(service, 'scrollMap'), { }, 'does not set scrollMap b/c in fastboot'); - }); + function scrollMapCurrentPos (assert) { + const otherElem = document.createElement('div') + otherElem.setAttribute('id', 'other-elem') + const testing = document.querySelector('#ember-testing') + testing.appendChild(otherElem) + const service = this.owner.factoryFor('service:router-scroll').create({ scrollElement: '#other-elem', isFastBoot: true }) + window.history.replaceState({ uuid: '123' }, null) + + const expected = { x: 0, y: 0 } + assert.deepEqual(get(service, 'position'), expected, 'position is defaulted') + service.update() + assert.deepEqual(get(service, 'scrollMap'), { }, 'does not set scrollMap b/c in fastboot') + }) test('updating will set `scrollMap` if scrollElement is defined', - function scrollMapCurrentPos (assert) { - const otherElem = document.createElement('div'); - otherElem.setAttribute('id', 'other-elem'); - const testing = document.querySelector('#ember-testing'); - testing.appendChild(otherElem); - const service = this.owner.factoryFor('service:router-scroll').create({ scrollElement: '#other-elem' }); - window.history.replaceState({ uuid: '123' }, null); - - let expected = { x: 0, y: 0 }; - assert.deepEqual(get(service, 'position'), expected, 'position is defaulted'); - service.update(); - assert.deepEqual(get(service, 'scrollMap'), { '123': expected }, 'sets scrollMap'); - }); + function scrollMapCurrentPos (assert) { + const otherElem = document.createElement('div') + otherElem.setAttribute('id', 'other-elem') + const testing = document.querySelector('#ember-testing') + testing.appendChild(otherElem) + const service = this.owner.factoryFor('service:router-scroll').create({ scrollElement: '#other-elem' }) + window.history.replaceState({ uuid: '123' }, null) + + const expected = { x: 0, y: 0 } + assert.deepEqual(get(service, 'position'), expected, 'position is defaulted') + service.update() + assert.deepEqual(get(service, 'scrollMap'), { '123': expected }, 'sets scrollMap') + }) test('computing the position for an existing state uuid return the coords', - function existingUUID (assert) { - const service = this.owner.lookup('service:router-scroll'); - window.history.replaceState({ uuid: '123' }, null); + function existingUUID (assert) { + const service = this.owner.lookup('service:router-scroll') + window.history.replaceState({ uuid: '123' }, null) - const expected = { x: 1, y: 1 }; - set(service, 'scrollMap.123', expected); - assert.deepEqual(get(service, 'position'), expected); - }); + const expected = { x: 1, y: 1 } + set(service, 'scrollMap.123', expected) + assert.deepEqual(get(service, 'position'), expected) + }) test('computing the position for a state without a cached scroll position returns default', - function cachedScroll (assert) { - const service = this.owner.lookup('service:router-scroll'); - const state = window.history.state; - window.history.replaceState({ uuid: '123' }, null); + function cachedScroll (assert) { + const service = this.owner.lookup('service:router-scroll') + const state = window.history.state + window.history.replaceState({ uuid: '123' }, null) - const expected = { x: 0, y: 0 }; - assert.deepEqual(get(service, 'position'), expected); - window.history.replaceState(state, null); - }); + const expected = { x: 0, y: 0 } + assert.deepEqual(get(service, 'position'), expected) + window.history.replaceState(state, null) + }) test('computing the position for a non-existant state returns default', - function nonExistantState (assert) { - const service = this.owner.lookup('service:router-scroll'); + function nonExistantState (assert) { + const service = this.owner.lookup('service:router-scroll') - const expected = { x: 0, y: 0 }; - assert.deepEqual(get(service, 'position'), expected); - }); -}); \ No newline at end of file + const expected = { x: 0, y: 0 } + assert.deepEqual(get(service, 'position'), expected) + }) +})