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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
import { nextTick } from 'vue';
import { GlFormCheckbox, GlFormRadioGroup } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import PushEvents from '~/webhooks/components/push_events.vue';
describe('Webhook push events form editor component', () => {
let wrapper;
const findPushEventsCheckBox = (w = wrapper) => w.findComponent(GlFormCheckbox);
const findPushEventsIndicator = (w = wrapper) => w.find('input[name="hook[push_events]"]');
const findPushEventRulesGroup = (w = wrapper) => w.findComponent(GlFormRadioGroup);
const getPushEventsRuleValue = (w = wrapper) => findPushEventRulesGroup(w).vm.$attrs.checked;
const findWildcardRuleInput = (w = wrapper) => w.findByTestId('webhook_branch_filter_field');
const findRegexRuleInput = (w = wrapper) => w.findByTestId('webhook_branch_filter_field');
const createComponent = (provides) =>
shallowMountExtended(PushEvents, {
provide: {
isNewHook: true,
pushEvents: false,
strategy: 'wildcard',
pushEventsBranchFilter: '',
...provides,
},
});
describe('Renders push events checkbox', () => {
it('when it is a new hook', async () => {
wrapper = createComponent({
isNewHook: true,
});
await nextTick();
const checkbox = findPushEventsCheckBox();
expect(checkbox.exists()).toBe(true);
expect(findPushEventRulesGroup().exists()).toBe(false);
expect(findPushEventsIndicator().attributes('value')).toBe('false');
});
it('when it is not a new hook and push events is enabled', async () => {
wrapper = createComponent({
isNewHook: false,
pushEvents: true,
});
await nextTick();
expect(findPushEventsCheckBox().exists()).toBe(true);
expect(findPushEventRulesGroup().exists()).toBe(true);
expect(findPushEventsIndicator().attributes('value')).toBe('true');
});
});
describe('Different push events rules', () => {
describe('when editing new hook', () => {
beforeEach(async () => {
wrapper = createComponent({
isNewHook: true,
});
await nextTick();
await findPushEventsCheckBox().vm.$emit('input', true);
await nextTick();
});
it('all_branches should be selected by default', async () => {
expect(findPushEventRulesGroup().element).toMatchSnapshot();
});
it('should be able to set wildcard rule', async () => {
expect(getPushEventsRuleValue()).toBe('all_branches');
expect(findWildcardRuleInput().exists()).toBe(false);
expect(findRegexRuleInput().exists()).toBe(false);
await findPushEventRulesGroup(wrapper).vm.$emit('input', 'wildcard');
expect(findWildcardRuleInput().exists()).toBe(true);
expect(findPushEventRulesGroup().element).toMatchSnapshot();
const testVal = 'test-val';
findWildcardRuleInput().vm.$emit('input', testVal);
await nextTick();
expect(findWildcardRuleInput().attributes('value')).toBe(testVal);
});
it('should be able to set regex rule', async () => {
expect(getPushEventsRuleValue()).toBe('all_branches');
expect(findRegexRuleInput().exists()).toBe(false);
expect(findWildcardRuleInput().exists()).toBe(false);
await findPushEventRulesGroup(wrapper).vm.$emit('input', 'regex');
expect(findRegexRuleInput().exists()).toBe(true);
expect(findPushEventRulesGroup().element).toMatchSnapshot();
const testVal = 'test-val';
findRegexRuleInput().vm.$emit('input', testVal);
await nextTick();
expect(findRegexRuleInput().attributes('value')).toBe(testVal);
});
});
describe('when editing existing hook', () => {
it.each(['all_branches', 'wildcard', 'regex'])(
'with "%s" strategy selected',
async (strategy) => {
wrapper = createComponent({
isNewHook: false,
pushEvents: true,
pushEventsBranchFilter: 'foo',
strategy,
});
await nextTick();
expect(findPushEventsIndicator().attributes('value')).toBe('true');
expect(findPushEventRulesGroup().element).toMatchSnapshot();
},
);
});
});
});
|