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
|
import { nextTick } from 'vue';
import { shallowMount } from '@vue/test-utils';
import CiVariableSettings from '~/ci_variable_list/components/ci_variable_settings.vue';
import ciVariableModal from '~/ci_variable_list/components/ci_variable_modal.vue';
import ciVariableTable from '~/ci_variable_list/components/ci_variable_table.vue';
import {
ADD_VARIABLE_ACTION,
EDIT_VARIABLE_ACTION,
projectString,
} from '~/ci_variable_list/constants';
import { mapEnvironmentNames } from '~/ci_variable_list/utils';
import { mockEnvs, mockVariablesWithScopes, newVariable } from '../mocks';
describe('Ci variable table', () => {
let wrapper;
const defaultProps = {
areScopedVariablesAvailable: true,
environments: mapEnvironmentNames(mockEnvs),
isLoading: false,
variables: mockVariablesWithScopes(projectString),
};
const findCiVariableTable = () => wrapper.findComponent(ciVariableTable);
const findCiVariableModal = () => wrapper.findComponent(ciVariableModal);
const createComponent = () => {
wrapper = shallowMount(CiVariableSettings, {
propsData: {
...defaultProps,
},
});
};
beforeEach(() => {
createComponent();
});
afterEach(() => {
wrapper.destroy();
});
describe('props passing', () => {
it('passes props down correctly to the ci table', () => {
expect(findCiVariableTable().props()).toEqual({
isLoading: defaultProps.isLoading,
variables: defaultProps.variables,
});
});
it('passes props down correctly to the ci modal', async () => {
findCiVariableTable().vm.$emit('set-selected-variable');
await nextTick();
expect(findCiVariableModal().props()).toEqual({
areScopedVariablesAvailable: defaultProps.areScopedVariablesAvailable,
environments: defaultProps.environments,
variables: defaultProps.variables,
mode: ADD_VARIABLE_ACTION,
selectedVariable: {},
});
});
});
describe('modal mode', () => {
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', () => {
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', () => {
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]]);
});
});
});
|