-
Notifications
You must be signed in to change notification settings - Fork 264
/
Probe.test.ts
74 lines (60 loc) · 2.57 KB
/
Probe.test.ts
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
import { mount } from '@vue/test-utils';
import Probe from '@shell/components/form/Probe.vue';
import { _EDIT } from '@shell/config/query-params';
import { ExtendedVue, Vue } from 'vue/types/vue';
import { DefaultProps } from 'vue/types/options';
describe('component: Probe', () => {
describe.each([
['HTTPS', ['port', 'path']],
['tcp', ['socket']],
['exec', ['command']],
])('given kind %p', (kind, extraFields) => {
it.each([
...extraFields,
'successThreshold',
'failureThreshold',
])('should emit an update on %p input', (field) => {
const wrapper = mount(Probe as unknown as ExtendedVue<Vue, {}, {}, {}, DefaultProps>, {
props: { mode: _EDIT },
data: () => ({ kind })
});
const input = wrapper.find(`[data-testid="input-probe-${ field }"]`).find('input');
const newValue = 123;
input.setValue(newValue);
expect(wrapper.emitted('input')).toHaveLength(1);
});
it.each([
'periodSeconds',
'initialDelaySeconds',
'timeoutSeconds',
])('should emit an update on %p input and blur', (field) => {
const wrapper = mount(Probe as unknown as ExtendedVue<Vue, {}, {}, {}, DefaultProps>, {
props: { mode: _EDIT },
data: () => ({ kind })
});
const input = wrapper.find(`[data-testid="input-probe-${ field }"]`).find('input');
const newValue = 123;
input.setValue(newValue);
input.trigger('blur');
expect(wrapper.emitted('input')).toHaveLength(1);
});
});
it.each([
'kind',
])('should emit an update on %p selection change', async(field) => {
const wrapper = mount(Probe as unknown as ExtendedVue<Vue, {}, {}, {}, DefaultProps>, { props: { mode: _EDIT } });
const select = wrapper.find(`[data-testid="input-probe-${ field }"]`);
select.find('button').trigger('click');
await wrapper.trigger('keydown.down');
await wrapper.trigger('keydown.enter');
expect(wrapper.emitted('update:value')).toHaveLength(2);
});
it('should emit an update when http headers are modified', () => {
const wrapper = mount(Probe as unknown as ExtendedVue<Vue, {}, {}, {}, DefaultProps>, { props: { mode: _EDIT, value: { httpGet: { scheme: 'https' } } } });
const httpHeaders = wrapper.getComponent('[data-testid="input-probe-http-headers"]');
httpHeaders.vm.$emit('update:value', [{ name: 'abc', value: 'def' }]);
expect(wrapper.emitted()?.['update:value']?.[0]?.[0]).toStrictEqual({
exec: null, httpGet: { httpHeaders: [{ name: 'abc', value: 'def' }], scheme: 'HTTPS' }, tcpSocket: null
});
});
});