diff --git a/app/controllers/team/user.js b/app/controllers/team/user.js index 1f7e81e8c3..59039d5b9e 100644 --- a/app/controllers/team/user.js +++ b/app/controllers/team/user.js @@ -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'; @@ -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); diff --git a/app/utils/window-proxy.js b/app/utils/window-proxy.js index 48b98a6c30..1ac66bd1b1 100644 --- a/app/utils/window-proxy.js +++ b/app/utils/window-proxy.js @@ -5,5 +5,9 @@ export default { replaceLocation(url) { window.location.replace(url); + }, + + replaceState(params, title, url) { + window.history.replaceState(params, title, url); } }; diff --git a/tests/acceptance/team-test.js b/tests/acceptance/team-test.js index b44e0b1d35..5212f3dc91 100644 --- a/tests/acceptance/team-test.js +++ b/tests/acceptance/team-test.js @@ -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'; @@ -449,7 +450,7 @@ describe('Acceptance: Team', function () { }); describe('existing user', function () { - let user; + let user, newLocation, originalReplaceState; beforeEach(function () { user = server.create('user', { @@ -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 () { @@ -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');