Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
use windowProxy to avoid mangling URL during team acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinansfield committed Nov 10, 2017
1 parent d0c33c9 commit 82d1473
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/controllers/team/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Controller from '@ember/controller';
import Ember from 'ember';
import boundOneWay from 'ghost-admin/utils/bound-one-way';
import isNumber from 'ghost-admin/utils/isNumber';
import windowProxy from 'ghost-admin/utils/window-proxy';
import {alias, and, not, or, readOnly} from '@ember/object/computed';
import {computed} from '@ember/object';
import {htmlSafe} from '@ember/string';
Expand Down Expand Up @@ -182,7 +183,7 @@ export default Controller.extend({
newPath[newPath.length - 1] = model.get('slug');
newPath = newPath.join('/');

window.history.replaceState({path: newPath}, '', newPath);
windowProxy.replaceState({path: newPath}, '', newPath);
}

this.set('dirtyAttributes', false);
Expand Down
4 changes: 4 additions & 0 deletions app/utils/window-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ export default {

replaceLocation(url) {
window.location.replace(url);
},

replaceState(params, title, url) {
window.history.replaceState(params, title, url);
}
};
16 changes: 15 additions & 1 deletion tests/acceptance/team-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ctrlOrCmd from 'ghost-admin/utils/ctrl-or-cmd';
import destroyApp from '../helpers/destroy-app';
import moment from 'moment';
import startApp from '../helpers/start-app';
import windowProxy from 'ghost-admin/utils/window-proxy';
import {Response} from 'ember-cli-mirage';
import {afterEach, beforeEach, describe, it} from 'mocha';
import {authenticateSession, invalidateSession} from '../helpers/ember-simple-auth';
Expand Down Expand Up @@ -449,7 +450,7 @@ describe('Acceptance: Team', function () {
});

describe('existing user', function () {
let user;
let user, newLocation, originalReplaceState;

beforeEach(function () {
user = server.create('user', {
Expand All @@ -458,6 +459,16 @@ describe('Acceptance: Team', function () {
facebook: 'test',
twitter: '@test'
});

originalReplaceState = windowProxy.replaceState;
windowProxy.replaceState = function (params, title, url) {
newLocation = url;
};
newLocation = undefined;
});

afterEach(function () {
windowProxy.replaceState = originalReplaceState;
});

it('input fields reset and validate correctly', async function () {
Expand Down Expand Up @@ -511,6 +522,9 @@ describe('Acceptance: Team', function () {

expect(params.users[0].name).to.equal('Test User');

// check that the history state has been updated
expect(newLocation).to.equal('Test User');

await fillIn('[data-test-slug-input]', 'white space');
await triggerEvent('[data-test-slug-input]', 'blur');

Expand Down

0 comments on commit 82d1473

Please sign in to comment.