2019-01-02 12:58:55 +03:00
|
|
|
import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
|
|
|
|
import {beforeEach, describe, it} from 'mocha';
|
2020-07-16 12:13:36 +03:00
|
|
|
import {click, currentURL, fillIn, find, findAll} from '@ember/test-helpers';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {expect} from 'chai';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {fileUpload} from '../../helpers/file-upload';
|
|
|
|
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';
|
|
|
|
// import wait from 'ember-test-helpers/wait';
|
2017-09-21 18:01:40 +03:00
|
|
|
// import {timeout} from 'ember-concurrency';
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
describe('Acceptance: Settings - Labs', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let hooks = setupApplicationTest();
|
|
|
|
setupMirage(hooks);
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('redirects to signin when not authenticated', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
await invalidateSession();
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/settings/labs');
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/signin');
|
2016-02-11 18:19:04 +03:00
|
|
|
});
|
|
|
|
|
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();
|
2018-02-07 12:42:46 +03:00
|
|
|
await visit('/settings/labs');
|
|
|
|
|
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'});
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await authenticateSession();
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/settings/labs');
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2022-01-17 13:05:27 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/site');
|
2016-02-11 18:19:04 +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'});
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await authenticateSession();
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/settings/labs');
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2022-01-17 13:05:27 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/site');
|
2016-02-11 18:19:04 +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]});
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
return await authenticateSession();
|
2016-02-11 18:19:04 +03:00
|
|
|
});
|
|
|
|
|
2022-09-08 11:18:46 +03:00
|
|
|
it('it renders', async function () {
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/settings/labs');
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
// has correct url
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/labs');
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
// has correct page title
|
|
|
|
expect(document.title, 'page title').to.equal('Settings - Labs - Test Blog');
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
// highlights nav menu
|
2022-09-08 11:18:46 +03:00
|
|
|
expect(find('[data-test-nav="settings"]'), 'highlights nav menu item')
|
2019-01-02 12:58:55 +03:00
|
|
|
.to.have.class('active');
|
2022-09-08 11:18:46 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can delete all content', async function () {
|
|
|
|
await visit('/settings/labs');
|
|
|
|
await click('[data-test-button="delete-all"]');
|
|
|
|
|
|
|
|
const modal = '[data-test-modal="confirm-delete-all"]';
|
|
|
|
expect(find(modal)).to.exist;
|
|
|
|
|
|
|
|
await click(`${modal} [data-test-button="confirm"]`);
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2022-09-08 11:18:46 +03:00
|
|
|
// API request is correct
|
|
|
|
const [lastRequest] = this.server.pretender.handledRequests.slice(-1);
|
|
|
|
expect(lastRequest.url).to.equal('/ghost/api/admin/db/');
|
|
|
|
expect(lastRequest.method).to.equal('DELETE');
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2022-09-08 11:18:46 +03:00
|
|
|
expect(find(modal)).to.not.exist;
|
2016-02-11 18:19:04 +03:00
|
|
|
});
|
2017-09-21 18:01:40 +03:00
|
|
|
|
|
|
|
it('can upload/download redirects', async function () {
|
|
|
|
await visit('/settings/labs');
|
|
|
|
|
|
|
|
// successful upload
|
2021-02-22 03:27:00 +03:00
|
|
|
this.server.post('/redirects/upload/', {}, 200);
|
2017-09-21 18:01:40 +03:00
|
|
|
|
|
|
|
await fileUpload(
|
2019-01-02 12:58:55 +03:00
|
|
|
'[data-test-file-input="redirects"] input',
|
2017-09-21 18:01:40 +03:00
|
|
|
['test'],
|
|
|
|
{name: 'redirects.json', type: 'application/json'}
|
|
|
|
);
|
|
|
|
|
|
|
|
// TODO: tests for the temporary success/failure state have been
|
|
|
|
// disabled because they were randomly failing
|
|
|
|
|
|
|
|
// this should be half-way through button reset timeout
|
|
|
|
// await timeout(50);
|
|
|
|
//
|
|
|
|
// // shows success button
|
2019-01-02 12:58:55 +03:00
|
|
|
// let buttons = findAll('[data-test-button="upload-redirects"]');
|
|
|
|
// expect(buttons.length, 'no of success buttons').to.equal(1);
|
2017-09-21 18:01:40 +03:00
|
|
|
// expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
// buttons[0],
|
2017-09-21 18:01:40 +03:00
|
|
|
// 'success button is green'
|
2019-01-02 12:58:55 +03:00
|
|
|
// ).to.have.class('gh-btn-green);
|
2017-09-21 18:01:40 +03:00
|
|
|
// expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
// button.textContent,
|
2017-09-21 18:01:40 +03:00
|
|
|
// 'success button text'
|
|
|
|
// ).to.have.string('Uploaded');
|
|
|
|
//
|
|
|
|
// await wait();
|
|
|
|
|
|
|
|
// returned to normal button
|
2019-01-02 12:58:55 +03:00
|
|
|
let buttons = findAll('[data-test-button="upload-redirects"]');
|
|
|
|
expect(buttons.length, 'no of post-success buttons').to.equal(1);
|
2017-09-21 18:01:40 +03:00
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
buttons[0],
|
2017-09-21 18:01:40 +03:00
|
|
|
'post-success button doesn\'t have success class'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.not.have.class('gh-btn-green');
|
2017-09-21 18:01:40 +03:00
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
buttons[0].textContent,
|
2017-09-21 18:01:40 +03:00
|
|
|
'post-success button text'
|
|
|
|
).to.have.string('Upload redirects');
|
|
|
|
|
|
|
|
// failed upload
|
2021-02-22 03:27:00 +03:00
|
|
|
this.server.post('/redirects/upload/', {
|
2017-09-21 18:01:40 +03:00
|
|
|
errors: [{
|
2019-03-25 14:29:14 +03:00
|
|
|
type: 'BadRequestError',
|
2017-09-21 18:01:40 +03:00
|
|
|
message: 'Test failure message'
|
|
|
|
}]
|
|
|
|
}, 400);
|
|
|
|
|
|
|
|
await fileUpload(
|
2019-01-02 12:58:55 +03:00
|
|
|
'[data-test-file-input="redirects"] input',
|
2017-09-21 18:01:40 +03:00
|
|
|
['test'],
|
|
|
|
{name: 'redirects-bad.json', type: 'application/json'}
|
|
|
|
);
|
|
|
|
|
|
|
|
// TODO: tests for the temporary success/failure state have been
|
|
|
|
// disabled because they were randomly failing
|
|
|
|
|
|
|
|
// this should be half-way through button reset timeout
|
|
|
|
// await timeout(50);
|
|
|
|
//
|
|
|
|
// shows failure button
|
2019-01-02 12:58:55 +03:00
|
|
|
// buttons = findAll('[data-test-button="upload-redirects"]');
|
|
|
|
// expect(buttons.length, 'no of failure buttons').to.equal(1);
|
2017-09-21 18:01:40 +03:00
|
|
|
// expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
// buttons[0],
|
2017-09-21 18:01:40 +03:00
|
|
|
// 'failure button is red'
|
2019-01-02 12:58:55 +03:00
|
|
|
// ).to.have.class('gh-btn-red);
|
2017-09-21 18:01:40 +03:00
|
|
|
// expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
// buttons[0].textContent,
|
2017-09-21 18:01:40 +03:00
|
|
|
// 'failure button text'
|
|
|
|
// ).to.have.string('Upload Failed');
|
|
|
|
//
|
|
|
|
// await wait();
|
|
|
|
|
|
|
|
// shows error message
|
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
find('[data-test-error="redirects"]').textContent.trim(),
|
2017-09-21 18:01:40 +03:00
|
|
|
'upload error text'
|
|
|
|
).to.have.string('Test failure message');
|
|
|
|
|
|
|
|
// returned to normal button
|
2019-01-02 12:58:55 +03:00
|
|
|
buttons = findAll('[data-test-button="upload-redirects"]');
|
|
|
|
expect(buttons.length, 'no of post-failure buttons').to.equal(1);
|
2017-09-21 18:01:40 +03:00
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
buttons[0],
|
2017-09-21 18:01:40 +03:00
|
|
|
'post-failure button doesn\'t have failure class'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.not.have.class('gh-btn-red');
|
2017-09-21 18:01:40 +03:00
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
buttons[0].textContent,
|
2017-09-21 18:01:40 +03:00
|
|
|
'post-failure button text'
|
|
|
|
).to.have.string('Upload redirects');
|
|
|
|
|
|
|
|
// successful upload clears error
|
2021-02-22 03:27:00 +03:00
|
|
|
this.server.post('/redirects/upload/', {}, 200);
|
2017-09-21 18:01:40 +03:00
|
|
|
await fileUpload(
|
2019-01-02 12:58:55 +03:00
|
|
|
'[data-test-file-input="redirects"] input',
|
2017-09-21 18:01:40 +03:00
|
|
|
['test'],
|
|
|
|
{name: 'redirects-bad.json', type: 'application/json'}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(find('[data-test-error="redirects"]')).to.not.exist;
|
|
|
|
|
|
|
|
// can download redirects.json
|
|
|
|
await click('[data-test-link="download-redirects"]');
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
let iframe = document.querySelector('#iframeDownload');
|
2021-02-22 03:27:00 +03:00
|
|
|
expect(iframe.getAttribute('src')).to.have.string('/redirects/download/');
|
2017-09-21 18:01:40 +03:00
|
|
|
});
|
2018-07-24 14:20:53 +03:00
|
|
|
|
|
|
|
it('can upload/download routes.yaml', async function () {
|
|
|
|
await visit('/settings/labs');
|
|
|
|
|
|
|
|
// successful upload
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.post('/settings/routes/yaml/', {}, 200);
|
2018-07-24 14:20:53 +03:00
|
|
|
|
|
|
|
await fileUpload(
|
2019-01-02 12:58:55 +03:00
|
|
|
'[data-test-file-input="routes"] input',
|
2018-07-24 14:20:53 +03:00
|
|
|
['test'],
|
|
|
|
{name: 'routes.yaml', type: 'application/x-yaml'}
|
|
|
|
);
|
|
|
|
|
|
|
|
// TODO: tests for the temporary success/failure state have been
|
|
|
|
// disabled because they were randomly failing
|
|
|
|
|
|
|
|
// this should be half-way through button reset timeout
|
|
|
|
// await timeout(50);
|
|
|
|
//
|
|
|
|
// // shows success button
|
|
|
|
// let button = find('[data-test-button="upload-routes"]');
|
|
|
|
// expect(button.length, 'no of success buttons').to.equal(1);
|
|
|
|
// expect(
|
|
|
|
// button.hasClass('gh-btn-green'),
|
|
|
|
// 'success button is green'
|
|
|
|
// ).to.be.true;
|
|
|
|
// expect(
|
|
|
|
// button.text().trim(),
|
|
|
|
// 'success button text'
|
|
|
|
// ).to.have.string('Uploaded');
|
|
|
|
//
|
|
|
|
// await wait();
|
|
|
|
|
|
|
|
// returned to normal button
|
2019-01-02 12:58:55 +03:00
|
|
|
let buttons = findAll('[data-test-button="upload-routes"]');
|
|
|
|
expect(buttons.length, 'no of post-success buttons').to.equal(1);
|
2018-07-24 14:20:53 +03:00
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
buttons[0],
|
2018-07-24 14:20:53 +03:00
|
|
|
'routes post-success button doesn\'t have success class'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.not.have.class('gh-btn-green');
|
2018-07-24 14:20:53 +03:00
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
buttons[0].textContent,
|
2018-07-24 14:20:53 +03:00
|
|
|
'routes post-success button text'
|
|
|
|
).to.have.string('Upload routes YAML');
|
|
|
|
|
|
|
|
// failed upload
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.post('/settings/routes/yaml/', {
|
2018-07-24 14:20:53 +03:00
|
|
|
errors: [{
|
2019-03-25 14:29:14 +03:00
|
|
|
type: 'BadRequestError',
|
2018-07-24 14:20:53 +03:00
|
|
|
message: 'Test failure message'
|
|
|
|
}]
|
|
|
|
}, 400);
|
|
|
|
|
|
|
|
await fileUpload(
|
2019-01-02 12:58:55 +03:00
|
|
|
'[data-test-file-input="routes"] input',
|
2018-07-24 14:20:53 +03:00
|
|
|
['test'],
|
|
|
|
{name: 'routes-bad.yaml', type: 'application/x-yaml'}
|
|
|
|
);
|
|
|
|
|
|
|
|
// TODO: tests for the temporary success/failure state have been
|
|
|
|
// disabled because they were randomly failing
|
|
|
|
|
|
|
|
// this should be half-way through button reset timeout
|
|
|
|
// await timeout(50);
|
|
|
|
//
|
|
|
|
// shows failure button
|
|
|
|
// button = find('[data-test-button="upload-routes"]');
|
|
|
|
// expect(button.length, 'no of failure buttons').to.equal(1);
|
|
|
|
// expect(
|
|
|
|
// button.hasClass('gh-btn-red'),
|
|
|
|
// 'failure button is red'
|
|
|
|
// ).to.be.true;
|
|
|
|
// expect(
|
|
|
|
// button.text().trim(),
|
|
|
|
// 'failure button text'
|
|
|
|
// ).to.have.string('Upload Failed');
|
|
|
|
//
|
|
|
|
// await wait();
|
|
|
|
|
|
|
|
// shows error message
|
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
find('[data-test-error="routes"]').textContent,
|
2018-07-24 14:20:53 +03:00
|
|
|
'routes upload error text'
|
|
|
|
).to.have.string('Test failure message');
|
|
|
|
|
|
|
|
// returned to normal button
|
2019-01-02 12:58:55 +03:00
|
|
|
buttons = findAll('[data-test-button="upload-routes"]');
|
|
|
|
expect(buttons.length, 'no of post-failure buttons').to.equal(1);
|
2018-07-24 14:20:53 +03:00
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
buttons[0],
|
2018-07-24 14:20:53 +03:00
|
|
|
'routes post-failure button doesn\'t have failure class'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.not.have.class('gh-btn-red');
|
2018-07-24 14:20:53 +03:00
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
buttons[0].textContent,
|
2018-07-24 14:20:53 +03:00
|
|
|
'routes post-failure button text'
|
|
|
|
).to.have.string('Upload routes YAML');
|
|
|
|
|
|
|
|
// successful upload clears error
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.post('/settings/routes/yaml/', {}, 200);
|
2018-07-24 14:20:53 +03:00
|
|
|
await fileUpload(
|
2019-01-02 12:58:55 +03:00
|
|
|
'[data-test-file-input="routes"] input',
|
2018-07-24 14:20:53 +03:00
|
|
|
['test'],
|
|
|
|
{name: 'routes-good.yaml', type: 'application/x-yaml'}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(find('[data-test-error="routes"]')).to.not.exist;
|
|
|
|
|
|
|
|
// can download redirects.json
|
|
|
|
await click('[data-test-link="download-routes"]');
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
let iframe = document.querySelector('#iframeDownload');
|
|
|
|
expect(iframe.getAttribute('src')).to.have.string('/settings/routes/yaml/');
|
2018-07-24 14:20:53 +03:00
|
|
|
});
|
2016-02-11 18:19:04 +03:00
|
|
|
});
|
2020-07-16 12:13:36 +03:00
|
|
|
|
|
|
|
describe('When logged in as Owner', function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
let role = this.server.create('role', {name: 'Owner'});
|
|
|
|
this.server.create('user', {roles: [role]});
|
|
|
|
|
|
|
|
return await authenticateSession();
|
|
|
|
});
|
|
|
|
|
2021-01-28 18:25:21 +03:00
|
|
|
it.skip('sets the mailgunBaseUrl to the default', async function () {
|
2021-01-22 11:59:30 +03:00
|
|
|
await visit('/settings/members');
|
2020-07-16 12:13:36 +03:00
|
|
|
|
|
|
|
await fillIn('[data-test-mailgun-api-key-input]', 'i_am_an_api_key');
|
|
|
|
await fillIn('[data-test-mailgun-domain-input]', 'https://domain.tld');
|
|
|
|
|
|
|
|
await click('[data-test-button="save-members-settings"]');
|
|
|
|
|
|
|
|
let [lastRequest] = this.server.pretender.handledRequests.slice(-1);
|
|
|
|
let params = JSON.parse(lastRequest.requestBody);
|
|
|
|
|
|
|
|
expect(params.settings.findBy('key', 'mailgun_base_url').value).not.to.equal(null);
|
|
|
|
});
|
|
|
|
});
|
2016-02-11 18:19:04 +03:00
|
|
|
});
|