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
|
import { getByRole } from '@testing-library/dom';
import { mount } from '@vue/test-utils';
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
import PipelineConfigReferenceCard from '~/pipeline_editor/components/drawer/cards/pipeline_config_reference_card.vue';
import { pipelineEditorTrackingOptions } from '~/pipeline_editor/constants';
describe('Pipeline config reference card', () => {
let wrapper;
let trackingSpy;
const defaultProvide = {
ciExamplesHelpPagePath: 'help/ci/examples/',
ciHelpPagePath: 'help/ci/introduction',
needsHelpPagePath: 'help/ci/yaml#needs',
ymlHelpPagePath: 'help/ci/yaml',
};
const createComponent = () => {
wrapper = mount(PipelineConfigReferenceCard, {
provide: {
...defaultProvide,
},
});
};
const getLinkByName = (name) => getByRole(wrapper.element, 'link', { name });
const findCiExamplesLink = () => getLinkByName(/CI\/CD examples and templates/i);
const findCiIntroLink = () => getLinkByName(/GitLab CI\/CD concepts/i);
const findNeedsLink = () => getLinkByName(/Needs keyword/i);
const findYmlSyntaxLink = () => getLinkByName(/.gitlab-ci.yml syntax reference/i);
beforeEach(() => {
createComponent();
});
afterEach(() => {
wrapper.destroy();
});
it('renders the title', () => {
expect(wrapper.text()).toContain(wrapper.vm.$options.i18n.title);
});
it('renders the content', () => {
expect(wrapper.text()).toContain(wrapper.vm.$options.i18n.firstParagraph);
});
it('renders the links', () => {
expect(findCiExamplesLink().href).toContain(defaultProvide.ciExamplesHelpPagePath);
expect(findCiIntroLink().href).toContain(defaultProvide.ciHelpPagePath);
expect(findNeedsLink().href).toContain(defaultProvide.needsHelpPagePath);
expect(findYmlSyntaxLink().href).toContain(defaultProvide.ymlHelpPagePath);
});
describe('tracking', () => {
beforeEach(() => {
createComponent();
trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
});
afterEach(() => {
unmockTracking();
});
const testTracker = async (element, expectedAction) => {
const { label } = pipelineEditorTrackingOptions;
await element.click();
expect(trackingSpy).toHaveBeenCalledWith(undefined, expectedAction, {
label,
});
};
it('tracks help page links', async () => {
const {
CI_EXAMPLES_LINK,
CI_HELP_LINK,
CI_NEEDS_LINK,
CI_YAML_LINK,
} = pipelineEditorTrackingOptions.actions.helpDrawerLinks;
testTracker(findCiExamplesLink(), CI_EXAMPLES_LINK);
testTracker(findCiIntroLink(), CI_HELP_LINK);
testTracker(findNeedsLink(), CI_NEEDS_LINK);
testTracker(findYmlSyntaxLink(), CI_YAML_LINK);
});
});
});
|