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

input_wrapper_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: f288264a11ebebb6ec9569d0b3b9e9dc7e1f5f32 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { mount, shallowMount } from '@vue/test-utils';
import { Document } from 'yaml';
import InputWrapper from '~/pipeline_wizard/components/input_wrapper.vue';
import TextWidget from '~/pipeline_wizard/components/widgets/text.vue';

describe('Pipeline Wizard -- Input Wrapper', () => {
  let wrapper;

  const createComponent = (props = {}, mountFunc = mount) => {
    wrapper = 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,
      },
    });
  };

  describe('API', () => {
    const inputValue = 'dslkfjsdlkfjlskdjfn';
    let inputChild;

    beforeEach(() => {
      createComponent({});
      inputChild = wrapper.findComponent(TextWidget);
    });

    afterEach(() => {
      wrapper.destroy();
    });

    it('will replace its value in compiled', async () => {
      await inputChild.vm.$emit('input', inputValue);
      const expected = new Document({
        bar: 'baz',
        foo: { some: inputValue },
      });
      expect(wrapper.emitted()['update:compiled']).toEqual([[expected]]);
    });

    it('will emit a highlight event with the correct path if child emits an input event', async () => {
      await inputChild.vm.$emit('input', inputValue);
      const expected = ['foo', 'some'];
      expect(wrapper.emitted().highlight).toEqual([[expected]]);
    });
  });

  describe('Target Path Discovery', () => {
    afterEach(() => {
      wrapper.destroy();
    });

    it.each`
      scenario                  | template                             | target     | expected
      ${'simple nested object'} | ${{ foo: { bar: { baz: '$BOO' } } }} | ${'$BOO'}  | ${['foo', 'bar', 'baz']}
      ${'list, first pos.'}     | ${{ foo: ['$BOO'] }}                 | ${'$BOO'}  | ${['foo', 0]}
      ${'list, second pos.'}    | ${{ foo: ['bar', '$BOO'] }}          | ${'$BOO'}  | ${['foo', 1]}
      ${'lowercase target'}     | ${{ foo: { bar: '$jupp' } }}         | ${'$jupp'} | ${['foo', 'bar']}
      ${'root list'}            | ${['$BOO']}                          | ${'$BOO'}  | ${[0]}
    `('$scenario', ({ template, target, expected }) => {
      createComponent(
        {
          template: new Document({ template }).get('template'),
          target,
        },
        shallowMount,
      );
      expect(wrapper.vm.path).toEqual(expected);
    });
  });
});