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
|
import { shallowMount, mount } from '@vue/test-utils';
import { GlAlert, GlLink } from '@gitlab/ui';
import CiLint from '~/pipeline_editor/components/lint/ci_lint.vue';
import { CI_CONFIG_STATUS_INVALID } from '~/pipeline_editor/constants';
import { mergeUnwrappedCiConfig, mockLintHelpPagePath } from '../../mock_data';
describe('~/pipeline_editor/components/lint/ci_lint.vue', () => {
let wrapper;
const createComponent = (props = {}, mountFn = shallowMount) => {
wrapper = mountFn(CiLint, {
provide: {
lintHelpPagePath: mockLintHelpPagePath,
},
propsData: {
ciConfig: mergeUnwrappedCiConfig(),
...props,
},
});
};
const findAllByTestId = (selector) => wrapper.findAll(`[data-testid="${selector}"]`);
const findAlert = () => wrapper.find(GlAlert);
const findLintParameters = () => findAllByTestId('ci-lint-parameter');
const findLintParameterAt = (i) => findLintParameters().at(i);
const findLintValueAt = (i) => findAllByTestId('ci-lint-value').at(i);
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
describe('Valid Results', () => {
beforeEach(() => {
createComponent({}, mount);
});
it('displays valid results', () => {
expect(findAlert().text()).toMatch('Status: Syntax is correct.');
});
it('displays link to the right help page', () => {
expect(findAlert().find(GlLink).attributes('href')).toBe(mockLintHelpPagePath);
});
it('displays jobs', () => {
expect(findLintParameters()).toHaveLength(3);
expect(findLintParameterAt(0).text()).toBe('Test Job - job_test_1');
expect(findLintParameterAt(1).text()).toBe('Test Job - job_test_2');
expect(findLintParameterAt(2).text()).toBe('Build Job - job_build');
});
it('displays jobs details', () => {
expect(findLintParameters()).toHaveLength(3);
expect(findLintValueAt(0).text()).toMatchInterpolatedText(
'echo "test 1" Only policy: branches, tags When: on_success',
);
expect(findLintValueAt(1).text()).toMatchInterpolatedText(
'echo "test 2" Only policy: branches, tags When: on_success',
);
expect(findLintValueAt(2).text()).toMatchInterpolatedText(
'echo "build" Only policy: branches, tags When: on_success',
);
});
it('displays invalid results', () => {
createComponent(
{
ciConfig: mergeUnwrappedCiConfig({
status: CI_CONFIG_STATUS_INVALID,
}),
},
mount,
);
expect(findAlert().text()).toMatch('Status: Syntax is incorrect.');
});
});
});
|