2015-10-05 09:07:44 +03:00
|
|
|
/* jshint expr:true */
|
2016-11-14 16:16:51 +03:00
|
|
|
/* eslint-disable camelcase */
|
2015-10-05 09:07:44 +03:00
|
|
|
import {
|
|
|
|
describe,
|
|
|
|
it,
|
|
|
|
beforeEach,
|
|
|
|
afterEach
|
|
|
|
} from 'mocha';
|
2016-11-14 16:16:51 +03:00
|
|
|
import {expect} from 'chai';
|
2015-10-05 09:07:44 +03:00
|
|
|
import startApp from '../../helpers/start-app';
|
2015-11-30 20:21:39 +03:00
|
|
|
import destroyApp from '../../helpers/destroy-app';
|
2016-11-14 16:16:51 +03:00
|
|
|
import {invalidateSession, authenticateSession} from 'ghost-admin/tests/helpers/ember-simple-auth';
|
2015-10-05 09:07:44 +03:00
|
|
|
|
|
|
|
describe('Acceptance: Settings - Navigation', function () {
|
2015-10-13 16:52:41 +03:00
|
|
|
let application;
|
2015-10-05 09:07:44 +03:00
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
application = startApp();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
2015-11-30 20:21:39 +03:00
|
|
|
destroyApp(application);
|
2015-10-05 09:07:44 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects to signin when not authenticated', function () {
|
2015-10-18 21:17:02 +03:00
|
|
|
invalidateSession(application);
|
2015-10-05 09:07:44 +03:00
|
|
|
visit('/settings/navigation');
|
|
|
|
|
|
|
|
andThen(function () {
|
2015-10-13 16:52:41 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/signin');
|
2015-10-05 09:07:44 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects to team page when authenticated as author', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let role = server.create('role', {name: 'Author'});
|
2016-11-14 16:16:51 +03:00
|
|
|
server.create('user', {roles: [role], slug: 'test-user'});
|
2015-10-05 09:07:44 +03:00
|
|
|
|
2015-10-18 21:17:02 +03:00
|
|
|
authenticateSession(application);
|
2015-10-05 09:07:44 +03:00
|
|
|
visit('/settings/navigation');
|
|
|
|
|
|
|
|
andThen(function () {
|
2015-10-13 16:52:41 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/team/test-user');
|
2015-10-05 09:07:44 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when logged in', function () {
|
|
|
|
beforeEach(function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let role = server.create('role', {name: 'Administrator'});
|
2016-11-14 16:16:51 +03:00
|
|
|
server.create('user', {roles: [role]});
|
2015-10-13 16:52:41 +03:00
|
|
|
|
2015-10-18 21:17:02 +03:00
|
|
|
authenticateSession(application);
|
2015-10-05 09:07:44 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can visit /settings/navigation', function () {
|
|
|
|
visit('/settings/navigation');
|
|
|
|
|
|
|
|
andThen(function () {
|
|
|
|
expect(currentPath()).to.equal('settings.navigation');
|
2016-02-09 20:16:18 +03:00
|
|
|
|
|
|
|
// fixtures contain two nav items, check for three rows as we
|
|
|
|
// should have one extra that's blank
|
|
|
|
expect(
|
|
|
|
find('.gh-blognav-item').length,
|
|
|
|
'navigation items count'
|
|
|
|
).to.equal(3);
|
2015-10-05 09:07:44 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-02-09 20:16:18 +03:00
|
|
|
it('saves navigation settings', function () {
|
2015-10-05 09:07:44 +03:00
|
|
|
visit('/settings/navigation');
|
|
|
|
fillIn('.gh-blognav-label:first input', 'Test');
|
|
|
|
fillIn('.gh-blognav-url:first input', '/test');
|
|
|
|
triggerEvent('.gh-blognav-url:first input', 'blur');
|
|
|
|
|
2017-02-16 22:50:05 +03:00
|
|
|
click('.gh-btn-blue');
|
2015-10-05 09:07:44 +03:00
|
|
|
|
|
|
|
andThen(function () {
|
2016-02-09 20:16:18 +03:00
|
|
|
let [navSetting] = server.db.settings.where({key: 'navigation'});
|
|
|
|
|
|
|
|
expect(navSetting.value).to.equal('[{"label":"Test","url":"/test/"},{"label":"About","url":"/about"}]');
|
2015-10-14 12:37:57 +03:00
|
|
|
|
|
|
|
// don't test against .error directly as it will pick up failed
|
|
|
|
// tests "pre.error" elements
|
2016-02-09 20:16:18 +03:00
|
|
|
expect(find('span.error').length, 'error fields count').to.equal(0);
|
|
|
|
expect(find('.gh-alert').length, 'alerts count').to.equal(0);
|
|
|
|
expect(find('.response:visible').length, 'validation errors count')
|
|
|
|
.to.equal(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('validates new item correctly on save', function () {
|
|
|
|
visit('/settings/navigation');
|
|
|
|
|
2017-02-16 22:50:05 +03:00
|
|
|
click('.gh-btn-blue');
|
2016-02-09 20:16:18 +03:00
|
|
|
|
|
|
|
andThen(function () {
|
|
|
|
expect(
|
|
|
|
find('.gh-blognav-item').length,
|
|
|
|
'number of nav items after saving with blank new item'
|
|
|
|
).to.equal(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
fillIn('.gh-blognav-label:last input', 'Test');
|
|
|
|
fillIn('.gh-blognav-url:last input', 'http://invalid domain/');
|
|
|
|
triggerEvent('.gh-blognav-url:last input', 'blur');
|
|
|
|
|
2017-02-16 22:50:05 +03:00
|
|
|
click('.gh-btn-blue');
|
2016-02-09 20:16:18 +03:00
|
|
|
|
|
|
|
andThen(function () {
|
|
|
|
expect(
|
|
|
|
find('.gh-blognav-item').length,
|
|
|
|
'number of nav items after saving with invalid new item'
|
|
|
|
).to.equal(3);
|
|
|
|
|
|
|
|
expect(
|
2016-04-19 22:08:36 +03:00
|
|
|
find('.gh-blognav-item:last .error').length,
|
2016-02-09 20:16:18 +03:00
|
|
|
'number of invalid fields in new item'
|
|
|
|
).to.equal(1);
|
2015-10-05 09:07:44 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('clears unsaved settings when navigating away', function () {
|
|
|
|
visit('/settings/navigation');
|
2015-10-14 12:37:57 +03:00
|
|
|
fillIn('.gh-blognav-label:first input', 'Test');
|
|
|
|
triggerEvent('.gh-blognav-label:first input', 'blur');
|
2015-10-05 09:07:44 +03:00
|
|
|
|
|
|
|
andThen(function () {
|
2016-02-09 20:16:18 +03:00
|
|
|
expect(find('.gh-blognav-label:first input').val()).to.equal('Test');
|
2015-10-05 09:07:44 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
visit('/settings/code-injection');
|
|
|
|
visit('/settings/navigation');
|
|
|
|
|
|
|
|
andThen(function () {
|
2016-02-09 20:16:18 +03:00
|
|
|
expect(find('.gh-blognav-label:first input').val()).to.equal('Home');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can add and remove items', function (done) {
|
|
|
|
visit('/settings/navigation');
|
|
|
|
|
|
|
|
click('.gh-blognav-add');
|
|
|
|
|
|
|
|
andThen(function () {
|
|
|
|
expect(
|
|
|
|
find('.gh-blognav-label:last .response').is(':visible'),
|
|
|
|
'blank label has validation error'
|
|
|
|
).to.be.true;
|
|
|
|
});
|
|
|
|
|
|
|
|
fillIn('.gh-blognav-label:last input', 'New');
|
|
|
|
triggerEvent('.gh-blognav-label:last input', 'keypress', {});
|
|
|
|
|
|
|
|
andThen(function () {
|
|
|
|
expect(
|
|
|
|
find('.gh-blognav-label:last .response').is(':visible'),
|
|
|
|
'label validation is visible after typing'
|
|
|
|
).to.be.false;
|
|
|
|
});
|
|
|
|
|
|
|
|
fillIn('.gh-blognav-url:last input', '/new');
|
|
|
|
triggerEvent('.gh-blognav-url:last input', 'keypress', {});
|
|
|
|
triggerEvent('.gh-blognav-url:last input', 'blur');
|
|
|
|
|
|
|
|
andThen(function () {
|
|
|
|
expect(
|
|
|
|
find('.gh-blognav-url:last .response').is(':visible'),
|
|
|
|
'url validation is visible after typing'
|
|
|
|
).to.be.false;
|
|
|
|
|
|
|
|
expect(
|
|
|
|
find('.gh-blognav-url:last input').val()
|
|
|
|
).to.equal(`${window.location.protocol}//${window.location.host}/new/`);
|
|
|
|
});
|
|
|
|
|
|
|
|
click('.gh-blognav-add');
|
|
|
|
|
|
|
|
andThen(function () {
|
|
|
|
expect(
|
|
|
|
find('.gh-blognav-item').length,
|
|
|
|
'number of nav items after successful add'
|
|
|
|
).to.equal(4);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
find('.gh-blognav-label:last input').val(),
|
|
|
|
'new item label value after successful add'
|
|
|
|
).to.be.blank;
|
|
|
|
|
|
|
|
expect(
|
|
|
|
find('.gh-blognav-url:last input').val(),
|
|
|
|
'new item url value after successful add'
|
|
|
|
).to.equal(`${window.location.protocol}//${window.location.host}/`);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
find('.gh-blognav-item .response:visible').length,
|
|
|
|
'number or validation errors shown after successful add'
|
|
|
|
).to.equal(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
click('.gh-blognav-item:first .gh-blognav-delete');
|
|
|
|
|
|
|
|
andThen(function () {
|
|
|
|
expect(
|
|
|
|
find('.gh-blognav-item').length,
|
|
|
|
'number of nav items after successful remove'
|
|
|
|
).to.equal(3);
|
|
|
|
});
|
|
|
|
|
2017-02-16 22:50:05 +03:00
|
|
|
click('.gh-btn-blue');
|
2016-02-09 20:16:18 +03:00
|
|
|
|
|
|
|
andThen(function () {
|
|
|
|
let [navSetting] = server.db.settings.where({key: 'navigation'});
|
|
|
|
|
|
|
|
expect(navSetting.value).to.equal('[{"label":"About","url":"/about"},{"label":"New","url":"/new/"}]');
|
|
|
|
|
|
|
|
done();
|
2015-10-05 09:07:44 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|