2021-03-11 19:13:27 +05:30
|
|
|
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';
|
2021-04-29 21:17:54 +05:30
|
|
|
import EditorTab from '~/pipeline_editor/components/ui/editor_tab.vue';
|
|
|
|
import {
|
|
|
|
EDITOR_APP_STATUS_EMPTY,
|
|
|
|
EDITOR_APP_STATUS_ERROR,
|
|
|
|
EDITOR_APP_STATUS_LOADING,
|
|
|
|
EDITOR_APP_STATUS_INVALID,
|
|
|
|
EDITOR_APP_STATUS_VALID,
|
|
|
|
} from '~/pipeline_editor/constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
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 />',
|
|
|
|
};
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
const createComponent = ({
|
|
|
|
props = {},
|
|
|
|
provide = {},
|
|
|
|
appStatus = EDITOR_APP_STATUS_VALID,
|
|
|
|
mountFn = shallowMount,
|
|
|
|
} = {}) => {
|
2021-03-11 19:13:27 +05:30
|
|
|
wrapper = mountFn(PipelineEditorTabs, {
|
|
|
|
propsData: {
|
|
|
|
ciConfigData: mockLintResponse,
|
|
|
|
ciFileContent: mockCiYml,
|
|
|
|
...props,
|
|
|
|
},
|
2021-04-29 21:17:54 +05:30
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
appStatus,
|
|
|
|
};
|
|
|
|
},
|
2021-06-08 01:23:25 +05:30
|
|
|
provide: { ...provide },
|
2021-03-11 19:13:27 +05:30
|
|
|
stubs: {
|
|
|
|
TextEditor: MockTextEditor,
|
2021-04-29 21:17:54 +05:30
|
|
|
EditorTab,
|
2021-03-11 19:13:27 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
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', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
describe('while loading', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ appStatus: EDITOR_APP_STATUS_LOADING });
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('displays a loading icon if the lint query is loading', () => {
|
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
|
|
|
expect(findPipelineGraph().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('after loading', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
beforeEach(() => {
|
2021-06-08 01:23:25 +05:30
|
|
|
createComponent();
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('display the tab and visualization', () => {
|
|
|
|
expect(findVisualizationTab().exists()).toBe(true);
|
|
|
|
expect(findPipelineGraph().exists()).toBe(true);
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('lint tab', () => {
|
|
|
|
describe('while loading', () => {
|
|
|
|
beforeEach(() => {
|
2021-04-29 21:17:54 +05:30
|
|
|
createComponent({ appStatus: EDITOR_APP_STATUS_LOADING });
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
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', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
describe('while loading', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ appStatus: EDITOR_APP_STATUS_LOADING });
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('displays a loading icon if the lint query is loading', () => {
|
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
describe('when there is a fetch error', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ appStatus: EDITOR_APP_STATUS_ERROR });
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('show an error message', () => {
|
|
|
|
expect(findAlert().exists()).toBe(true);
|
|
|
|
expect(findAlert().text()).toBe(wrapper.vm.$options.errorTexts.loadMergedYaml);
|
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('does not render the `merged_preview` component', () => {
|
|
|
|
expect(findMergedPreview().exists()).toBe(false);
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
});
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
describe('after loading', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
beforeEach(() => {
|
2021-06-08 01:23:25 +05:30
|
|
|
createComponent();
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('display the tab and the merged preview component', () => {
|
|
|
|
expect(findMergedTab().exists()).toBe(true);
|
|
|
|
expect(findMergedPreview().exists()).toBe(true);
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
describe('show tab content based on status', () => {
|
|
|
|
it.each`
|
|
|
|
appStatus | editor | viz | lint | merged
|
|
|
|
${undefined} | ${true} | ${true} | ${true} | ${true}
|
|
|
|
${EDITOR_APP_STATUS_EMPTY} | ${true} | ${false} | ${false} | ${false}
|
|
|
|
${EDITOR_APP_STATUS_INVALID} | ${true} | ${false} | ${true} | ${false}
|
|
|
|
${EDITOR_APP_STATUS_VALID} | ${true} | ${true} | ${true} | ${true}
|
|
|
|
`(
|
|
|
|
'when status is $appStatus, we show - editor:$editor | viz:$viz | lint:$lint | merged:$merged ',
|
|
|
|
({ appStatus, editor, viz, lint, merged }) => {
|
|
|
|
createComponent({ appStatus });
|
|
|
|
|
|
|
|
expect(findTextEditor().exists()).toBe(editor);
|
|
|
|
expect(findPipelineGraph().exists()).toBe(viz);
|
|
|
|
expect(findCiLint().exists()).toBe(lint);
|
|
|
|
expect(findMergedPreview().exists()).toBe(merged);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|