2015-10-05 09:07:44 +03:00
|
|
|
/* jshint expr:true */
|
2015-10-28 14:36:45 +03:00
|
|
|
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
|
2015-10-05 09:07:44 +03:00
|
|
|
import {
|
|
|
|
describe,
|
|
|
|
it,
|
|
|
|
beforeEach,
|
|
|
|
afterEach
|
|
|
|
} from 'mocha';
|
|
|
|
import { expect } from 'chai';
|
|
|
|
import startApp from '../../helpers/start-app';
|
2015-11-30 20:21:39 +03:00
|
|
|
import destroyApp from '../../helpers/destroy-app';
|
2015-10-18 21:17:02 +03:00
|
|
|
import { invalidateSession, authenticateSession } from 'ghost/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'});
|
|
|
|
let user = 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'});
|
|
|
|
let user = server.create('user', {roles: [role]});
|
2015-10-13 16:52:41 +03:00
|
|
|
|
|
|
|
// load the settings fixtures
|
|
|
|
// TODO: this should always be run for acceptance tests
|
|
|
|
server.loadFixtures();
|
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
|
|
|
});
|
|
|
|
|
|
|
|
it('can visit /settings/navigation', function () {
|
|
|
|
visit('/settings/navigation');
|
|
|
|
|
|
|
|
andThen(function () {
|
|
|
|
expect(currentPath()).to.equal('settings.navigation');
|
|
|
|
// test has expected number of rows
|
2015-10-13 16:52:41 +03:00
|
|
|
expect($('.gh-blognav-item').length, 'navigation items count').to.equal(3);
|
2015-10-05 09:07:44 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
2015-10-14 12:37:57 +03:00
|
|
|
|
|
|
|
// don't test against .error directly as it will pick up failed
|
|
|
|
// tests "pre.error" elements
|
|
|
|
expect($('span.error').length, 'error fields count').to.equal(0);
|
|
|
|
expect($('.gh-alert').length, 'alerts count').to.equal(0);
|
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 () {
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|