2017-08-02 10:05:59 +03:00
|
|
|
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';
|
|
|
|
|
2018-10-04 13:02:36 +03:00
|
|
|
describe('Acceptance: Settings - Integrations - Unsplash', function () {
|
2017-08-02 10:05:59 +03:00
|
|
|
let application;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
application = startApp();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
destroyApp(application);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects to signin when not authenticated', async function () {
|
|
|
|
invalidateSession(application);
|
2018-10-04 13:02:36 +03:00
|
|
|
await visit('/settings/integrations/unsplash');
|
2017-08-02 10:05:59 +03:00
|
|
|
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/signin');
|
|
|
|
});
|
|
|
|
|
2018-02-07 12:42:46 +03:00
|
|
|
it('redirects to team page when authenticated as contributor', async function () {
|
|
|
|
let role = server.create('role', {name: 'Contributor'});
|
|
|
|
server.create('user', {roles: [role], slug: 'test-user'});
|
|
|
|
|
|
|
|
authenticateSession(application);
|
2018-10-04 13:02:36 +03:00
|
|
|
await visit('/settings/integrations/unsplash');
|
2018-02-07 12:42:46 +03:00
|
|
|
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/team/test-user');
|
|
|
|
});
|
|
|
|
|
2017-08-02 10:05:59 +03:00
|
|
|
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);
|
2018-10-04 13:02:36 +03:00
|
|
|
await visit('/settings/integrations/unsplash');
|
2017-08-02 10:05:59 +03:00
|
|
|
|
|
|
|
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);
|
2018-10-04 13:02:36 +03:00
|
|
|
await visit('/settings/integrations/unsplash');
|
2017-08-02 10:05:59 +03:00
|
|
|
|
|
|
|
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 () {
|
2018-10-04 13:02:36 +03:00
|
|
|
await visit('/settings/integrations/unsplash');
|
2017-08-02 10:05:59 +03:00
|
|
|
|
|
|
|
// has correct url
|
2018-10-04 13:02:36 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/integrations/unsplash');
|
2017-08-02 10:05:59 +03:00
|
|
|
|
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
|
|
|
});
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
it('warns when leaving without saving', async function () {
|
2018-10-04 13:02:36 +03:00
|
|
|
await visit('/settings/integrations/unsplash');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
// has correct url
|
2018-10-04 13:02:36 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/integrations/unsplash');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
expect(
|
|
|
|
find('[data-test-checkbox="unsplash"]').prop('checked'),
|
|
|
|
'checked by default'
|
|
|
|
).to.be.true;
|
|
|
|
|
|
|
|
await click('[data-test-checkbox="unsplash"]');
|
|
|
|
|
|
|
|
expect(find('[data-test-checkbox="unsplash"]').prop('checked'), 'Unsplash checkbox').to.be.false;
|
|
|
|
|
|
|
|
await visit('/settings/labs');
|
|
|
|
|
|
|
|
expect(find('.fullscreen-modal').length, 'modal exists').to.equal(1);
|
|
|
|
|
|
|
|
// Leave without saving
|
2018-01-05 18:38:23 +03:00
|
|
|
await (click('.fullscreen-modal [data-test-leave-button]'), 'leave without saving');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/labs');
|
|
|
|
|
2018-10-04 13:02:36 +03:00
|
|
|
await visit('/settings/integrations/unsplash');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2018-10-04 13:02:36 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/integrations/unsplash');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
// settings were not saved
|
|
|
|
expect(find('[data-test-checkbox="unsplash"]').prop('checked'), 'Unsplash checkbox').to.be.true;
|
|
|
|
});
|
2017-08-02 10:05:59 +03:00
|
|
|
});
|
|
|
|
});
|