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

snippet_edit_spec.js « snippet « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 42a55ac0d3e0b30b120f9c10fe595a29c519b1cb (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
import '~/snippet/snippet_edit';
import { triggerDOMEvent } from 'jest/helpers/dom_events_helper';
import { SnippetEditInit } from '~/snippets';
import initSnippet from '~/snippet/snippet_bundle';

jest.mock('~/snippet/snippet_bundle');
jest.mock('~/snippets');
jest.mock('~/gl_form');

describe('Snippet edit form initialization', () => {
  const setFF = flag => {
    gon.features = { snippetsEditVue: flag };
  };
  let features;

  beforeEach(() => {
    features = gon.features;
    setFixtures('<div class="snippet-form"></div>');
  });

  afterEach(() => {
    gon.features = features;
  });

  it.each`
    name         | flag     | isVue
    ${'Regular'} | ${false} | ${false}
    ${'Vue'}     | ${true}  | ${true}
  `('correctly initializes $name Snippet Edit form', ({ flag, isVue }) => {
    initSnippet.mockClear();
    SnippetEditInit.mockClear();

    setFF(flag);

    triggerDOMEvent('DOMContentLoaded');

    if (isVue) {
      expect(initSnippet).not.toHaveBeenCalled();
      expect(SnippetEditInit).toHaveBeenCalled();
    } else {
      expect(initSnippet).toHaveBeenCalled();
      expect(SnippetEditInit).not.toHaveBeenCalled();
    }
  });
});