diff --git a/core/client/app/router.js b/core/client/app/router.js
index 56cb015253..6a7f4e53e9 100644
--- a/core/client/app/router.js
+++ b/core/client/app/router.js
@@ -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(),
diff --git a/core/client/app/routes/settings/navigation.js b/core/client/app/routes/settings/navigation.js
index 4660cde193..b86e65b41b 100644
--- a/core/client/app/routes/settings/navigation.js
+++ b/core/client/app/routes/settings/navigation.js
@@ -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);
}
}
});
diff --git a/core/client/bower.json b/core/client/bower.json
index f97f82ff64..0eb33329a5 100644
--- a/core/client/bower.json
+++ b/core/client/bower.json
@@ -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",
diff --git a/core/client/config/environment.js b/core/client/config/environment.js
index 2eea50c355..b8d4b2c302 100644
--- a/core/client/config/environment.js
+++ b/core/client/config/environment.js
@@ -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;
diff --git a/core/client/package.json b/core/client/package.json
index 790e0ac5f2..1c2c0a7b66 100644
--- a/core/client/package.json
+++ b/core/client/package.json
@@ -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",
diff --git a/core/client/tests/.jshintrc b/core/client/tests/.jshintrc
index b97fc9cbcb..b364e56a6b 100644
--- a/core/client/tests/.jshintrc
+++ b/core/client/tests/.jshintrc
@@ -1,5 +1,8 @@
{
"predef": [
+ "authenticateSession",
+ "invalidateSession",
+ "currentSession",
"document",
"window",
"location",
diff --git a/core/client/tests/acceptance/settings/navigation-test.js b/core/client/tests/acceptance/settings/navigation-test.js
new file mode 100644
index 0000000000..026f2e922a
--- /dev/null
+++ b/core/client/tests/acceptance/settings/navigation-test.js
@@ -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');
+ });
+ });
+ });
+});
diff --git a/core/client/tests/index.html b/core/client/tests/index.html
index 9ed774846a..3dee3fb615 100644
--- a/core/client/tests/index.html
+++ b/core/client/tests/index.html
@@ -10,6 +10,14 @@
{{content-for 'head'}}
{{content-for 'test-head'}}
+
+
+
+
+
+
+
+
diff --git a/core/client/tests/integration/components/gh-navigation-test.js b/core/client/tests/integration/components/gh-navigation-test.js
index ffb3d36e23..74451d864c 100644
--- a/core/client/tests/integration/components/gh-navigation-test.js
+++ b/core/client/tests/integration/components/gh-navigation-test.js
@@ -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'
+ });
});
});
}