2017-08-02 10:05:59 +03:00
|
|
|
/* jshint expr:true */
|
|
|
|
import ctrlOrCmd from 'ghost-admin/utils/ctrl-or-cmd';
|
|
|
|
import destroyApp from '../../helpers/destroy-app';
|
|
|
|
import startApp from '../../helpers/start-app';
|
|
|
|
import {afterEach, beforeEach, describe, it} from 'mocha';
|
|
|
|
import {authenticateSession, invalidateSession} from 'ghost-admin/tests/helpers/ember-simple-auth';
|
|
|
|
import {expect} from 'chai';
|
|
|
|
|
|
|
|
describe('Acceptance: Settings - Apps - Unsplash', function () {
|
|
|
|
let application;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
application = startApp();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
destroyApp(application);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects to signin when not authenticated', async function () {
|
|
|
|
invalidateSession(application);
|
|
|
|
await visit('/settings/apps/unsplash');
|
|
|
|
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/signin');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects to team page when authenticated as author', async function () {
|
|
|
|
let role = server.create('role', {name: 'Author'});
|
|
|
|
server.create('user', {roles: [role], slug: 'test-user'});
|
|
|
|
|
|
|
|
authenticateSession(application);
|
|
|
|
await visit('/settings/apps/unsplash');
|
|
|
|
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/team/test-user');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects to team page when authenticated as editor', async function () {
|
|
|
|
let role = server.create('role', {name: 'Editor'});
|
|
|
|
server.create('user', {roles: [role], slug: 'test-user'});
|
|
|
|
|
|
|
|
authenticateSession(application);
|
|
|
|
await visit('/settings/apps/unsplash');
|
|
|
|
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/team');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when logged in', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
let role = server.create('role', {name: 'Administrator'});
|
|
|
|
server.create('user', {roles: [role]});
|
|
|
|
|
|
|
|
return authenticateSession(application);
|
|
|
|
});
|
|
|
|
|
2017-09-20 13:19:48 +03:00
|
|
|
it('it can activate/deactivate', async function () {
|
2017-08-02 10:05:59 +03:00
|
|
|
await visit('/settings/apps/unsplash');
|
|
|
|
|
|
|
|
// has correct url
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/apps/unsplash');
|
|
|
|
|
2017-09-20 13:19:48 +03:00
|
|
|
// verify we don't have an unsplash setting fixture loaded
|
|
|
|
expect(
|
|
|
|
server.db.settings.where({key: 'unsplash'}),
|
|
|
|
'initial server settings'
|
|
|
|
).to.be.empty;
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2017-09-20 13:19:48 +03:00
|
|
|
// it's enabled by default when settings is empty
|
|
|
|
expect(
|
|
|
|
find('[data-test-checkbox="unsplash"]').prop('checked'),
|
|
|
|
'checked by default'
|
|
|
|
).to.be.true;
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2017-09-20 13:19:48 +03:00
|
|
|
// trigger a save
|
2017-08-02 10:05:59 +03:00
|
|
|
await click('[data-test-save-button]');
|
|
|
|
|
2017-09-20 13:19:48 +03:00
|
|
|
// server should now have an unsplash setting
|
|
|
|
let [setting] = server.db.settings.where({key: 'unsplash'});
|
|
|
|
expect(setting, 'unsplash setting after save').to.exist;
|
|
|
|
expect(setting.value).to.equal('{"isActive":true}');
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2017-09-20 13:19:48 +03:00
|
|
|
// disable
|
|
|
|
await click(find('[data-test-checkbox="unsplash"]'));
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2017-09-20 13:19:48 +03:00
|
|
|
// save via CMD-S shortcut
|
2017-08-02 10:05:59 +03:00
|
|
|
await triggerEvent('.gh-app', 'keydown', {
|
|
|
|
keyCode: 83, // s
|
|
|
|
metaKey: ctrlOrCmd === 'command',
|
|
|
|
ctrlKey: ctrlOrCmd === 'ctrl'
|
|
|
|
});
|
|
|
|
|
2017-09-20 13:19:48 +03:00
|
|
|
// server should have an updated setting
|
|
|
|
[setting] = server.db.settings.where({key: 'unsplash'});
|
|
|
|
expect(setting.value).to.equal('{"isActive":false}');
|
2017-08-02 10:05:59 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|