2020-10-30 21:08:52 +00:00
|
|
|
import { nextTick } from 'vue';
|
2020-11-03 15:09:05 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import { GlAlert, GlLoadingIcon, GlTabs, GlTab } from '@gitlab/ui';
|
2020-10-30 12:08:44 +00:00
|
|
|
|
2020-10-30 21:08:52 +00:00
|
|
|
import { mockProjectPath, mockDefaultBranch, mockCiConfigPath, mockCiYml } from './mock_data';
|
|
|
|
import TextEditor from '~/pipeline_editor/components/text_editor.vue';
|
|
|
|
import EditorLite from '~/vue_shared/components/editor_lite.vue';
|
2020-11-03 15:09:05 +00:00
|
|
|
import PipelineGraph from '~/pipelines/components/pipeline_graph/pipeline_graph.vue';
|
2020-10-30 12:08:44 +00:00
|
|
|
import PipelineEditorApp from '~/pipeline_editor/pipeline_editor_app.vue';
|
|
|
|
|
|
|
|
describe('~/pipeline_editor/pipeline_editor_app.vue', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2020-11-03 15:09:05 +00:00
|
|
|
const createComponent = (
|
|
|
|
{ props = {}, data = {}, loading = false } = {},
|
|
|
|
mountFn = shallowMount,
|
|
|
|
) => {
|
2020-10-30 21:08:52 +00:00
|
|
|
wrapper = mountFn(PipelineEditorApp, {
|
|
|
|
propsData: {
|
|
|
|
projectPath: mockProjectPath,
|
|
|
|
defaultBranch: mockDefaultBranch,
|
|
|
|
ciConfigPath: mockCiConfigPath,
|
|
|
|
...props,
|
|
|
|
},
|
2020-11-03 15:09:05 +00:00
|
|
|
data() {
|
|
|
|
return data;
|
|
|
|
},
|
2020-10-30 21:08:52 +00:00
|
|
|
stubs: {
|
2020-11-03 15:09:05 +00:00
|
|
|
GlTabs,
|
2020-10-30 21:08:52 +00:00
|
|
|
TextEditor,
|
|
|
|
},
|
|
|
|
mocks: {
|
|
|
|
$apollo: {
|
|
|
|
queries: {
|
|
|
|
content: {
|
|
|
|
loading,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2020-10-30 12:08:44 +00:00
|
|
|
};
|
|
|
|
|
2020-10-30 21:08:52 +00:00
|
|
|
const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
|
|
|
|
const findAlert = () => wrapper.find(GlAlert);
|
2020-11-03 15:09:05 +00:00
|
|
|
const findTabAt = i => wrapper.findAll(GlTab).at(i);
|
|
|
|
const findEditorLite = () => wrapper.find(EditorLite);
|
2020-10-30 12:08:44 +00:00
|
|
|
|
2020-11-03 15:09:05 +00:00
|
|
|
beforeEach(() => {
|
2020-10-30 12:08:44 +00:00
|
|
|
createComponent();
|
2020-11-03 15:09:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays content', () => {
|
|
|
|
createComponent({ data: { content: mockCiYml } });
|
2020-10-30 12:08:44 +00:00
|
|
|
|
2020-10-30 21:08:52 +00:00
|
|
|
expect(findLoadingIcon().exists()).toBe(false);
|
2020-11-03 15:09:05 +00:00
|
|
|
expect(findEditorLite().props('value')).toBe(mockCiYml);
|
2020-10-30 12:08:44 +00:00
|
|
|
});
|
|
|
|
|
2020-11-03 15:09:05 +00:00
|
|
|
it('displays a loading icon if the query is loading', () => {
|
2020-10-30 21:08:52 +00:00
|
|
|
createComponent({ loading: true });
|
2020-10-30 12:08:44 +00:00
|
|
|
|
2020-10-30 21:08:52 +00:00
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-11-03 15:09:05 +00:00
|
|
|
describe('tabs', () => {
|
|
|
|
it('displays tabs and their content', () => {
|
|
|
|
createComponent({ data: { content: mockCiYml } });
|
|
|
|
|
|
|
|
expect(
|
|
|
|
findTabAt(0)
|
|
|
|
.find(EditorLite)
|
|
|
|
.exists(),
|
|
|
|
).toBe(true);
|
|
|
|
expect(
|
|
|
|
findTabAt(1)
|
|
|
|
.find(PipelineGraph)
|
|
|
|
.exists(),
|
|
|
|
).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays editor tab lazily, until editor is ready', async () => {
|
|
|
|
createComponent({ data: { content: mockCiYml } });
|
|
|
|
|
|
|
|
expect(findTabAt(0).attributes('lazy')).toBe('true');
|
|
|
|
|
|
|
|
findEditorLite().vm.$emit('editor-ready');
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(findTabAt(0).attributes('lazy')).toBe(undefined);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-30 21:08:52 +00:00
|
|
|
describe('when in error state', () => {
|
|
|
|
class MockError extends Error {
|
|
|
|
constructor(message, data) {
|
|
|
|
super(message);
|
|
|
|
if (data) {
|
|
|
|
this.networkError = {
|
|
|
|
response: { data },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:09:05 +00:00
|
|
|
it('shows a generic error', () => {
|
|
|
|
const error = new MockError('An error message');
|
|
|
|
createComponent({ data: { error } });
|
2020-10-30 21:08:52 +00:00
|
|
|
|
|
|
|
expect(findAlert().text()).toBe('CI file could not be loaded: An error message');
|
|
|
|
});
|
|
|
|
|
2020-11-03 15:09:05 +00:00
|
|
|
it('shows a ref missing error state', () => {
|
2020-10-30 21:08:52 +00:00
|
|
|
const error = new MockError('Ref missing!', {
|
|
|
|
error: 'ref is missing, ref is empty',
|
|
|
|
});
|
2020-11-03 15:09:05 +00:00
|
|
|
createComponent({ data: { error } });
|
2020-10-30 21:08:52 +00:00
|
|
|
|
|
|
|
expect(findAlert().text()).toMatch(
|
|
|
|
'CI file could not be loaded: ref is missing, ref is empty',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows a file missing error state', async () => {
|
|
|
|
const error = new MockError('File missing!', {
|
|
|
|
message: 'file not found',
|
|
|
|
});
|
|
|
|
|
2020-11-03 15:09:05 +00:00
|
|
|
await wrapper.setData({ error });
|
2020-10-30 21:08:52 +00:00
|
|
|
|
|
|
|
expect(findAlert().text()).toMatch('CI file could not be loaded: file not found');
|
|
|
|
});
|
2020-10-30 12:08:44 +00:00
|
|
|
});
|
|
|
|
});
|