2016-02-11 18:05:48 +03:00
|
|
|
/* jshint expr:true */
|
2017-05-29 21:50:03 +03:00
|
|
|
import $ from 'jquery';
|
|
|
|
import ctrlOrCmd from 'ghost-admin/utils/ctrl-or-cmd';
|
|
|
|
import destroyApp from '../../helpers/destroy-app';
|
|
|
|
import startApp from '../../helpers/start-app';
|
2016-02-11 18:05:48 +03:00
|
|
|
import {
|
2017-05-29 21:50:03 +03:00
|
|
|
afterEach,
|
2016-02-11 18:05:48 +03:00
|
|
|
beforeEach,
|
2017-05-29 21:50:03 +03:00
|
|
|
describe,
|
|
|
|
it
|
2016-02-11 18:05:48 +03:00
|
|
|
} from 'mocha';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {authenticateSession, invalidateSession} from 'ghost-admin/tests/helpers/ember-simple-auth';
|
2016-11-14 16:16:51 +03:00
|
|
|
import {expect} from 'chai';
|
2016-02-11 18:05:48 +03:00
|
|
|
|
|
|
|
describe('Acceptance: Settings - Code-Injection', function() {
|
|
|
|
let application;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
application = startApp();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
destroyApp(application);
|
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('redirects to signin when not authenticated', async function () {
|
2016-02-11 18:05:48 +03:00
|
|
|
invalidateSession(application);
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/settings/code-injection');
|
2016-02-11 18:05:48 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/signin');
|
2016-02-11 18:05:48 +03:00
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('redirects to team page when authenticated as author', async function () {
|
2016-02-11 18:05:48 +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'});
|
2016-02-11 18:05:48 +03:00
|
|
|
|
|
|
|
authenticateSession(application);
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/settings/code-injection');
|
2016-02-11 18:05:48 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/team/test-user');
|
2016-02-11 18:05:48 +03:00
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('redirects to team page when authenticated as editor', async function () {
|
2016-02-11 18:05:48 +03:00
|
|
|
let role = server.create('role', {name: 'Editor'});
|
2016-11-14 16:16:51 +03:00
|
|
|
server.create('user', {roles: [role], slug: 'test-user'});
|
2016-02-11 18:05:48 +03:00
|
|
|
|
|
|
|
authenticateSession(application);
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/settings/code-injection');
|
2016-02-11 18:05:48 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/team');
|
2016-02-11 18:05:48 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when logged in', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
let role = server.create('role', {name: 'Administrator'});
|
2016-11-14 16:16:51 +03:00
|
|
|
server.create('user', {roles: [role]});
|
2016-02-11 18:05:48 +03:00
|
|
|
|
|
|
|
return authenticateSession(application);
|
|
|
|
});
|
|
|
|
|
2017-05-18 13:48:37 +03:00
|
|
|
it('it renders, loads and saves editors correctly', async function () {
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/settings/code-injection');
|
2016-02-11 18:05:48 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
// has correct url
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/code-injection');
|
2016-02-11 18:05:48 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
// has correct page title
|
|
|
|
expect(document.title, 'page title').to.equal('Settings - Code injection - Test Blog');
|
2016-02-11 18:05:48 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
// highlights nav menu
|
|
|
|
expect($('.gh-nav-settings-code-injection').hasClass('active'), 'highlights nav menu item')
|
|
|
|
.to.be.true;
|
2016-02-11 18:05:48 +03:00
|
|
|
|
2017-08-11 18:28:05 +03:00
|
|
|
expect(find('[data-test-save-button]').text().trim(), 'save button text').to.equal('Save');
|
2016-02-11 18:05:48 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(find('#ghost-head .CodeMirror').length, 'ghost head codemirror element').to.equal(1);
|
|
|
|
expect($('#ghost-head .CodeMirror').hasClass('cm-s-xq-light'), 'ghost head editor theme').to.be.true;
|
2016-02-11 18:05:48 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(find('#ghost-foot .CodeMirror').length, 'ghost head codemirror element').to.equal(1);
|
|
|
|
expect($('#ghost-foot .CodeMirror').hasClass('cm-s-xq-light'), 'ghost head editor theme').to.be.true;
|
2017-05-18 13:48:37 +03:00
|
|
|
|
2017-08-11 18:28:05 +03:00
|
|
|
await click('[data-test-save-button]');
|
2017-05-18 13:48:37 +03:00
|
|
|
|
|
|
|
let [lastRequest] = server.pretender.handledRequests.slice(-1);
|
|
|
|
let params = JSON.parse(lastRequest.requestBody);
|
|
|
|
|
|
|
|
expect(params.settings.findBy('key', 'ghost_head').value).to.equal('');
|
2017-08-11 18:28:05 +03:00
|
|
|
expect(find('[data-test-save-button]').text().trim(), 'save button text').to.equal('Saved');
|
2017-05-18 13:48:37 +03:00
|
|
|
|
|
|
|
// CMD-S shortcut works
|
|
|
|
await triggerEvent('.gh-app', 'keydown', {
|
|
|
|
keyCode: 83, // s
|
|
|
|
metaKey: ctrlOrCmd === 'command',
|
|
|
|
ctrlKey: ctrlOrCmd === 'ctrl'
|
|
|
|
});
|
|
|
|
// we've already saved in this test so there's no on-screen indication
|
|
|
|
// that we've had another save, check the request was fired instead
|
|
|
|
let [newRequest] = server.pretender.handledRequests.slice(-1);
|
|
|
|
params = JSON.parse(newRequest.requestBody);
|
|
|
|
|
|
|
|
expect(params.settings.findBy('key', 'ghost_head').value).to.equal('');
|
2017-08-11 18:28:05 +03:00
|
|
|
expect(find('[data-test-save-button]').text().trim(), 'save button text').to.equal('Saved');
|
2016-02-11 18:05:48 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|