2022-08-23 13:45:50 +03:00
|
|
|
import loginAsRole from '../../helpers/login-as-role';
|
2022-09-13 20:55:28 +03:00
|
|
|
import {BLANK_DOC} from 'koenig-editor/components/koenig-editor';
|
2022-08-23 13:45:50 +03:00
|
|
|
import {currentURL} from '@ember/test-helpers';
|
|
|
|
import {expect} from 'chai';
|
|
|
|
import {setupApplicationTest} from 'ember-mocha';
|
|
|
|
import {setupMirage} from 'ember-cli-mirage/test-support';
|
|
|
|
import {visit} from '../../helpers/visit';
|
|
|
|
|
|
|
|
describe('Acceptance: Lexical editor', function () {
|
|
|
|
let hooks = setupApplicationTest();
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
|
|
|
beforeEach(async function () {
|
|
|
|
this.server.loadFixtures();
|
2022-09-13 20:55:28 +03:00
|
|
|
|
|
|
|
// ensure required config is in place for external lexical editor to load
|
|
|
|
const config = this.server.schema.configs.find(1);
|
|
|
|
config.attrs.editor = {url: 'https://cdn.pkg/editor.js'};
|
|
|
|
config.save();
|
|
|
|
|
|
|
|
// stub loaded external module to avoid loading of external dep
|
|
|
|
window['@tryghost/koenig-lexical'] = {
|
|
|
|
KoenigComposer: () => null,
|
|
|
|
KoenigEditor: () => null
|
|
|
|
};
|
2022-08-23 13:45:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects to signin when not authenticated', async function () {
|
|
|
|
await visit('/lexical-editor/post/');
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/signin');
|
|
|
|
});
|
|
|
|
|
2022-09-13 13:45:49 +03:00
|
|
|
it('redirects to posts screen if editor.url config is missing', async function () {
|
2022-09-13 20:55:28 +03:00
|
|
|
const config = this.server.schema.configs.find(1);
|
|
|
|
config.attrs.editor = undefined;
|
|
|
|
config.save();
|
|
|
|
|
2022-08-23 13:45:50 +03:00
|
|
|
await loginAsRole('Administrator', this.server);
|
|
|
|
await visit('/lexical-editor/post/');
|
|
|
|
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/posts');
|
|
|
|
});
|
|
|
|
|
2022-09-13 13:45:49 +03:00
|
|
|
it('loads when editor.url is present', async function () {
|
2022-08-23 13:45:50 +03:00
|
|
|
await loginAsRole('Administrator', this.server);
|
|
|
|
await visit('/lexical-editor/post/');
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/lexical-editor/post/');
|
|
|
|
});
|
2022-09-13 20:55:28 +03:00
|
|
|
|
|
|
|
it('redirects mobiledoc editor to lexical editor when post.lexical is present', async function () {
|
|
|
|
const post = this.server.create('post', {
|
|
|
|
lexical: JSON.stringify({})
|
|
|
|
});
|
|
|
|
|
|
|
|
await loginAsRole('Administrator', this.server);
|
|
|
|
await visit(`/editor/post/${post.id}`);
|
|
|
|
|
|
|
|
expect(currentURL()).to.equal(`/lexical-editor/post/${post.id}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects lexical editor to mobiledoc editor when post.mobiledoc is present', async function () {
|
|
|
|
const post = this.server.create('post', {
|
|
|
|
mobiledoc: JSON.stringify(BLANK_DOC)
|
|
|
|
});
|
|
|
|
|
|
|
|
await loginAsRole('Administrator', this.server);
|
|
|
|
await visit(`/lexical-editor/post/${post.id}`);
|
|
|
|
|
|
|
|
expect(currentURL()).to.equal(`/editor/post/${post.id}`);
|
|
|
|
});
|
2022-08-23 13:45:50 +03:00
|
|
|
});
|