2017-08-10 13:59:53 +03:00
|
|
|
import Mirage from 'ember-cli-mirage';
|
2019-01-02 12:58:55 +03:00
|
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
|
|
|
import {authenticateSession} from 'ember-simple-auth/test-support';
|
|
|
|
import {beforeEach, describe, it} from 'mocha';
|
|
|
|
import {click, currentRouteName, fillIn, find, findAll, visit} from '@ember/test-helpers';
|
2017-08-10 13:59:53 +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';
|
2017-08-10 13:59:53 +03:00
|
|
|
import {versionMismatchResponse} from 'ghost-admin/mirage/utils';
|
|
|
|
|
|
|
|
let htmlErrorResponse = function () {
|
|
|
|
return new Mirage.Response(
|
|
|
|
504,
|
|
|
|
{'Content-Type': 'text/html'},
|
|
|
|
'<!DOCTYPE html><head><title>Server Error</title></head><body>504 Gateway Timeout</body></html>'
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
describe('Acceptance: Error Handling', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let hooks = setupApplicationTest();
|
|
|
|
setupMirage(hooks);
|
2017-08-10 13:59:53 +03:00
|
|
|
|
|
|
|
describe('VersionMismatch errors', function () {
|
|
|
|
describe('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-10 13:59:53 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
return await authenticateSession();
|
2017-08-10 13:59:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays an alert and disables navigation when saving', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.createList('post', 3);
|
2017-08-10 13:59:53 +03:00
|
|
|
|
|
|
|
// mock the post save endpoint to return version mismatch
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.put('/posts/:id', versionMismatchResponse);
|
2017-08-10 13:59:53 +03:00
|
|
|
|
2019-03-21 12:33:14 +03:00
|
|
|
await visit('/posts');
|
2017-08-10 13:59:53 +03:00
|
|
|
await click('.posts-list li:nth-of-type(2) a'); // select second post
|
2017-08-11 18:28:05 +03:00
|
|
|
await click('[data-test-publishmenu-trigger]');
|
|
|
|
await click('[data-test-publishmenu-save]'); // "Save post"
|
2017-08-10 13:59:53 +03:00
|
|
|
|
|
|
|
// has the refresh to update alert
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('.gh-alert').length).to.equal(1);
|
|
|
|
expect(find('.gh-alert').textContent).to.match(/refresh/);
|
2017-08-10 13:59:53 +03:00
|
|
|
|
|
|
|
// try navigating back to the content list
|
2019-02-22 06:17:33 +03:00
|
|
|
await click('[data-test-link="posts"]');
|
2017-08-10 13:59:53 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(currentRouteName()).to.equal('editor.edit');
|
2017-08-10 13:59:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays alert and aborts the transition when navigating', async function () {
|
2019-03-21 12:33:14 +03:00
|
|
|
await visit('/posts');
|
2017-08-10 13:59:53 +03:00
|
|
|
|
|
|
|
// mock the tags endpoint to return version mismatch
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.get('/tags/', versionMismatchResponse);
|
2017-08-10 13:59:53 +03:00
|
|
|
|
2018-10-23 20:11:48 +03:00
|
|
|
await click('[data-test-nav="tags"]');
|
2017-08-10 13:59:53 +03:00
|
|
|
|
|
|
|
// navigation is blocked on loading screen
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(currentRouteName()).to.equal('settings.tags_loading');
|
2017-08-10 13:59:53 +03:00
|
|
|
|
|
|
|
// has the refresh to update alert
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('.gh-alert').length).to.equal(1);
|
|
|
|
expect(find('.gh-alert').textContent).to.match(/refresh/);
|
2017-08-10 13:59:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays alert and aborts the transition when an ember-ajax error is thrown whilst navigating', async function () {
|
2019-02-26 08:37:50 +03:00
|
|
|
this.server.get('/settings/', versionMismatchResponse);
|
2017-08-10 13:59:53 +03:00
|
|
|
|
|
|
|
await visit('/settings/tags');
|
2018-10-23 20:11:48 +03:00
|
|
|
await click('[data-test-nav="settings"]');
|
2017-08-10 13:59:53 +03:00
|
|
|
|
|
|
|
// navigation is blocked
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(currentRouteName()).to.equal('settings.general_loading');
|
2017-08-10 13:59:53 +03:00
|
|
|
|
|
|
|
// has the refresh to update alert
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('.gh-alert').length).to.equal(1);
|
|
|
|
expect(find('.gh-alert').textContent).to.match(/refresh/);
|
2017-08-10 13:59:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can be triggered when passed in to a component', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.post('/subscribers/csv/', versionMismatchResponse);
|
2017-08-10 13:59:53 +03:00
|
|
|
|
|
|
|
await visit('/subscribers');
|
2018-10-23 20:11:48 +03:00
|
|
|
await click('[data-test-link="import-csv"]');
|
2017-08-10 13:59:53 +03:00
|
|
|
await fileUpload('.fullscreen-modal input[type="file"]', ['test'], {name: 'test.csv'});
|
|
|
|
|
|
|
|
// alert is shown
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('.gh-alert').length).to.equal(1);
|
|
|
|
expect(find('.gh-alert').textContent).to.match(/refresh/);
|
2017-08-10 13:59:53 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('logged out', function () {
|
|
|
|
it('displays alert', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.post('/session', versionMismatchResponse);
|
2017-08-10 13:59:53 +03:00
|
|
|
|
|
|
|
await visit('/signin');
|
|
|
|
await fillIn('[name="identification"]', 'test@example.com');
|
|
|
|
await fillIn('[name="password"]', 'password');
|
|
|
|
await click('.gh-btn-blue');
|
|
|
|
|
|
|
|
// has the refresh to update alert
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('.gh-alert').length).to.equal(1);
|
|
|
|
expect(find('.gh-alert').textContent).to.match(/refresh/);
|
2017-08-10 13:59:53 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('CloudFlare errors', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
beforeEach(async function () {
|
|
|
|
this.server.loadFixtures();
|
2017-08-10 13:59:53 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
let roles = this.server.schema.roles.where({name: 'Administrator'});
|
|
|
|
this.server.create('user', {roles});
|
2017-08-10 13:59:53 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
return await authenticateSession();
|
2017-08-10 13:59:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('handles Ember Data HTML response', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.put('/posts/1/', htmlErrorResponse);
|
|
|
|
this.server.create('post');
|
2017-08-10 13:59:53 +03:00
|
|
|
|
2019-02-22 06:17:33 +03:00
|
|
|
await visit('/editor/post/1');
|
2017-08-11 18:28:05 +03:00
|
|
|
await click('[data-test-publishmenu-trigger]');
|
|
|
|
await click('[data-test-publishmenu-save]');
|
2017-08-10 13:59:53 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('.gh-alert').length).to.equal(1);
|
|
|
|
expect(find('.gh-alert').textContent).to.not.match(/html>/);
|
|
|
|
expect(find('.gh-alert').textContent).to.match(/Request was rejected due to server error/);
|
2017-08-10 13:59:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('handles ember-ajax HTML response', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.del('/themes/foo/', htmlErrorResponse);
|
2017-08-10 13:59:53 +03:00
|
|
|
|
|
|
|
await visit('/settings/design');
|
2017-08-11 18:28:05 +03:00
|
|
|
await click('[data-test-theme-id="foo"] [data-test-theme-delete-button]');
|
|
|
|
await click('.fullscreen-modal [data-test-delete-button]');
|
2017-08-10 13:59:53 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(findAll('.gh-alert').length).to.equal(1);
|
|
|
|
expect(find('.gh-alert').textContent).to.not.match(/html>/);
|
|
|
|
expect(find('.gh-alert').textContent).to.match(/Request was rejected due to server error/);
|
2017-08-10 13:59:53 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|