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
|
import { GlAlert, GlModal } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import { nextTick } from 'vue';
import waitForPromises from 'helpers/wait_for_promises';
import CanaryUpdateModal from '~/environments/components/canary_update_modal.vue';
import updateCanaryIngress from '~/environments/graphql/mutations/update_canary_ingress.mutation.graphql';
describe('/environments/components/canary_update_modal.vue', () => {
let wrapper;
let modal;
let mutate;
const findAlert = () => wrapper.find(GlAlert);
const createComponent = () => {
mutate = jest.fn().mockResolvedValue();
wrapper = mount(CanaryUpdateModal, {
propsData: {
environment: {
name: 'staging',
global_id: 'gid://environments/staging',
},
weight: 60,
visible: true,
},
mocks: {
$apollo: { mutate },
},
});
modal = wrapper.find(GlModal);
};
afterEach(() => {
if (wrapper) {
wrapper.destroy();
}
wrapper = null;
});
beforeEach(() => {
createComponent();
});
it('should bind the modal props', () => {
expect(modal.props()).toMatchObject({
modalId: 'confirm-canary-change',
actionPrimary: {
text: 'Change ratio',
attributes: [{ variant: 'info' }],
},
actionCancel: { text: 'Cancel' },
});
});
it('should display the new weights', () => {
expect(modal.text()).toContain('Stable: 40');
expect(modal.text()).toContain('Canary: 60');
});
it('should display the affected environment', () => {
expect(modal.text()).toContain(
'You are changing the ratio of the canary rollout for staging compared to the stable deployment to:',
);
});
it('should update the weight on primary action', () => {
modal.vm.$emit('primary');
expect(mutate).toHaveBeenCalledWith({
mutation: updateCanaryIngress,
variables: {
input: {
id: 'gid://environments/staging',
weight: 60,
},
},
});
});
it('should do nothing on cancel', () => {
modal.vm.$emit('secondary');
expect(mutate).not.toHaveBeenCalled();
});
it('should not display an error if there was not one', async () => {
mutate.mockResolvedValue({ data: { environmentsCanaryIngressUpdate: { errors: [] } } });
modal.vm.$emit('primary');
await nextTick();
expect(findAlert().exists()).toBe(false);
});
it('should display an error if there was one', async () => {
mutate.mockResolvedValue({ data: { environmentsCanaryIngressUpdate: { errors: ['error'] } } });
modal.vm.$emit('primary');
await nextTick();
expect(findAlert().text()).toBe('error');
});
it('should display a generic error if there was a top-level one', async () => {
mutate.mockRejectedValue();
modal.vm.$emit('primary');
await waitForPromises();
await nextTick();
expect(findAlert().text()).toBe('Something went wrong. Please try again later');
});
it('hides teh alert on dismiss', async () => {
mutate.mockResolvedValue({ data: { environmentsCanaryIngressUpdate: { errors: ['error'] } } });
modal.vm.$emit('primary');
await nextTick();
const alert = findAlert();
alert.vm.$emit('dismiss');
await nextTick();
expect(alert.exists()).toBe(false);
});
});
|