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

widgets_spec.js « components « pipeline_wizard « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6bd858e746c44281ff091adc8c00e17743bab01e (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
import fs from 'fs';
import { mount } from '@vue/test-utils';
import { Document } from 'yaml';
import InputWrapper from '~/pipeline_wizard/components/input_wrapper.vue';

describe('Test all widgets in ./widgets/* whether they provide a minimal api', () => {
  const createComponent = (props = {}, mountFunc = mount) => {
    mountFunc(InputWrapper, {
      propsData: {
        template: new Document({
          template: {
            bar: 'baz',
            foo: { some: '$TARGET' },
          },
        }).get('template'),
        compiled: new Document({ bar: 'baz', foo: { some: '$TARGET' } }),
        target: '$TARGET',
        widget: 'text',
        label: 'some label (required by the text widget)',
        ...props,
      },
    });
  };

  const widgets = fs
    .readdirSync('./app/assets/javascripts/pipeline_wizard/components/widgets')
    .map((filename) => [filename.match(/^(.*).vue$/)[1]]);
  let consoleErrorSpy;

  beforeAll(() => {
    consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
  });

  afterAll(() => {
    consoleErrorSpy.mockRestore();
  });

  describe.each(widgets)('`%s` Widget', (name) => {
    it('passes the input validator', () => {
      const validatorFunc = InputWrapper.props.widget.validator;
      expect(validatorFunc(name)).toBe(true);
    });

    it('mounts without error', () => {
      createComponent({ widget: name });
      expect(consoleErrorSpy).not.toHaveBeenCalled();
    });
  });
});