2017-08-02 10:05:59 +03:00
|
|
|
import ctrlOrCmd from 'ghost-admin/utils/ctrl-or-cmd';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
|
|
|
|
import {
|
|
|
|
beforeEach,
|
|
|
|
describe,
|
|
|
|
it
|
|
|
|
} from 'mocha';
|
|
|
|
import {click, currentURL, find, findAll, triggerEvent} from '@ember/test-helpers';
|
2017-08-02 10:05:59 +03:00
|
|
|
import {expect} from 'chai';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {setupApplicationTest} from 'ember-mocha';
|
2019-05-27 11:37:05 +03:00
|
|
|
import {setupMirage} from 'ember-cli-mirage/test-support';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {visit} from '../../helpers/visit';
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2018-10-04 13:02:36 +03:00
|
|
|
describe('Acceptance: Settings - Integrations - Unsplash', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let hooks = setupApplicationTest();
|
|
|
|
setupMirage(hooks);
|
2017-08-02 10:05:59 +03:00
|
|
|
|
|
|
|
it('redirects to signin when not authenticated', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
await invalidateSession();
|
2021-01-28 18:25:21 +03:00
|
|
|
await visit('/integrations/unsplash');
|
2017-08-02 10:05:59 +03:00
|
|
|
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/signin');
|
|
|
|
});
|
|
|
|
|
2019-02-22 12:43:35 +03:00
|
|
|
it('redirects to staff page when authenticated as contributor', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let role = this.server.create('role', {name: 'Contributor'});
|
|
|
|
this.server.create('user', {roles: [role], slug: 'test-user'});
|
2018-02-07 12:42:46 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await authenticateSession();
|
2021-01-28 18:25:21 +03:00
|
|
|
await visit('/integrations/unsplash');
|
2018-02-07 12:42:46 +03:00
|
|
|
|
2019-02-22 12:43:35 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/staff/test-user');
|
2018-02-07 12:42:46 +03:00
|
|
|
});
|
|
|
|
|
2019-02-22 12:43:35 +03:00
|
|
|
it('redirects to staff page when authenticated as author', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let role = this.server.create('role', {name: 'Author'});
|
|
|
|
this.server.create('user', {roles: [role], slug: 'test-user'});
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await authenticateSession();
|
2021-01-28 18:25:21 +03:00
|
|
|
await visit('/integrations/unsplash');
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2019-02-22 12:43:35 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/staff/test-user');
|
2017-08-02 10:05:59 +03:00
|
|
|
});
|
|
|
|
|
2019-02-22 12:43:35 +03:00
|
|
|
it('redirects to staff page when authenticated as editor', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let role = this.server.create('role', {name: 'Editor'});
|
|
|
|
this.server.create('user', {roles: [role], slug: 'test-user'});
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await authenticateSession();
|
2021-01-28 18:25:21 +03:00
|
|
|
await visit('/integrations/unsplash');
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2019-02-22 12:43:35 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/staff');
|
2017-08-02 10:05:59 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when logged in', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
beforeEach(async function () {
|
|
|
|
let role = this.server.create('role', {name: 'Administrator'});
|
|
|
|
this.server.create('user', {roles: [role]});
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
return await authenticateSession();
|
2017-08-02 10:05:59 +03:00
|
|
|
});
|
|
|
|
|
2017-09-20 13:19:48 +03:00
|
|
|
it('it can activate/deactivate', async function () {
|
2021-01-28 18:25:21 +03:00
|
|
|
await visit('/integrations/unsplash');
|
2017-08-02 10:05:59 +03:00
|
|
|
|
|
|
|
// has correct url
|
2021-01-28 18:25:21 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/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(
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.db.settings.where({key: 'unsplash'}),
|
2017-09-20 13:19:48 +03:00
|
|
|
'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(
|
2019-01-02 12:58:55 +03:00
|
|
|
find('[data-test-checkbox="unsplash"]').checked,
|
2017-09-20 13:19:48 +03:00
|
|
|
'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
|
2019-01-02 12:58:55 +03:00
|
|
|
let [setting] = this.server.db.settings.where({key: 'unsplash'});
|
2017-09-20 13:19:48 +03:00
|
|
|
expect(setting, 'unsplash setting after save').to.exist;
|
2021-02-18 03:25:21 +03:00
|
|
|
expect(setting.value).to.equal(true);
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2017-09-20 13:19:48 +03:00
|
|
|
// disable
|
2019-01-02 12:58:55 +03:00
|
|
|
await click('[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
|
2019-01-02 12:58:55 +03:00
|
|
|
[setting] = this.server.db.settings.where({key: 'unsplash'});
|
2021-02-18 03:25:21 +03:00
|
|
|
expect(setting.value).to.equal(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 () {
|
2021-01-28 18:25:21 +03:00
|
|
|
await visit('/integrations/unsplash');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
// has correct url
|
2021-01-28 18:25:21 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/integrations/unsplash');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
find('[data-test-checkbox="unsplash"]').checked,
|
2017-10-31 18:27:25 +03:00
|
|
|
'checked by default'
|
|
|
|
).to.be.true;
|
|
|
|
|
|
|
|
await click('[data-test-checkbox="unsplash"]');
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('[data-test-checkbox="unsplash"]').checked, 'Unsplash checkbox').to.be.false;
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
await visit('/settings/labs');
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('.fullscreen-modal').length, 'modal exists').to.equal(1);
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
// Leave without saving
|
2019-01-02 12:58:55 +03:00
|
|
|
await click('.fullscreen-modal [data-test-leave-button]');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/labs');
|
|
|
|
|
2021-01-28 18:25:21 +03:00
|
|
|
await visit('/integrations/unsplash');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2021-01-28 18:25:21 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/integrations/unsplash');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
// settings were not saved
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('[data-test-checkbox="unsplash"]').checked, 'Unsplash checkbox').to.be.true;
|
2017-10-31 18:27:25 +03:00
|
|
|
});
|
2017-08-02 10:05:59 +03:00
|
|
|
});
|
|
|
|
});
|