2020-10-14 14:08:47 -04:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2020-07-01 14:08:50 -04:00
|
|
|
import EditBlob from '~/blob_edit/edit_blob';
|
|
|
|
import EditorLite from '~/editor/editor_lite';
|
|
|
|
import MarkdownExtension from '~/editor/editor_markdown_ext';
|
2020-08-31 14:10:43 -04:00
|
|
|
import FileTemplateExtension from '~/editor/editor_file_template_ext';
|
2020-07-01 14:08:50 -04:00
|
|
|
|
|
|
|
jest.mock('~/editor/editor_lite');
|
|
|
|
jest.mock('~/editor/editor_markdown_ext');
|
|
|
|
|
|
|
|
describe('Blob Editing', () => {
|
2020-10-14 14:08:47 -04:00
|
|
|
const useMock = jest.fn();
|
|
|
|
const mockInstance = {
|
|
|
|
use: useMock,
|
|
|
|
getValue: jest.fn(),
|
|
|
|
focus: jest.fn(),
|
|
|
|
};
|
2020-07-01 14:08:50 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures(
|
2020-08-31 14:10:43 -04:00
|
|
|
`<div class="js-edit-blob-form"><div id="file_path"></div><div id="editor"></div><input id="file-content"></div>`,
|
2020-07-01 14:08:50 -04:00
|
|
|
);
|
2020-08-31 14:10:43 -04:00
|
|
|
jest.spyOn(EditorLite.prototype, 'createInstance').mockReturnValue(mockInstance);
|
2020-07-01 14:08:50 -04:00
|
|
|
});
|
|
|
|
|
2020-10-14 14:08:47 -04:00
|
|
|
const editorInst = isMarkdown => {
|
2020-07-01 14:08:50 -04:00
|
|
|
return new EditBlob({
|
|
|
|
isMarkdown,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-10-14 14:08:47 -04:00
|
|
|
const initEditor = async (isMarkdown = false) => {
|
|
|
|
editorInst(isMarkdown);
|
|
|
|
await waitForPromises();
|
|
|
|
};
|
|
|
|
|
2020-08-31 14:10:43 -04:00
|
|
|
it('loads FileTemplateExtension by default', async () => {
|
2020-07-01 14:08:50 -04:00
|
|
|
await initEditor();
|
2020-10-14 14:08:47 -04:00
|
|
|
expect(useMock).toHaveBeenCalledWith(FileTemplateExtension);
|
2020-07-01 14:08:50 -04:00
|
|
|
});
|
|
|
|
|
2020-08-31 14:10:43 -04:00
|
|
|
describe('Markdown', () => {
|
|
|
|
it('does not load MarkdownExtension by default', async () => {
|
|
|
|
await initEditor();
|
2020-10-14 14:08:47 -04:00
|
|
|
expect(useMock).not.toHaveBeenCalledWith(MarkdownExtension);
|
2020-08-31 14:10:43 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('loads MarkdownExtension only for the markdown files', async () => {
|
|
|
|
await initEditor(true);
|
2020-10-14 14:08:47 -04:00
|
|
|
expect(useMock).toHaveBeenCalledTimes(2);
|
|
|
|
expect(useMock).toHaveBeenNthCalledWith(1, FileTemplateExtension);
|
|
|
|
expect(useMock).toHaveBeenNthCalledWith(2, MarkdownExtension);
|
2020-08-31 14:10:43 -04:00
|
|
|
});
|
2020-07-01 14:08:50 -04:00
|
|
|
});
|
|
|
|
});
|