2022-03-08 14:32:01 +03:00
|
|
|
import {Response} from 'miragejs';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {authenticateSession} from 'ember-simple-auth/test-support';
|
|
|
|
import {beforeEach, describe, it} from 'mocha';
|
2022-05-16 16:15:02 +03:00
|
|
|
import {blur, 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 {setupApplicationTest} from 'ember-mocha';
|
2019-05-27 11:37:05 +03:00
|
|
|
import {setupMirage} from 'ember-cli-mirage/test-support';
|
2017-08-10 13:59:53 +03:00
|
|
|
import {versionMismatchResponse} from 'ghost-admin/mirage/utils';
|
|
|
|
|
|
|
|
let htmlErrorResponse = function () {
|
2022-03-08 14:32:01 +03:00
|
|
|
return new Response(
|
2017-08-10 13:59:53 +03:00
|
|
|
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');
|
2022-10-07 15:27:57 +03:00
|
|
|
await click('.posts-list li:nth-of-type(1) a'); // select first draft post (otherwise no automatic saving on blur)
|
2022-05-16 16:15:02 +03:00
|
|
|
await fillIn('[data-test-editor-title-input]', 'Updated post');
|
|
|
|
await blur('[data-test-editor-title-input]');
|
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-06-18 13:47:21 +03:00
|
|
|
expect(currentRouteName()).to.equal('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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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');
|
2022-11-01 17:11:41 +03:00
|
|
|
await click('[data-test-button="sign-in"]');
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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');
|
2022-05-16 16:15:02 +03:00
|
|
|
await fillIn('[data-test-editor-title-input]', 'Updated post');
|
|
|
|
await blur('[data-test-editor-title-input]');
|
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
|
|
|
|
2021-11-10 15:45:26 +03:00
|
|
|
await visit('/settings/design/change-theme');
|
|
|
|
|
|
|
|
await click('[data-test-button="toggle-advanced"]');
|
|
|
|
await click('[data-test-theme-id="foo"] [data-test-button="actions"]');
|
|
|
|
await click('[data-test-actions-for="foo"] [data-test-button="delete"]');
|
|
|
|
await click('[data-test-modal="delete-theme"] [data-test-button="confirm"]');
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|