2020-07-28 23:09:34 +05:30
|
|
|
import EditBlob from '~/blob_edit/edit_blob';
|
|
|
|
import EditorLite from '~/editor/editor_lite';
|
|
|
|
import MarkdownExtension from '~/editor/editor_markdown_ext';
|
2020-11-24 15:15:51 +05:30
|
|
|
import FileTemplateExtension from '~/editor/editor_file_template_ext';
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
jest.mock('~/editor/editor_lite');
|
|
|
|
jest.mock('~/editor/editor_markdown_ext');
|
|
|
|
|
|
|
|
describe('Blob Editing', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
const mockInstance = 'foo';
|
2020-07-28 23:09:34 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures(
|
2020-11-24 15:15:51 +05:30
|
|
|
`<div class="js-edit-blob-form"><div id="file_path"></div><div id="editor"></div><input id="file-content"></div>`,
|
2020-07-28 23:09:34 +05:30
|
|
|
);
|
2020-11-24 15:15:51 +05:30
|
|
|
jest.spyOn(EditorLite.prototype, 'createInstance').mockReturnValue(mockInstance);
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
const initEditor = (isMarkdown = false) => {
|
|
|
|
return new EditBlob({
|
|
|
|
isMarkdown,
|
|
|
|
monacoEnabled: true,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('loads FileTemplateExtension by default', async () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
await initEditor();
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(EditorLite.prototype.use).toHaveBeenCalledWith(
|
|
|
|
expect.arrayContaining([FileTemplateExtension]),
|
|
|
|
mockInstance,
|
|
|
|
);
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
describe('Markdown', () => {
|
|
|
|
it('does not load MarkdownExtension by default', async () => {
|
|
|
|
await initEditor();
|
|
|
|
expect(EditorLite.prototype.use).not.toHaveBeenCalledWith(
|
|
|
|
expect.arrayContaining([MarkdownExtension]),
|
|
|
|
mockInstance,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads MarkdownExtension only for the markdown files', async () => {
|
|
|
|
await initEditor(true);
|
|
|
|
expect(EditorLite.prototype.use).toHaveBeenCalledWith(
|
|
|
|
[MarkdownExtension, FileTemplateExtension],
|
|
|
|
mockInstance,
|
|
|
|
);
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
});
|