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

pipeline_wizard_spec.js « pipeline_wizard « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3f689ffdbc88232a08fbe194fbbc4b132e61b739 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { parseDocument } from 'yaml';
import PipelineWizard from '~/pipeline_wizard/pipeline_wizard.vue';
import PipelineWizardWrapper from '~/pipeline_wizard/components/wrapper.vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import {
  fullTemplate as template,
  fullTemplateWithoutFilename as templateWithoutFilename,
} from './mock/yaml';

const projectPath = 'foo/bar';
const defaultBranch = 'main';

describe('PipelineWizard', () => {
  let wrapper;

  const createComponent = (props = {}) => {
    wrapper = shallowMountExtended(PipelineWizard, {
      propsData: {
        projectPath,
        defaultBranch,
        template,
        ...props,
      },
    });
  };

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

  it('mounts without error', () => {
    const consoleSpy = jest.spyOn(console, 'error');

    createComponent();

    expect(consoleSpy).not.toHaveBeenCalled();
    expect(wrapper.exists()).toBe(true);
  });

  it('mounts the wizard wrapper', () => {
    createComponent();

    expect(wrapper.findComponent(PipelineWizardWrapper).exists()).toBe(true);
  });

  it('passes the correct steps prop to the wizard wrapper', () => {
    createComponent();

    expect(wrapper.findComponent(PipelineWizardWrapper).props('steps')).toEqual(
      parseDocument(template).get('steps'),
    );
  });

  it('passes all other expected props to the wizard wrapper', () => {
    createComponent();

    expect(wrapper.findComponent(PipelineWizardWrapper).props()).toEqual(
      expect.objectContaining({
        defaultBranch,
        projectPath,
        filename: parseDocument(template).get('filename'),
      }),
    );
  });

  it('passes ".gitlab-ci.yml" as default filename to the wizard wrapper', () => {
    createComponent({ template: templateWithoutFilename });

    expect(wrapper.findComponent(PipelineWizardWrapper).attributes('filename')).toBe(
      '.gitlab-ci.yml',
    );
  });

  it('allows overriding the defaultFilename with `defaultFilename` prop', () => {
    const defaultFilename = 'foobar.yml';

    createComponent({
      template: templateWithoutFilename,
      defaultFilename,
    });

    expect(wrapper.findComponent(PipelineWizardWrapper).attributes('filename')).toBe(
      defaultFilename,
    );
  });

  it('displays the title', () => {
    createComponent();

    expect(wrapper.findByTestId('title').text()).toBe(
      parseDocument(template).get('title').toString(),
    );
  });

  it('displays the description', () => {
    createComponent();

    expect(wrapper.findByTestId('description').text()).toBe(
      parseDocument(template).get('description').toString(),
    );
  });

  it('bubbles the done event upwards', () => {
    createComponent();

    wrapper.findComponent(PipelineWizardWrapper).vm.$emit('done');

    expect(wrapper.emitted().done.length).toBe(1);
  });
});