2017-05-29 21:50:03 +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';
|
2017-05-18 13:48:37 +03:00
|
|
|
import {
|
|
|
|
beforeEach,
|
2017-05-29 21:50:03 +03:00
|
|
|
describe,
|
|
|
|
it
|
2017-05-18 13:48:37 +03:00
|
|
|
} from 'mocha';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {click, currentURL, find, findAll, triggerEvent} from '@ember/test-helpers';
|
2017-05-18 13:48:37 +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-05-18 13:48:37 +03:00
|
|
|
|
2018-10-04 13:02:36 +03:00
|
|
|
describe('Acceptance: Settings - Integrations - AMP', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let hooks = setupApplicationTest();
|
|
|
|
setupMirage(hooks);
|
2017-05-18 13:48:37 +03:00
|
|
|
|
|
|
|
it('redirects to signin when not authenticated', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
await invalidateSession();
|
2021-11-05 15:42:38 +03:00
|
|
|
await visit('/settings/integrations/amp');
|
2017-05-18 13:48:37 +03:00
|
|
|
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/signin');
|
|
|
|
});
|
|
|
|
|
2022-01-17 13:05:27 +03:00
|
|
|
it('redirects to home 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-11-05 15:42:38 +03:00
|
|
|
await visit('/settings/integrations/amp');
|
2018-02-07 12:42:46 +03:00
|
|
|
|
2022-02-02 12:57:34 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/posts');
|
2018-02-07 12:42:46 +03:00
|
|
|
});
|
|
|
|
|
2022-01-17 13:05:27 +03:00
|
|
|
it('redirects to home 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-05-18 13:48:37 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await authenticateSession();
|
2021-11-05 15:42:38 +03:00
|
|
|
await visit('/settings/integrations/amp');
|
2017-05-18 13:48:37 +03:00
|
|
|
|
2022-01-17 13:05:27 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/site');
|
2017-05-18 13:48:37 +03:00
|
|
|
});
|
|
|
|
|
2022-01-17 13:05:27 +03:00
|
|
|
it('redirects to home 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-05-18 13:48:37 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await authenticateSession();
|
2021-11-05 15:42:38 +03:00
|
|
|
await visit('/settings/integrations/amp');
|
2017-05-18 13:48:37 +03:00
|
|
|
|
2022-01-17 13:05:27 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/site');
|
2017-05-18 13:48:37 +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-05-18 13:48:37 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
return await authenticateSession();
|
2017-05-18 13:48:37 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('it enables or disables AMP properly and saves it', async function () {
|
2021-11-05 15:42:38 +03:00
|
|
|
await visit('/settings/integrations/amp');
|
2017-05-18 13:48:37 +03:00
|
|
|
|
|
|
|
// has correct url
|
2021-11-05 15:42:38 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/integrations/amp');
|
2017-05-18 13:48:37 +03:00
|
|
|
|
2022-05-30 16:09:04 +03:00
|
|
|
// AMP is disabled by default
|
|
|
|
expect(find('[data-test-amp-checkbox]').checked, 'AMP checkbox').to.be.false;
|
2017-05-18 13:48:37 +03:00
|
|
|
|
2017-08-11 18:28:05 +03:00
|
|
|
await click('[data-test-amp-checkbox]');
|
2017-05-18 13:48:37 +03:00
|
|
|
|
2022-05-30 16:09:04 +03:00
|
|
|
expect(find('[data-test-amp-checkbox]').checked, 'AMP checkbox').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
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
let [lastRequest] = this.server.pretender.handledRequests.slice(-1);
|
2017-05-18 13:48:37 +03:00
|
|
|
let params = JSON.parse(lastRequest.requestBody);
|
|
|
|
|
2022-05-30 16:09:04 +03:00
|
|
|
expect(params.settings.findBy('key', 'amp').value).to.equal(true);
|
2017-05-18 13:48:37 +03:00
|
|
|
|
|
|
|
// CMD-S shortcut works
|
2017-08-11 18:28:05 +03:00
|
|
|
await click('[data-test-amp-checkbox]');
|
2017-05-18 13:48:37 +03:00
|
|
|
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
|
2019-01-02 12:58:55 +03:00
|
|
|
let [newRequest] = this.server.pretender.handledRequests.slice(-1);
|
2017-05-18 13:48:37 +03:00
|
|
|
params = JSON.parse(newRequest.requestBody);
|
|
|
|
|
2022-05-30 16:09:04 +03:00
|
|
|
expect(find('[data-test-amp-checkbox]').checked, 'AMP checkbox').to.be.false;
|
|
|
|
expect(params.settings.findBy('key', 'amp').value).to.equal(false);
|
2017-05-18 13:48:37 +03:00
|
|
|
});
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
it('warns when leaving without saving', async function () {
|
2021-11-05 15:42:38 +03:00
|
|
|
await visit('/settings/integrations/amp');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
// has correct url
|
2021-11-05 15:42:38 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/integrations/amp');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2022-05-30 16:09:04 +03:00
|
|
|
// AMP is disabled by default
|
|
|
|
expect(find('[data-test-amp-checkbox]').checked, 'AMP checkbox default').to.be.false;
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
await click('[data-test-amp-checkbox]');
|
|
|
|
|
2022-05-30 16:09:04 +03:00
|
|
|
expect(find('[data-test-amp-checkbox]').checked, 'AMP checkbox after click').to.be.true;
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2021-11-04 11:40:24 +03:00
|
|
|
await visit('/settings/staff');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2022-09-09 19:02:45 +03:00
|
|
|
expect(findAll('[data-test-modal="unsaved-settings"]').length, 'unsaved changes modal exists').to.equal(1);
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
// Leave without saving
|
2022-09-09 19:02:45 +03:00
|
|
|
await click('[data-test-leave-button]');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2021-11-04 11:40:24 +03:00
|
|
|
expect(currentURL(), 'currentURL after leave without saving').to.equal('/settings/staff');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2021-11-05 15:42:38 +03:00
|
|
|
await visit('/settings/integrations/amp');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2021-11-05 15:42:38 +03:00
|
|
|
expect(currentURL(), 'currentURL after return').to.equal('/settings/integrations/amp');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
// settings were not saved
|
2022-05-30 16:09:04 +03:00
|
|
|
expect(find('[data-test-amp-checkbox]').checked, 'AMP checkbox').to.be.false;
|
2017-10-31 18:27:25 +03:00
|
|
|
});
|
2017-05-18 13:48:37 +03:00
|
|
|
});
|
|
|
|
});
|