mirror of
https://github.com/TryGhost/Ghost-Admin.git
synced 2023-12-14 02:33:04 +01:00
Fix unsaved nav settings persisting across transitions
closes #5852 - resets navigation settings controller's model when transitioning away - fixes `locationType` config setting so acceptance tests don't mess with the URL - configure the ephemeral session store for ember-simple-auth during tests - adds dummy env-config meta fields so acceptance tests don't fail - adds `ember-cli-simple-auth-testing` dependency for auth testing helpers - adds Pretender dependency to mock API requests for acceptance tests
This commit is contained in:
parent
1384bc44b5
commit
04d4c2bbad
9 changed files with 247 additions and 8 deletions
|
@ -1,9 +1,10 @@
|
|||
import Ember from 'ember';
|
||||
import ghostPaths from 'ghost/utils/ghost-paths';
|
||||
import documentTitle from 'ghost/utils/document-title';
|
||||
import config from './config/environment';
|
||||
|
||||
var Router = Ember.Router.extend({
|
||||
location: 'trailing-history', // use HTML5 History API instead of hash-tag based URLs
|
||||
location: config.locationType, // use HTML5 History API instead of hash-tag based URLs
|
||||
rootURL: ghostPaths().adminRoot, // admin interface lives under sub-directory /ghost
|
||||
|
||||
notifications: Ember.inject.service(),
|
||||
|
|
|
@ -26,6 +26,13 @@ export default AuthenticatedRoute.extend(styleBody, CurrentUserSettings, {
|
|||
$('.page-actions .btn-blue').focus();
|
||||
|
||||
this.get('controller').send('save');
|
||||
},
|
||||
|
||||
willTransition: function () {
|
||||
// reset the model so that our CPs re-calc and unsaved changes aren't
|
||||
// persisted across transitions
|
||||
this.set('controller.model', null);
|
||||
return this._super(...arguments);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
"moment": "2.10.3",
|
||||
"normalize.css": "3.0.3",
|
||||
"password-generator": "git://github.com/bermi/password-generator#49accd7",
|
||||
"pretender": "~0.9.0",
|
||||
"rangyinputs": "1.2.0",
|
||||
"selectize": "~0.12.1",
|
||||
"showdown-ghost": "0.3.6",
|
||||
|
|
|
@ -6,7 +6,7 @@ module.exports = function (environment) {
|
|||
modulePrefix: 'ghost',
|
||||
environment: environment,
|
||||
baseURL: '/',
|
||||
locationType: 'auto',
|
||||
locationType: 'trailing-history',
|
||||
EmberENV: {
|
||||
FEATURES: {
|
||||
// Here you can enable experimental features on an ember canary build
|
||||
|
@ -60,6 +60,10 @@ module.exports = function (environment) {
|
|||
ENV.APP.LOG_VIEW_LOOKUPS = false;
|
||||
|
||||
ENV.APP.rootElement = '#ember-testing';
|
||||
|
||||
ENV['simple-auth'] = {
|
||||
store: 'simple-auth-session-store:ephemeral'
|
||||
};
|
||||
}
|
||||
|
||||
return ENV;
|
||||
|
|
|
@ -31,10 +31,12 @@
|
|||
"ember-cli-ic-ajax": "0.2.1",
|
||||
"ember-cli-inject-live-reload": "^1.3.1",
|
||||
"ember-cli-mocha": "0.9.3",
|
||||
"ember-cli-pretender": "0.5.0",
|
||||
"ember-cli-release": "0.2.3",
|
||||
"ember-cli-selectize": "0.4.0",
|
||||
"ember-cli-simple-auth": "0.8.0",
|
||||
"ember-cli-simple-auth-oauth2": "0.8.0",
|
||||
"ember-cli-simple-auth-testing": "0.8.0",
|
||||
"ember-cli-sri": "^1.0.3",
|
||||
"ember-cli-uglify": "^1.2.0",
|
||||
"ember-data": "1.13.13",
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
{
|
||||
"predef": [
|
||||
"authenticateSession",
|
||||
"invalidateSession",
|
||||
"currentSession",
|
||||
"document",
|
||||
"window",
|
||||
"location",
|
||||
|
|
209
tests/acceptance/settings/navigation-test.js
Normal file
209
tests/acceptance/settings/navigation-test.js
Normal file
|
@ -0,0 +1,209 @@
|
|||
/* jshint expr:true */
|
||||
import {
|
||||
describe,
|
||||
it,
|
||||
beforeEach,
|
||||
afterEach
|
||||
} from 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import Ember from 'ember';
|
||||
import startApp from '../../helpers/start-app';
|
||||
import Pretender from 'pretender';
|
||||
import initializeTestHelpers from 'simple-auth-testing/test-helpers';
|
||||
|
||||
initializeTestHelpers();
|
||||
|
||||
const { run } = Ember,
|
||||
// TODO: Pull this into a fixture or similar when required elsewhere
|
||||
requiredSettings = [{
|
||||
created_at: '2015-09-11T09:44:30.805Z',
|
||||
created_by: 1,
|
||||
id: 5,
|
||||
key: 'title',
|
||||
type: 'blog',
|
||||
updated_at: '2015-10-04T16:26:05.195Z',
|
||||
updated_by: 1,
|
||||
uuid: '39e16daf-43fa-4bf0-87d4-44948ba8bf4c',
|
||||
value: 'The Daily Awesome'
|
||||
}, {
|
||||
created_at: '2015-09-11T09:44:30.806Z',
|
||||
created_by: 1,
|
||||
id: 6,
|
||||
key: 'description',
|
||||
type: 'blog',
|
||||
updated_at: '2015-10-04T16:26:05.198Z',
|
||||
updated_by: 1,
|
||||
uuid: 'e6c8b636-6925-4c4a-a5d9-1dc0870fb8ea',
|
||||
value: 'Thoughts, stories and ideas.'
|
||||
}, {
|
||||
created_at: '2015-09-11T09:44:30.809Z',
|
||||
created_by: 1,
|
||||
id: 10,
|
||||
key: 'postsPerPage',
|
||||
type: 'blog',
|
||||
updated_at: '2015-10-04T16:26:05.211Z',
|
||||
updated_by: 1,
|
||||
uuid: '775e6ca1-bcc3-4347-a53d-15d5d76c04a4',
|
||||
value: '5'
|
||||
}, {
|
||||
created_at: '2015-09-11T09:44:30.809Z',
|
||||
created_by: 1,
|
||||
id: 13,
|
||||
key: 'ghost_head',
|
||||
type: 'blog',
|
||||
updated_at: '2015-09-23T13:32:49.858Z',
|
||||
updated_by: 1,
|
||||
uuid: 'df7f3151-bc08-4a77-be9d-dd315b630d51',
|
||||
value: ''
|
||||
}, {
|
||||
created_at: '2015-09-11T09:44:30.809Z',
|
||||
created_by: 1,
|
||||
id: 14,
|
||||
key: 'ghost_foot',
|
||||
type: 'blog',
|
||||
updated_at: '2015-09-23T13:32:49.858Z',
|
||||
updated_by: 1,
|
||||
uuid: '0649d45e-828b-4dd0-8381-3dff6d1d5ddb',
|
||||
value: ''
|
||||
}];
|
||||
|
||||
describe('Acceptance: Settings - Navigation', function () {
|
||||
var application,
|
||||
store,
|
||||
server;
|
||||
|
||||
beforeEach(function () {
|
||||
application = startApp();
|
||||
store = application.__container__.lookup('store:main');
|
||||
server = new Pretender(function () {
|
||||
this.get('/ghost/api/v0.1/settings/', function (_request) {
|
||||
var response = {meta: {filters: 'blog,theme'}};
|
||||
response.settings = [{
|
||||
created_at: '2015-09-11T09:44:30.810Z',
|
||||
created_by: 1,
|
||||
id: 16,
|
||||
key: 'navigation',
|
||||
type: 'blog',
|
||||
updated_at: '2015-09-23T13:32:49.868Z',
|
||||
updated_by: 1,
|
||||
uuid: '4cc51d1c-fcbd-47e6-a71b-fdd1abb223fc',
|
||||
value: JSON.stringify([
|
||||
{label: 'Home', url: '/'},
|
||||
{label: 'About', url: '/about'}
|
||||
])
|
||||
}];
|
||||
response.settings.pushObjects(requiredSettings);
|
||||
|
||||
return [200, {'Content-Type': 'application/json'}, JSON.stringify(response)];
|
||||
});
|
||||
|
||||
// TODO: This will be needed for all authenticated page loads
|
||||
// - is there some way to make this a default?
|
||||
this.get('/ghost/api/v0.1/notifications/', function (_request) {
|
||||
return [200, {'Content-Type': 'application/json'}, JSON.stringify({notifications: []})];
|
||||
});
|
||||
|
||||
this.put('/ghost/api/v0.1/settings/', function (_request) {
|
||||
var response = {meta: {}};
|
||||
response.settings = [{
|
||||
created_at: '2015-09-11T09:44:30.810Z',
|
||||
created_by: 1,
|
||||
id: 16,
|
||||
key: 'navigation',
|
||||
type: 'blog',
|
||||
updated_at: '2015-09-23T13:32:49.868Z',
|
||||
updated_by: 1,
|
||||
uuid: '4cc51d1c-fcbd-47e6-a71b-fdd1abb223fc',
|
||||
value: JSON.stringify([
|
||||
{label: 'Test', url: '/test'},
|
||||
{label: 'About', url: '/about'}
|
||||
])
|
||||
}];
|
||||
response.settings.pushObjects(requiredSettings);
|
||||
|
||||
return [200, {'Content-Type': 'application/json'}, JSON.stringify(response)];
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
Ember.run(application, 'destroy');
|
||||
});
|
||||
|
||||
it('redirects to signin when not authenticated', function () {
|
||||
invalidateSession();
|
||||
visit('/settings/navigation');
|
||||
|
||||
andThen(function () {
|
||||
expect(currentPath()).to.not.equal('settings.navigation');
|
||||
});
|
||||
});
|
||||
|
||||
it('redirects to team page when authenticated as author', function () {
|
||||
run(() => {
|
||||
let role = store.createRecord('role', {name: 'Author'});
|
||||
store.createRecord('user', {id: 'me', roles: [role]});
|
||||
});
|
||||
|
||||
authenticateSession();
|
||||
visit('/settings/navigation');
|
||||
|
||||
andThen(function () {
|
||||
expect(currentPath()).to.equal('team.user');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when logged in', function () {
|
||||
beforeEach(function () {
|
||||
run(() => {
|
||||
let role = store.createRecord('role', {name: 'Administrator'});
|
||||
store.createRecord('user', {id: 'me', roles: [role]});
|
||||
});
|
||||
|
||||
authenticateSession();
|
||||
});
|
||||
|
||||
it('can visit /settings/navigation', function () {
|
||||
visit('/settings/navigation');
|
||||
|
||||
andThen(function () {
|
||||
expect(currentPath()).to.equal('settings.navigation');
|
||||
// test has expected number of rows
|
||||
expect($('.gh-blognav-item').length).to.equal(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('saves settings', function () {
|
||||
visit('/settings/navigation');
|
||||
fillIn('.gh-blognav-label:first input', 'Test');
|
||||
fillIn('.gh-blognav-url:first input', '/test');
|
||||
triggerEvent('.gh-blognav-url:first input', 'blur');
|
||||
|
||||
click('.btn-blue');
|
||||
|
||||
andThen(function () {
|
||||
// TODO: Test for successful save here once we have a visual
|
||||
// indication. For now we know the save happened because
|
||||
// Pretender doesn't complain about an unknown URL
|
||||
expect($('.error').length).to.equal(0);
|
||||
expect($('.gh-alert').length).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('clears unsaved settings when navigating away', function () {
|
||||
visit('/settings/navigation');
|
||||
|
||||
andThen(function () {
|
||||
$('.gh-blognav-label input').val('Test');
|
||||
expect($('.gh-blognav-label:first input').val()).to.equal('Test');
|
||||
});
|
||||
|
||||
visit('/settings/code-injection');
|
||||
visit('/settings/navigation');
|
||||
|
||||
andThen(function () {
|
||||
expect($('.gh-blognav-label:first input').val()).to.equal('Home');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -10,6 +10,14 @@
|
|||
{{content-for 'head'}}
|
||||
{{content-for 'test-head'}}
|
||||
|
||||
<meta name="env-fileStorage" content="true" />
|
||||
<meta name="env-apps" content="false" />
|
||||
<meta name="env-blogUrl" content="http://localhost:7357/" />
|
||||
<meta name="env-blogTitle" content="The Daily Awesome" />
|
||||
<meta name="env-routeKeywords" content="{"tag":"tag","author":"author","page":"page","preview":"p","private":"private"}" />
|
||||
<meta name="env-clientId" content="ghost-admin" />
|
||||
<meta name="env-clientSecret" content="5076dc643873" />
|
||||
|
||||
<link rel="stylesheet" href="assets/vendor.css">
|
||||
<link rel="stylesheet" href="assets/ghost.css">
|
||||
<link rel="stylesheet" href="assets/test-support.css">
|
||||
|
|
|
@ -54,17 +54,21 @@ describeComponent(
|
|||
// move second item up one
|
||||
expectedOldIndex = 1;
|
||||
expectedNewIndex = 0;
|
||||
Ember.$(this.$('.gh-blognav-item')[1]).simulateDragSortable({
|
||||
move: -1,
|
||||
handle: '.gh-blognav-grab'
|
||||
run(() => {
|
||||
Ember.$(this.$('.gh-blognav-item')[1]).simulateDragSortable({
|
||||
move: -1,
|
||||
handle: '.gh-blognav-grab'
|
||||
});
|
||||
});
|
||||
|
||||
// move second item down one
|
||||
expectedOldIndex = 1;
|
||||
expectedNewIndex = 2;
|
||||
Ember.$(this.$('.gh-blognav-item')[1]).simulateDragSortable({
|
||||
move: 1,
|
||||
handle: '.gh-blognav-grab'
|
||||
run(() => {
|
||||
Ember.$(this.$('.gh-blognav-item')[1]).simulateDragSortable({
|
||||
move: 1,
|
||||
handle: '.gh-blognav-grab'
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue