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

source_editor_extension_spec.js « editor « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6f2eb07a043900e40c55cc6f30ce41a07a165dbd (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
56
57
58
59
60
61
62
63
64
65
import EditorExtension from '~/editor/source_editor_extension';
import { EDITOR_EXTENSION_DEFINITION_ERROR } from '~/editor/constants';
import * as helpers from './helpers';

describe('Editor Extension', () => {
  const dummyObj = { foo: 'bar' };

  it.each`
    definition   | setupOptions
    ${undefined} | ${undefined}
    ${undefined} | ${{}}
    ${undefined} | ${dummyObj}
    ${{}}        | ${dummyObj}
    ${dummyObj}  | ${dummyObj}
  `(
    'throws when definition = $definition and setupOptions = $setupOptions',
    ({ definition, setupOptions }) => {
      const constructExtension = () => new EditorExtension({ definition, setupOptions });
      expect(constructExtension).toThrowError(EDITOR_EXTENSION_DEFINITION_ERROR);
    },
  );

  it.each`
    definition                  | setupOptions | expectedName
    ${helpers.MyClassExtension} | ${undefined} | ${'MyClassExtension'}
    ${helpers.MyClassExtension} | ${{}}        | ${'MyClassExtension'}
    ${helpers.MyClassExtension} | ${dummyObj}  | ${'MyClassExtension'}
    ${helpers.MyFnExtension}    | ${undefined} | ${'MyFnExtension'}
    ${helpers.MyFnExtension}    | ${{}}        | ${'MyFnExtension'}
    ${helpers.MyFnExtension}    | ${dummyObj}  | ${'MyFnExtension'}
    ${helpers.MyConstExt}       | ${undefined} | ${'MyConstExt'}
    ${helpers.MyConstExt}       | ${{}}        | ${'MyConstExt'}
    ${helpers.MyConstExt}       | ${dummyObj}  | ${'MyConstExt'}
  `(
    'correctly creates extension for definition = $definition and setupOptions = $setupOptions',
    ({ definition, setupOptions, expectedName }) => {
      const extension = new EditorExtension({ definition, setupOptions });
      // eslint-disable-next-line new-cap
      const constructedDefinition = new definition();

      expect(extension).toEqual(
        expect.objectContaining({
          name: expectedName,
          setupOptions,
        }),
      );
      expect(extension.obj.constructor.prototype).toBe(constructedDefinition.constructor.prototype);
    },
  );

  describe('api', () => {
    it.each`
      definition                  | expectedKeys
      ${helpers.MyClassExtension} | ${['shared', 'classExtMethod']}
      ${helpers.MyFnExtension}    | ${['fnExtMethod']}
      ${helpers.MyConstExt}       | ${['constExtMethod']}
    `('correctly returns API for $definition', ({ definition, expectedKeys }) => {
      const extension = new EditorExtension({ definition });
      const expectedApi = Object.fromEntries(
        expectedKeys.map((key) => [key, expect.any(Function)]),
      );
      expect(extension.api).toEqual(expect.objectContaining(expectedApi));
    });
  });
});