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

pipeline_editor_tabs_spec.js « components « pipeline_editor « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 24af17e9ce662f0734941a4c1276be835e7814f6 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import { GlAlert, GlLoadingIcon } from '@gitlab/ui';
import { shallowMount, mount } from '@vue/test-utils';
import { nextTick } from 'vue';
import CiConfigMergedPreview from '~/pipeline_editor/components/editor/ci_config_merged_preview.vue';
import CiLint from '~/pipeline_editor/components/lint/ci_lint.vue';
import PipelineEditorTabs from '~/pipeline_editor/components/pipeline_editor_tabs.vue';
import PipelineGraph from '~/pipelines/components/pipeline_graph/pipeline_graph.vue';

import { mockLintResponse, mockCiYml } from '../mock_data';

describe('Pipeline editor tabs component', () => {
  let wrapper;
  const MockTextEditor = {
    template: '<div />',
  };
  const mockProvide = {
    glFeatures: {
      ciConfigVisualizationTab: true,
      ciConfigMergedTab: true,
    },
  };

  const createComponent = ({ props = {}, provide = {}, mountFn = shallowMount } = {}) => {
    wrapper = mountFn(PipelineEditorTabs, {
      propsData: {
        ciConfigData: mockLintResponse,
        ciFileContent: mockCiYml,
        isCiConfigDataLoading: false,
        ...props,
      },
      provide: { ...mockProvide, ...provide },
      stubs: {
        TextEditor: MockTextEditor,
      },
    });
  };

  const findEditorTab = () => wrapper.find('[data-testid="editor-tab"]');
  const findLintTab = () => wrapper.find('[data-testid="lint-tab"]');
  const findMergedTab = () => wrapper.find('[data-testid="merged-tab"]');
  const findVisualizationTab = () => wrapper.find('[data-testid="visualization-tab"]');

  const findAlert = () => wrapper.findComponent(GlAlert);
  const findCiLint = () => wrapper.findComponent(CiLint);
  const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
  const findPipelineGraph = () => wrapper.findComponent(PipelineGraph);
  const findTextEditor = () => wrapper.findComponent(MockTextEditor);
  const findMergedPreview = () => wrapper.findComponent(CiConfigMergedPreview);

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

  describe('editor tab', () => {
    it('displays editor only after the tab is mounted', async () => {
      createComponent({ mountFn: mount });

      expect(findTextEditor().exists()).toBe(false);

      await nextTick();

      expect(findTextEditor().exists()).toBe(true);
      expect(findEditorTab().exists()).toBe(true);
    });
  });

  describe('visualization tab', () => {
    describe('with feature flag on', () => {
      describe('while loading', () => {
        beforeEach(() => {
          createComponent({ props: { isCiConfigDataLoading: true } });
        });

        it('displays a loading icon if the lint query is loading', () => {
          expect(findLoadingIcon().exists()).toBe(true);
          expect(findPipelineGraph().exists()).toBe(false);
        });
      });
      describe('after loading', () => {
        beforeEach(() => {
          createComponent();
        });

        it('display the tab and visualization', () => {
          expect(findVisualizationTab().exists()).toBe(true);
          expect(findPipelineGraph().exists()).toBe(true);
        });
      });
    });

    describe('with feature flag off', () => {
      beforeEach(() => {
        createComponent({
          provide: {
            glFeatures: { ciConfigVisualizationTab: false },
          },
        });
      });

      it('does not display the tab or component', () => {
        expect(findVisualizationTab().exists()).toBe(false);
        expect(findPipelineGraph().exists()).toBe(false);
      });
    });
  });

  describe('lint tab', () => {
    describe('while loading', () => {
      beforeEach(() => {
        createComponent({ props: { isCiConfigDataLoading: true } });
      });

      it('displays a loading icon if the lint query is loading', () => {
        expect(findLoadingIcon().exists()).toBe(true);
      });

      it('does not display the lint component', () => {
        expect(findCiLint().exists()).toBe(false);
      });
    });
    describe('after loading', () => {
      beforeEach(() => {
        createComponent();
      });

      it('display the tab and the lint component', () => {
        expect(findLintTab().exists()).toBe(true);
        expect(findCiLint().exists()).toBe(true);
      });
    });
  });

  describe('merged tab', () => {
    describe('with feature flag on', () => {
      describe('while loading', () => {
        beforeEach(() => {
          createComponent({ props: { isCiConfigDataLoading: true } });
        });

        it('displays a loading icon if the lint query is loading', () => {
          expect(findLoadingIcon().exists()).toBe(true);
        });
      });

      describe('when `mergedYaml` is undefined', () => {
        beforeEach(() => {
          createComponent({ props: { ciConfigData: {} } });
        });

        it('show an error message', () => {
          expect(findAlert().exists()).toBe(true);
          expect(findAlert().text()).toBe(wrapper.vm.$options.errorTexts.loadMergedYaml);
        });

        it('does not render the `meged_preview` component', () => {
          expect(findMergedPreview().exists()).toBe(false);
        });
      });

      describe('after loading', () => {
        beforeEach(() => {
          createComponent();
        });

        it('display the tab and the merged preview component', () => {
          expect(findMergedTab().exists()).toBe(true);
          expect(findMergedPreview().exists()).toBe(true);
        });
      });
    });
    describe('with feature flag off', () => {
      beforeEach(() => {
        createComponent({ provide: { glFeatures: { ciConfigMergedTab: false } } });
      });

      it('does not display the merged tab', () => {
        expect(findMergedTab().exists()).toBe(false);
        expect(findMergedPreview().exists()).toBe(false);
      });
    });
  });
});