2015-10-05 09:07:44 +03:00
|
|
|
/* jshint expr:true */
|
|
|
|
import {
|
|
|
|
describe,
|
|
|
|
it,
|
|
|
|
beforeEach,
|
|
|
|
afterEach
|
|
|
|
} from 'mocha';
|
|
|
|
import { expect } from 'chai';
|
|
|
|
import Ember from 'ember';
|
|
|
|
import startApp from '../../helpers/start-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
|
|
|
|
2015-10-15 15:03:26 +03:00
|
|
|
const {run} = Ember;
|
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-10-13 16:52:41 +03:00
|
|
|
run(application, 'destroy');
|
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-13 16:52:41 +03:00
|
|
|
const role = server.create('role', {name: 'Author'}),
|
|
|
|
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-13 16:52:41 +03:00
|
|
|
const role = server.create('role', {name: 'Administrator'}),
|
|
|
|
user = server.create('user', {roles: [role]});
|
|
|
|
|
|
|
|
// 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');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|