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

source_editor_webide_ext_spec.js « editor « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f418eab668afb754aafe6325f671d861ade946f7 (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
51
52
53
54
55
import { Emitter } from 'monaco-editor';
import { setHTMLFixture } from 'helpers/fixtures';
import { EditorWebIdeExtension } from '~/editor/extensions/source_editor_webide_ext';
import SourceEditor from '~/editor/source_editor';

describe('Source Editor Web IDE Extension', () => {
  let editorEl;
  let editor;
  let instance;

  beforeEach(() => {
    setHTMLFixture('<div id="editor" data-editor-loading></div>');
    editorEl = document.getElementById('editor');
    editor = new SourceEditor();
  });
  afterEach(() => {});

  describe('onSetup', () => {
    it.each`
      width      | renderSideBySide
      ${'0'}     | ${false}
      ${'699px'} | ${false}
      ${'700px'} | ${true}
    `(
      "correctly renders the Diff Editor when the parent element's width is $width",
      ({ width, renderSideBySide }) => {
        editorEl.style.width = width;
        instance = editor.createDiffInstance({ el: editorEl });

        const sideBySideSpy = jest.spyOn(instance, 'updateOptions');
        instance.use({ definition: EditorWebIdeExtension });

        expect(sideBySideSpy).toHaveBeenCalledWith({ renderSideBySide });
      },
    );

    it('re-renders the Diff Editor when layout of the modified editor is changed', async () => {
      const emitter = new Emitter();
      editorEl.style.width = '700px';

      instance = editor.createDiffInstance({ el: editorEl });
      instance.getModifiedEditor().onDidLayoutChange = emitter.event;
      instance.use({ definition: EditorWebIdeExtension });

      const sideBySideSpy = jest.spyOn(instance, 'updateOptions');
      await emitter.fire();

      expect(sideBySideSpy).toHaveBeenCalledWith({ renderSideBySide: true });

      editorEl.style.width = '0px';
      await emitter.fire();
      expect(sideBySideSpy).toHaveBeenCalledWith({ renderSideBySide: false });
    });
  });
});