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
|
import { shallowMount } from '@vue/test-utils';
import RefSelector from '~/ref/components/ref_selector.vue';
import RefsDropdown from '~/ci/pipeline_new/components/refs_dropdown.vue';
import { REF_TYPE_BRANCHES, REF_TYPE_TAGS } from '~/ref/constants';
const projectId = '8';
const refShortName = 'main';
const refFullName = 'refs/heads/main';
describe('Pipeline New Form', () => {
let wrapper;
const findRefSelector = () => wrapper.findComponent(RefSelector);
const createComponent = (props = {}) => {
wrapper = shallowMount(RefsDropdown, {
propsData: {
projectId,
value: {
shortName: refShortName,
fullName: refFullName,
},
...props,
},
});
};
describe('when user opens dropdown', () => {
beforeEach(() => {
createComponent();
});
it('has default selected branch', () => {
expect(findRefSelector().props('value')).toBe('main');
});
it('has ref selector for branches and tags', () => {
expect(findRefSelector().props('enabledRefTypes')).toEqual([
REF_TYPE_BRANCHES,
REF_TYPE_TAGS,
]);
});
describe('when user selects a value', () => {
const fullName = `refs/heads/conflict-contains-conflict-markers`;
it('component emits @input', () => {
findRefSelector().vm.$emit('input', fullName);
const inputs = wrapper.emitted('input');
expect(inputs).toHaveLength(1);
expect(inputs[0]).toEqual([
{
shortName: 'conflict-contains-conflict-markers',
fullName: 'refs/heads/conflict-contains-conflict-markers',
},
]);
});
});
});
describe('when user has selected a value', () => {
const mockShortName = 'conflict-contains-conflict-markers';
const mockFullName = `refs/heads/${mockShortName}`;
it('branch is checked', () => {
createComponent({
value: {
shortName: mockShortName,
fullName: mockFullName,
},
});
expect(findRefSelector().props('value')).toBe(mockShortName);
});
});
});
|