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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
import { nextTick } from 'vue';
import { shallowMount } from '@vue/test-utils';
import CiVariableSettings from '~/ci/ci_variable_list/components/ci_variable_settings.vue';
import ciVariableModal from '~/ci/ci_variable_list/components/ci_variable_modal.vue';
import ciVariableTable from '~/ci/ci_variable_list/components/ci_variable_table.vue';
import {
ADD_VARIABLE_ACTION,
EDIT_VARIABLE_ACTION,
projectString,
} from '~/ci/ci_variable_list/constants';
import { mapEnvironmentNames } from '~/ci/ci_variable_list/utils';
import { mockEnvs, mockVariablesWithScopes, newVariable } from '../mocks';
describe('Ci variable table', () => {
let wrapper;
const defaultProps = {
areScopedVariablesAvailable: true,
entity: 'project',
environments: mapEnvironmentNames(mockEnvs),
hideEnvironmentScope: false,
isLoading: false,
maxVariableLimit: 5,
pageInfo: { after: '' },
variables: mockVariablesWithScopes(projectString),
};
const findCiVariableTable = () => wrapper.findComponent(ciVariableTable);
const findCiVariableModal = () => wrapper.findComponent(ciVariableModal);
const createComponent = ({ props = {} } = {}) => {
wrapper = shallowMount(CiVariableSettings, {
propsData: {
...defaultProps,
...props,
},
});
};
describe('props passing', () => {
it('passes props down correctly to the ci table', () => {
createComponent();
expect(findCiVariableTable().props()).toEqual({
entity: 'project',
isLoading: defaultProps.isLoading,
maxVariableLimit: defaultProps.maxVariableLimit,
pageInfo: defaultProps.pageInfo,
variables: defaultProps.variables,
});
});
it('passes props down correctly to the ci modal', async () => {
createComponent();
findCiVariableTable().vm.$emit('set-selected-variable');
await nextTick();
expect(findCiVariableModal().props()).toEqual({
areScopedVariablesAvailable: defaultProps.areScopedVariablesAvailable,
environments: defaultProps.environments,
hideEnvironmentScope: defaultProps.hideEnvironmentScope,
variables: defaultProps.variables,
mode: ADD_VARIABLE_ACTION,
selectedVariable: {},
});
});
});
describe('modal mode', () => {
beforeEach(() => {
createComponent();
});
it('passes down ADD mode when receiving an empty variable', async () => {
findCiVariableTable().vm.$emit('set-selected-variable');
await nextTick();
expect(findCiVariableModal().props('mode')).toBe(ADD_VARIABLE_ACTION);
});
it('passes down EDIT mode when receiving a variable', async () => {
findCiVariableTable().vm.$emit('set-selected-variable', newVariable);
await nextTick();
expect(findCiVariableModal().props('mode')).toBe(EDIT_VARIABLE_ACTION);
});
});
describe('variable modal', () => {
beforeEach(() => {
createComponent();
});
it('is hidden by default', () => {
expect(findCiVariableModal().exists()).toBe(false);
});
it('shows modal when adding a new variable', async () => {
findCiVariableTable().vm.$emit('set-selected-variable');
await nextTick();
expect(findCiVariableModal().exists()).toBe(true);
});
it('shows modal when updating a variable', async () => {
findCiVariableTable().vm.$emit('set-selected-variable', newVariable);
await nextTick();
expect(findCiVariableModal().exists()).toBe(true);
});
it('hides modal when receiving the event from the modal', async () => {
findCiVariableTable().vm.$emit('set-selected-variable');
await nextTick();
findCiVariableModal().vm.$emit('hideModal');
await nextTick();
expect(findCiVariableModal().exists()).toBe(false);
});
});
describe('variable events', () => {
beforeEach(() => {
createComponent();
});
it.each`
eventName
${'add-variable'}
${'update-variable'}
${'delete-variable'}
`('bubbles up the $eventName event', async ({ eventName }) => {
findCiVariableTable().vm.$emit('set-selected-variable');
await nextTick();
findCiVariableModal().vm.$emit(eventName, newVariable);
await nextTick();
expect(wrapper.emitted(eventName)).toEqual([[newVariable]]);
});
});
describe('pages events', () => {
beforeEach(() => {
createComponent();
});
it.each`
eventName | args
${'handle-prev-page'} | ${undefined}
${'handle-next-page'} | ${undefined}
${'sort-changed'} | ${{ sortDesc: true }}
`('bubbles up the $eventName event', async ({ args, eventName }) => {
findCiVariableTable().vm.$emit(eventName, args);
await nextTick();
expect(wrapper.emitted(eventName)).toEqual([[args]]);
});
});
});
|