2016-06-30 13:21:47 +03:00
|
|
|
import $ from 'jquery';
|
2016-02-11 18:19:04 +03:00
|
|
|
import destroyApp from '../../helpers/destroy-app';
|
2017-05-29 21:50:03 +03:00
|
|
|
import startApp from '../../helpers/start-app';
|
2017-09-21 18:01:40 +03:00
|
|
|
// import wait from 'ember-test-helpers/wait';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {afterEach, beforeEach, describe, it} from 'mocha';
|
|
|
|
import {authenticateSession, invalidateSession} from 'ghost-admin/tests/helpers/ember-simple-auth';
|
|
|
|
import {expect} from 'chai';
|
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 () {
|
2016-02-11 18:19:04 +03:00
|
|
|
let application;
|
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
beforeEach(function () {
|
2016-02-11 18:19:04 +03:00
|
|
|
application = startApp();
|
|
|
|
});
|
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
afterEach(function () {
|
2016-02-11 18:19:04 +03:00
|
|
|
destroyApp(application);
|
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('redirects to signin when not authenticated', async function () {
|
2016-02-11 18:19:04 +03:00
|
|
|
invalidateSession(application);
|
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
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
await visit('/settings/labs');
|
|
|
|
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/team/test-user');
|
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('redirects to team page when authenticated as author', async function () {
|
2016-02-11 18:19:04 +03:00
|
|
|
let role = server.create('role', {name: 'Author'});
|
2016-11-14 16:16:51 +03:00
|
|
|
server.create('user', {roles: [role], slug: 'test-user'});
|
2016-02-11 18:19:04 +03:00
|
|
|
|
|
|
|
authenticateSession(application);
|
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('/team/test-user');
|
2016-02-11 18:19:04 +03:00
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('redirects to team page when authenticated as editor', async function () {
|
2016-02-11 18:19:04 +03:00
|
|
|
let role = server.create('role', {name: 'Editor'});
|
2016-11-14 16:16:51 +03:00
|
|
|
server.create('user', {roles: [role], slug: 'test-user'});
|
2016-02-11 18:19:04 +03:00
|
|
|
|
|
|
|
authenticateSession(application);
|
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('/team');
|
2016-02-11 18:19:04 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when logged in', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
let role = server.create('role', {name: 'Administrator'});
|
2016-11-14 16:16:51 +03:00
|
|
|
server.create('user', {roles: [role]});
|
2016-02-11 18:19:04 +03:00
|
|
|
|
|
|
|
return authenticateSession(application);
|
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it.skip('it renders, loads modals correctly', async function () {
|
|
|
|
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
|
|
|
|
expect($('.gh-nav-settings-labs').hasClass('active'), 'highlights nav menu item')
|
|
|
|
.to.be.true;
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
await click('#settings-resetdb .js-delete');
|
|
|
|
expect(find('.fullscreen-modal .modal-content').length, 'modal element').to.equal(1);
|
2016-02-11 18:19:04 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
await click('.fullscreen-modal .modal-footer .gh-btn');
|
|
|
|
expect(find('.fullscreen-modal').length, 'modal element').to.equal(0);
|
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
|
|
|
|
server.post('/redirects/json/', {}, 200);
|
|
|
|
|
|
|
|
await fileUpload(
|
|
|
|
'[data-test-file-input="redirects"]',
|
|
|
|
['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
|
|
|
|
// let button = find('[data-test-button="upload-redirects"]');
|
|
|
|
// 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
|
|
|
|
let button = find('[data-test-button="upload-redirects"]');
|
|
|
|
expect(button.length, 'no of post-success buttons').to.equal(1);
|
|
|
|
expect(
|
|
|
|
button.hasClass('gh-btn-green'),
|
|
|
|
'post-success button doesn\'t have success class'
|
|
|
|
).to.be.false;
|
|
|
|
expect(
|
|
|
|
button.text().trim(),
|
|
|
|
'post-success button text'
|
|
|
|
).to.have.string('Upload redirects');
|
|
|
|
|
|
|
|
// failed upload
|
|
|
|
server.post('/redirects/json/', {
|
|
|
|
errors: [{
|
|
|
|
errorType: 'BadRequestError',
|
|
|
|
message: 'Test failure message'
|
|
|
|
}]
|
|
|
|
}, 400);
|
|
|
|
|
|
|
|
await fileUpload(
|
|
|
|
'[data-test-file-input="redirects"]',
|
|
|
|
['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
|
|
|
|
// button = find('[data-test-button="upload-redirects"]');
|
|
|
|
// 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(
|
|
|
|
find('[data-test-error="redirects"]').text().trim(),
|
|
|
|
'upload error text'
|
|
|
|
).to.have.string('Test failure message');
|
|
|
|
|
|
|
|
// returned to normal button
|
|
|
|
button = find('[data-test-button="upload-redirects"]');
|
|
|
|
expect(button.length, 'no of post-failure buttons').to.equal(1);
|
|
|
|
expect(
|
|
|
|
button.hasClass('gh-btn-red'),
|
|
|
|
'post-failure button doesn\'t have failure class'
|
|
|
|
).to.be.false;
|
|
|
|
expect(
|
|
|
|
button.text().trim(),
|
|
|
|
'post-failure button text'
|
|
|
|
).to.have.string('Upload redirects');
|
|
|
|
|
|
|
|
// successful upload clears error
|
|
|
|
server.post('/redirects/json/', {}, 200);
|
|
|
|
await fileUpload(
|
|
|
|
'[data-test-file-input="redirects"]',
|
|
|
|
['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"]');
|
|
|
|
|
|
|
|
let iframe = $('#iframeDownload');
|
|
|
|
expect(iframe.attr('src')).to.have.string('/redirects/json/');
|
|
|
|
});
|
2016-02-11 18:19:04 +03:00
|
|
|
});
|
|
|
|
});
|