Welcome to mirror list, hosted at ThFree Co, Russian Federation.

edit_blob_spec.js « blob_edit « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8f92e8498b93e85fa040c3c5b8514e13c797d67a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import EditBlob from '~/blob_edit/edit_blob';
import EditorLite from '~/editor/editor_lite';
import MarkdownExtension from '~/editor/editor_markdown_ext';
import FileTemplateExtension from '~/editor/editor_file_template_ext';

jest.mock('~/editor/editor_lite');
jest.mock('~/editor/editor_markdown_ext');

describe('Blob Editing', () => {
  const mockInstance = 'foo';
  beforeEach(() => {
    setFixtures(
      `<div class="js-edit-blob-form"><div id="file_path"></div><div id="editor"></div><input id="file-content"></div>`,
    );
    jest.spyOn(EditorLite.prototype, 'createInstance').mockReturnValue(mockInstance);
  });

  const initEditor = (isMarkdown = false) => {
    return new EditBlob({
      isMarkdown,
      monacoEnabled: true,
    });
  };

  it('loads FileTemplateExtension by default', async () => {
    await initEditor();
    expect(EditorLite.prototype.use).toHaveBeenCalledWith(
      expect.arrayContaining([FileTemplateExtension]),
      mockInstance,
    );
  });

  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,
      );
    });
  });
});