Skip to content

Commit

Permalink
Fixed tests, upgraded deps
Browse files Browse the repository at this point in the history
  • Loading branch information
briangonzalez committed Jan 24, 2017
1 parent b777579 commit b5aa167
Show file tree
Hide file tree
Showing 6 changed files with 6,093 additions and 48 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ install:
script:
# Usually, it's ok to finish the test scenario without reverting
# to the addon's original dependency state, skipping "cleanup".
- npm run eslint
- ember try $EMBER_TRY_SCENARIO test --skip-cleanup
21 changes: 9 additions & 12 deletions addon/locations/router-scroll.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Ember from 'ember';

function _uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r, v;
r = Math.random() * 16 | 0;
v = c === 'x' ? r : r & 3 | 8;
const uuid = () => {
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : r & 3 | 8;
return v.toString(16);
});
}
};

const {
get,
Expand All @@ -16,15 +15,13 @@ const {

export default HistoryLocation.extend({
pushState(path) {
const uuid = _uuid();
const state = { path, uuid };
const state = { path, uuid: uuid() };
get(this, 'history').pushState(state, null, path);
this._previousURL = this.getURL(); // eslint-disable-line no-underscore-dangle
this.previousURL = this.getURL();
},
replaceState(path) {
const uuid = _uuid();
const state = { path, uuid };
const state = { path, uuid: uuid() };
get(this, 'history').replaceState(state, null, path);
this._previousURL = this.getURL(); // eslint-disable-line no-underscore-dangle
this.previousURL = this.getURL();
},
});
6 changes: 3 additions & 3 deletions addon/services/router-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export default Service.extend({
},

position: computed(function position() {
let scrollMap = get(this, 'scrollMap');
let stateUuid = get(window, 'history.state.uuid');
const scrollMap = get(this, 'scrollMap');
const stateUuid = get(window, 'history.state.uuid');

set(this, 'key', stateUuid);
let key = getWithDefault(this, 'key', '-1');
const key = getWithDefault(this, 'key', '-1');

return getWithDefault(scrollMap, key, { x: 0, y: 0 });
}).volatile(),
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@
},
{
"name": "Brian Gonzalez",
"url": "https://twitter.com/brianmgonzalez"
"url": "https://github.com/briangonzalez"
}
],
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.4.2",
"ember-ajax": "^2.0.1",
"ember-cli": "2.6.2",
"ember-cli": "2.11.0",
"ember-cli-app-version": "^1.0.0",
"ember-cli-dependency-checker": "^1.2.0",
"ember-cli-htmlbars": "^1.0.3",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-inject-live-reload": "^1.4.0",
"ember-cli-jshint": "^1.0.0",
"ember-cli-qunit": "^1.4.0",
"ember-cli-release": "^0.2.9",
"ember-cli-release": "^1.0.0-beta.2",
"ember-cli-sri": "^2.1.0",
"ember-cli-uglify": "^1.2.0",
"ember-data": "^2.6.0",
Expand All @@ -74,8 +74,8 @@
"ember-getowner-polyfill": "1.0.1",
"ember-load-initializers": "^0.5.1",
"ember-resolver": "^2.0.3",
"ember-welcome-page": "^1.0.1",
"eslint": "^2.4.0",
"ember-welcome-page": "^2.0.3",
"eslint": "^3.14.0",
"eslint-config-airbnb": "^6.1.0",
"eslint-plugin-dollarshaveclub": "^1.0.0",
"loader.js": "^4.0.1",
Expand All @@ -92,6 +92,6 @@
},
"ember-addon": {
"configPath": "tests/dummy/config",
"demoURL": "https://dollarshaveclub.github.io/router-scroll-demo/"
"demoURL": "https://dollarshaveclub.github.io/router-scroll-demo/"
}
}
53 changes: 26 additions & 27 deletions tests/unit/services/router-scroll-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,60 @@ import { moduleFor, test } from 'ember-qunit';

const {
get,
set
set,
} = Ember;

moduleFor('service:router-scroll', {
// Specify the other units that are required for this test.
// needs: ['service:foo']
});
moduleFor('service:router-scroll');

// Replace this with your real tests.
test('it inits `scrollMap` and `key`', function(assert) {
let service = this.subject();
test('it inits `scrollMap` and `key`', function init(assert) {
const service = this.subject();
assert.deepEqual(get(service, 'scrollMap'), {});
assert.deepEqual(get(service, 'key'), null);
});

test('updating will set `scrollMap` to the current scroll position', function(assert) {
let service = this.subject();
test('updating will set `scrollMap` to the current scroll position', function scrollMap(assert) {
const service = this.subject();

let expected = { x: window.scrollX, y: window.scrollY };
const expected = { x: window.scrollX, y: window.scrollY };
set(service, 'key', '123');
service.update();
assert.deepEqual(get(service, 'scrollMap'), { '123': expected });
assert.deepEqual(get(service, 'scrollMap'), { 123: expected });
});

test('updating will not set `scrollMap` to the current scroll position if `key` is not yet set', function(assert) {
let service = this.subject();
test('updating will not set `scrollMap` to the current scroll position if `key` is not yet set',
function scrollMapCurrentPos(assert) {
const service = this.subject();

service.update();
assert.deepEqual(get(service, 'scrollMap'), { });
});

test('computing the position for an existing state uuid return the coords', function(assert) {
let service = this.subject();
let state = window.history.state;
window.history.replaceState({uuid: '123'}, null);
test('computing the position for an existing state uuid return the coords',
function existingUUID(assert) {
const service = this.subject();
window.history.replaceState({ uuid: '123' }, null);

let expected = { x: 1, y: 1 };
const expected = { x: 1, y: 1 };
set(service, 'scrollMap.123', expected);
assert.deepEqual(get(service, 'position'), expected);
window.history.replaceState(state, null);
});

test('computing the position for a state without a cached scroll position returns default', function(assert) {
let service = this.subject();
let state = window.history.state;
window.history.replaceState({uuid: '123'}, null);
test('computing the position for a state without a cached scroll position returns default',
function cachedScroll(assert) {
const service = this.subject();
const state = window.history.state;
window.history.replaceState({ uuid: '123' }, null);

let expected = { x: 0, y: 0 };
const expected = { x: 0, y: 0 };
assert.deepEqual(get(service, 'position'), expected);
window.history.replaceState(state, null);
});

test('computing the position for a non-existing state returns default', function(assert) {
let service = this.subject();
test('computing the position for a non-existant state returns default',
function nonExistantState(assert) {
const service = this.subject();

let expected = { x: 0, y: 0 };
const expected = { x: 0, y: 0 };
assert.deepEqual(get(service, 'position'), expected);
});
Loading

0 comments on commit b5aa167

Please sign in to comment.