mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-03 00:15:11 +03:00
34e15f0619
closes TryGhost/Ghost#9119, refs TryGhost/Ghost#8483 - Apps - AMP - Added `leave-settings-modal` component to Settings - Apps - AMP - Apps - Slack - Added `leave-settings-modal` component to Settings - Apps - Slack - Added a `triggerDirtyState` action that will uses a new Array with the input data to trigger the dirty state on the parent settings model - Apps - Unsplash - Added `leave-settings-modal` component to Settings - Apps - Unsplash - Used manual tracking of changes with using a custom `dirtyAttributes` property and a `rollbackValue` to manually rollback the `isActive` attribute on the model - Code injection - Added `leave-settings-modal` component to Settings - Code injection - Design - Added `leave-settings-modal` component to Settings - Design (only for navigation model) - Used manual tracking of changes with using a custom `dirtyAttributes` - Added an additional `updateLabel` action to underlying `gh-navitem` component which gets fired on the `focusOut` event, to detect changes on the label - Team - User - Added `leave-settings-modal` component to Team - User - Used manual tracking of changes with using a custom `dirtyAttributes` to track changes in slug and role properties
129 lines
4.5 KiB
JavaScript
129 lines
4.5 KiB
JavaScript
/* 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);
|
|
});
|
|
|
|
it('it can activate/deactivate', async function () {
|
|
await visit('/settings/apps/unsplash');
|
|
|
|
// has correct url
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/apps/unsplash');
|
|
|
|
// verify we don't have an unsplash setting fixture loaded
|
|
expect(
|
|
server.db.settings.where({key: 'unsplash'}),
|
|
'initial server settings'
|
|
).to.be.empty;
|
|
|
|
// it's enabled by default when settings is empty
|
|
expect(
|
|
find('[data-test-checkbox="unsplash"]').prop('checked'),
|
|
'checked by default'
|
|
).to.be.true;
|
|
|
|
// trigger a save
|
|
await click('[data-test-save-button]');
|
|
|
|
// 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}');
|
|
|
|
// disable
|
|
await click(find('[data-test-checkbox="unsplash"]'));
|
|
|
|
// save via CMD-S shortcut
|
|
await triggerEvent('.gh-app', 'keydown', {
|
|
keyCode: 83, // s
|
|
metaKey: ctrlOrCmd === 'command',
|
|
ctrlKey: ctrlOrCmd === 'ctrl'
|
|
});
|
|
|
|
// server should have an updated setting
|
|
[setting] = server.db.settings.where({key: 'unsplash'});
|
|
expect(setting.value).to.equal('{"isActive":false}');
|
|
});
|
|
|
|
it('warns when leaving without saving', async function () {
|
|
await visit('/settings/apps/unsplash');
|
|
|
|
// has correct url
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/apps/unsplash');
|
|
|
|
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
|
|
await(click('.fullscreen-modal [data-test-leave-button]'), 'leave without saving');
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/labs');
|
|
|
|
await visit('/settings/apps/unsplash');
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/apps/unsplash');
|
|
|
|
// settings were not saved
|
|
expect(find('[data-test-checkbox="unsplash"]').prop('checked'), 'Unsplash checkbox').to.be.true;
|
|
});
|
|
});
|
|
});
|