@rancher/shell 3.0.9-rc.6 → 3.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/components/IconOrSvg.vue +61 -42
  2. package/components/SortableTable/index.vue +2 -2
  3. package/components/form/BannerSettings.vue +2 -2
  4. package/components/form/NotificationSettings.vue +2 -2
  5. package/config/product/manager.js +0 -1
  6. package/detail/fleet.cattle.io.cluster.vue +1 -1
  7. package/dialog/FeatureFlagListDialog.vue +1 -1
  8. package/edit/catalog.cattle.io.clusterrepo.vue +1 -1
  9. package/edit/monitoring.coreos.com.alertmanagerconfig/__tests__/auth.spec.ts +145 -0
  10. package/edit/monitoring.coreos.com.alertmanagerconfig/__tests__/index.test.ts +202 -0
  11. package/edit/monitoring.coreos.com.alertmanagerconfig/__tests__/tls.spec.ts +226 -0
  12. package/edit/monitoring.coreos.com.alertmanagerconfig/auth.vue +24 -21
  13. package/edit/monitoring.coreos.com.alertmanagerconfig/types/__tests__/opsgenie.spec.ts +157 -0
  14. package/edit/monitoring.coreos.com.alertmanagerconfig/types/__tests__/pagerduty.spec.ts +132 -0
  15. package/edit/monitoring.coreos.com.alertmanagerconfig/types/__tests__/slack.spec.ts +108 -0
  16. package/edit/monitoring.coreos.com.alertmanagerconfig/types/pagerduty.vue +2 -1
  17. package/edit/monitoring.coreos.com.receiver/__tests__/auth.spec.ts +165 -0
  18. package/edit/monitoring.coreos.com.receiver/__tests__/index.test.ts +153 -0
  19. package/edit/monitoring.coreos.com.receiver/__tests__/tls.spec.ts +115 -0
  20. package/edit/monitoring.coreos.com.receiver/types/__tests__/email.spec.ts +86 -0
  21. package/edit/monitoring.coreos.com.receiver/types/__tests__/opsgenie.spec.ts +209 -0
  22. package/edit/monitoring.coreos.com.receiver/types/__tests__/pagerduty.spec.ts +105 -0
  23. package/edit/monitoring.coreos.com.receiver/types/__tests__/slack.spec.ts +92 -0
  24. package/edit/monitoring.coreos.com.receiver/types/__tests__/webhook.spec.ts +131 -0
  25. package/edit/provisioning.cattle.io.cluster/ingress/IngressCards.vue +14 -12
  26. package/edit/provisioning.cattle.io.cluster/rke2.vue +4 -5
  27. package/edit/provisioning.cattle.io.cluster/tabs/Basics.vue +18 -3
  28. package/edit/provisioning.cattle.io.cluster/tabs/Ingress.vue +100 -76
  29. package/list/provisioning.cattle.io.cluster.vue +2 -2
  30. package/models/__tests__/chart.test.ts +2 -2
  31. package/models/chart.js +3 -3
  32. package/package.json +1 -1
  33. package/pages/c/_cluster/apps/charts/AppChartCardFooter.vue +45 -18
  34. package/pages/c/_cluster/apps/charts/index.vue +1 -11
  35. package/pages/c/_cluster/explorer/tools/index.vue +1 -1
  36. package/pages/c/_cluster/manager/cloudCredential/index.vue +1 -1
  37. package/pages/c/_cluster/uiplugins/index.vue +1 -1
  38. package/rancher-components/RcItemCard/RcItemCard.vue +8 -1
  39. package/types/shell/index.d.ts +1 -0
  40. package/utils/svg-filter.js +4 -3
@@ -0,0 +1,108 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import Slack from '@shell/edit/monitoring.coreos.com.alertmanagerconfig/types/slack.vue';
3
+ import { Checkbox } from '@components/Form/Checkbox';
4
+ import { LabeledInput } from '@components/Form/LabeledInput';
5
+ import { _CREATE } from '@shell/config/query-params';
6
+
7
+ describe('component: Slack.vue', () => {
8
+ const defaultProps = {
9
+ mode: 'edit',
10
+ value: {},
11
+ namespace: 'test-namespace'
12
+ };
13
+
14
+ it('should render correctly with initial props', () => {
15
+ const wrapper = shallowMount(Slack, {
16
+ props: defaultProps,
17
+ global: { mocks: { $fetchState: { pending: false, error: null } } }
18
+ });
19
+
20
+ const headings = wrapper.findAll('h3');
21
+
22
+ expect(headings[0].text()).toBe('Target');
23
+
24
+ expect(wrapper.findComponent({ name: 'SimpleSecretSelector' }).exists()).toBe(true);
25
+ expect(wrapper.findAllComponents(LabeledInput)).toHaveLength(2);
26
+ expect(wrapper.findComponent(Checkbox).exists()).toBe(true);
27
+ });
28
+
29
+ it('should initialize text template in create mode', () => {
30
+ const wrapper = shallowMount(Slack, {
31
+ props: { ...defaultProps, mode: _CREATE },
32
+ global: { mocks: { $fetchState: { pending: false, error: null } } }
33
+ });
34
+
35
+ expect(wrapper.props('value').text).toBe('{{ template "slack.rancher.text" . }}');
36
+ });
37
+
38
+ it('should update API URL secret', async() => {
39
+ const wrapper = shallowMount(Slack, {
40
+ props: defaultProps,
41
+ global: { mocks: { $fetchState: { pending: false, error: null } } }
42
+ });
43
+
44
+ const secretSelector = wrapper.findComponent({ name: 'SimpleSecretSelector' });
45
+
46
+ await secretSelector.vm.$emit('updateSecretName', 'my-secret');
47
+ await secretSelector.vm.$emit('updateSecretKey', 'my-key');
48
+
49
+ expect(wrapper.props('value').apiURL.name).toBe('my-secret');
50
+ expect(wrapper.props('value').apiURL.key).toBe('my-key');
51
+ });
52
+
53
+ it('should update default channel', async() => {
54
+ const wrapper = shallowMount(Slack, {
55
+ props: defaultProps,
56
+ global: { mocks: { $fetchState: { pending: false, error: null } } }
57
+ });
58
+ const channelInput = wrapper.findAllComponents(LabeledInput)[0];
59
+
60
+ await channelInput.vm.$emit('update:value', '#my-channel');
61
+ expect(wrapper.props('value').channel).toBe('#my-channel');
62
+ });
63
+
64
+ it('should update proxy URL', async() => {
65
+ const wrapper = shallowMount(Slack, {
66
+ props: defaultProps,
67
+ global: { mocks: { $fetchState: { pending: false, error: null } } }
68
+ });
69
+ const proxyInput = wrapper.findAllComponents(LabeledInput)[1];
70
+
71
+ await proxyInput.vm.$emit('update:value', 'http://my-proxy.com');
72
+ expect(wrapper.props('value').httpConfig.proxyURL).toBe('http://my-proxy.com');
73
+ });
74
+
75
+ it('should toggle send resolved alerts', async() => {
76
+ const wrapper = shallowMount(Slack, {
77
+ props: defaultProps,
78
+ global: { mocks: { $fetchState: { pending: false, error: null } } }
79
+ });
80
+ const checkbox = wrapper.findComponent(Checkbox);
81
+
82
+ await checkbox.vm.$emit('update:value', true);
83
+ expect(wrapper.props('value').sendResolved).toBe(true);
84
+ });
85
+
86
+ it('should render in view mode', () => {
87
+ const wrapper = shallowMount(Slack, {
88
+ props: { ...defaultProps, mode: 'view' },
89
+ global: { mocks: { $fetchState: { pending: false, error: null } } }
90
+ });
91
+
92
+ expect(wrapper.findComponent({ name: 'SimpleSecretSelector' }).props('disabled')).toBe(true);
93
+ const inputs = wrapper.findAllComponents(LabeledInput);
94
+
95
+ expect(inputs[0].props('mode')).toBe('view');
96
+ expect(inputs[1].props('mode')).toBe('view');
97
+ expect(wrapper.findComponent(Checkbox).props('mode')).toBe('view');
98
+ });
99
+
100
+ it('should show banner if no namespace is provided', () => {
101
+ const wrapper = shallowMount(Slack, {
102
+ props: { ...defaultProps, namespace: '' },
103
+ global: { mocks: { $fetchState: { pending: false, error: null } } }
104
+ });
105
+
106
+ expect(wrapper.findComponent({ name: 'Banner' }).exists()).toBe(true);
107
+ });
108
+ });
@@ -4,10 +4,11 @@ import LabeledSelect from '@shell/components/form/LabeledSelect';
4
4
  import { Checkbox } from '@components/Form/Checkbox';
5
5
  import SimpleSecretSelector from '@shell/components/form/SimpleSecretSelector';
6
6
  import { _VIEW } from '@shell/config/query-params';
7
+ import Banner from '@components/Banner/Banner.vue';
7
8
 
8
9
  export default {
9
10
  components: {
10
- Checkbox, LabeledInput, LabeledSelect, SimpleSecretSelector
11
+ Banner, Checkbox, LabeledInput, LabeledSelect, SimpleSecretSelector
11
12
  },
12
13
  props: {
13
14
  mode: {
@@ -0,0 +1,165 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import Auth from '@shell/edit/monitoring.coreos.com.receiver/auth.vue';
3
+ import { LabeledInput } from '@components/Form/LabeledInput';
4
+ import LabeledSelect from '@shell/components/form/LabeledSelect';
5
+
6
+ describe('component: Auth', () => {
7
+ const defaultProps = {
8
+ mode: 'create',
9
+ value: {},
10
+ };
11
+
12
+ it('should render correctly with default auth type "none"', () => {
13
+ const wrapper = shallowMount(Auth, { props: { ...defaultProps } });
14
+
15
+ expect(wrapper.find('h3').text()).toBe('%monitoringReceiver.auth.label%');
16
+ const labeledSelect = wrapper.findComponent(LabeledSelect);
17
+
18
+ expect(labeledSelect.exists()).toBe(true);
19
+ expect(wrapper.vm.authType).toBe('none');
20
+
21
+ const labeledInputs = wrapper.findAllComponents(LabeledInput);
22
+
23
+ expect(labeledInputs).toHaveLength(0);
24
+ });
25
+
26
+ it('should initialize with "basic_auth" if value contains it', () => {
27
+ const value = { basic_auth: { username: 'user' } };
28
+ const wrapper = shallowMount(Auth, { props: { ...defaultProps, value } });
29
+
30
+ expect(wrapper.vm.authType).toBe('basic_auth');
31
+ const labeledInputs = wrapper.findAllComponents(LabeledInput);
32
+
33
+ expect(labeledInputs).toHaveLength(2);
34
+ });
35
+
36
+ it('should initialize with "bearer_token" if value contains it', () => {
37
+ const value = { bearer_token: 'token' };
38
+ const wrapper = shallowMount(Auth, { props: { ...defaultProps, value } });
39
+
40
+ expect(wrapper.vm.authType).toBe('bearer_token');
41
+ const labeledInputs = wrapper.findAllComponents(LabeledInput);
42
+
43
+ expect(labeledInputs).toHaveLength(1);
44
+ });
45
+
46
+ it('should initialize with "bearer_token_file" if value contains it', () => {
47
+ const value = { bearer_token_file: '/path/to/file' };
48
+ const wrapper = shallowMount(Auth, { props: { ...defaultProps, value } });
49
+
50
+ expect(wrapper.vm.authType).toBe('bearer_token_file');
51
+ const labeledInputs = wrapper.findAllComponents(LabeledInput);
52
+
53
+ expect(labeledInputs).toHaveLength(1);
54
+ });
55
+
56
+ it('should switch to "basic_auth" and display its inputs', async() => {
57
+ const wrapper = shallowMount(Auth, { props: { ...defaultProps } });
58
+
59
+ const labeledSelect = wrapper.findComponent(LabeledSelect);
60
+
61
+ await labeledSelect.vm.$emit('update:value', 'basic_auth');
62
+ await wrapper.vm.$nextTick();
63
+
64
+ expect(wrapper.vm.authType).toBe('basic_auth');
65
+ expect(wrapper.props().value).toHaveProperty('basic_auth');
66
+ expect(wrapper.props().value.basic_auth).toStrictEqual({});
67
+
68
+ const labeledInputs = wrapper.findAllComponents(LabeledInput);
69
+
70
+ expect(labeledInputs).toHaveLength(2);
71
+ expect(labeledInputs[0].props().label).toBe('%monitoringReceiver.auth.username%');
72
+ expect(labeledInputs[1].props().label).toBe('%monitoringReceiver.auth.password%');
73
+ });
74
+
75
+ it('should update basic_auth username and password', async() => {
76
+ const value = { basic_auth: { username: 'initial' } };
77
+ const wrapper = shallowMount(Auth, { props: { ...defaultProps, value } });
78
+
79
+ const labeledInputs = wrapper.findAllComponents(LabeledInput);
80
+
81
+ await labeledInputs[0].vm.$emit('update:value', 'testuser');
82
+ await labeledInputs[1].vm.$emit('update:value', 'testpass');
83
+
84
+ expect(wrapper.props().value.basic_auth.username).toBe('testuser');
85
+ expect(wrapper.props().value.basic_auth.password).toBe('testpass');
86
+ });
87
+
88
+ it('should switch to "bearer_token" and display its input', async() => {
89
+ const value = { basic_auth: { username: 'user' } };
90
+ const wrapper = shallowMount(Auth, { props: { ...defaultProps, value } });
91
+
92
+ const labeledSelect = wrapper.findComponent(LabeledSelect);
93
+
94
+ await labeledSelect.vm.$emit('update:value', 'bearer_token');
95
+ await wrapper.vm.$nextTick();
96
+
97
+ expect(wrapper.vm.authType).toBe('bearer_token');
98
+ expect(wrapper.props().value).not.toHaveProperty('basic_auth');
99
+ expect(wrapper.props().value).toHaveProperty('bearer_token');
100
+ expect(wrapper.props().value.bearer_token).toBe('');
101
+
102
+ const labeledInputs = wrapper.findAllComponents(LabeledInput);
103
+
104
+ expect(labeledInputs).toHaveLength(1);
105
+ expect(labeledInputs[0].props().label).toBe('%monitoringReceiver.auth.bearerToken.label%');
106
+ });
107
+
108
+ it('should update bearer_token', async() => {
109
+ const value = { bearer_token: 'initial-token' };
110
+ const wrapper = shallowMount(Auth, { props: { ...defaultProps, value } });
111
+ const labeledInput = wrapper.findComponent(LabeledInput);
112
+
113
+ await labeledInput.vm.$emit('update:value', 'secret-token');
114
+
115
+ expect(wrapper.props().value.bearer_token).toBe('secret-token');
116
+ });
117
+
118
+ it('should switch to "bearer_token_file" and display its input', async() => {
119
+ const value = { basic_auth: { username: 'user' } };
120
+ const wrapper = shallowMount(Auth, { props: { ...defaultProps, value } });
121
+
122
+ const labeledSelect = wrapper.findComponent(LabeledSelect);
123
+
124
+ await labeledSelect.vm.$emit('update:value', 'bearer_token_file');
125
+ await wrapper.vm.$nextTick();
126
+
127
+ expect(wrapper.vm.authType).toBe('bearer_token_file');
128
+ expect(wrapper.props().value).not.toHaveProperty('basic_auth');
129
+ expect(wrapper.props().value).toHaveProperty('bearer_token_file');
130
+ expect(wrapper.props().value.bearer_token_file).toBe('');
131
+
132
+ const labeledInputs = wrapper.findAllComponents(LabeledInput);
133
+
134
+ expect(labeledInputs).toHaveLength(1);
135
+ expect(labeledInputs[0].props().label).toBe('%monitoringReceiver.auth.bearerTokenFile.label%');
136
+ });
137
+
138
+ it('should update bearer_token_file', async() => {
139
+ const value = { bearer_token_file: '/initial/path' };
140
+ const wrapper = shallowMount(Auth, { props: { ...defaultProps, value } });
141
+ const labeledInput = wrapper.findComponent(LabeledInput);
142
+
143
+ await labeledInput.vm.$emit('update:value', '/path/to/token/file');
144
+
145
+ expect(wrapper.props().value.bearer_token_file).toBe('/path/to/token/file');
146
+ });
147
+
148
+ it('should switch from a selected auth type back to "none"', async() => {
149
+ const value = { basic_auth: { username: 'user' } };
150
+ const wrapper = shallowMount(Auth, { props: { ...defaultProps, value } });
151
+
152
+ expect(wrapper.vm.authType).toBe('basic_auth');
153
+
154
+ const labeledSelect = wrapper.findComponent(LabeledSelect);
155
+
156
+ await labeledSelect.vm.$emit('update:value', 'none');
157
+ await wrapper.vm.$nextTick();
158
+
159
+ expect(wrapper.vm.authType).toBe('none');
160
+ expect(wrapper.props().value).not.toHaveProperty('basic_auth');
161
+ const labeledInputs = wrapper.findAllComponents(LabeledInput);
162
+
163
+ expect(labeledInputs).toHaveLength(0);
164
+ });
165
+ });
@@ -0,0 +1,153 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import { _EDIT } from '@shell/config/query-params';
3
+ import Index from '../index.vue';
4
+
5
+ describe('shell/edit/monitoring.coreos.com.receiver/index.vue', () => {
6
+ const mockStore = (resourceFields = {}) => ({
7
+ getters: {
8
+ 'cluster/schemaFor': jest.fn(() => ({ resourceFields })),
9
+ clusterId: 'c-cluster-123',
10
+ 'i18n/t': (key) => key,
11
+ },
12
+ dispatch: jest.fn(),
13
+ });
14
+
15
+ const baseValue = () => ({
16
+ spec: {
17
+ name: 'test-receiver',
18
+ email_configs: [],
19
+ slack_configs: [],
20
+ webhook_configs: [],
21
+ pagerduty_configs: [],
22
+ opsgenie_configs: [],
23
+ victorops_configs: [],
24
+ pushover_configs: [],
25
+ wechat_configs: [],
26
+ },
27
+ applyDefaults: jest.fn(),
28
+ save: jest.fn(),
29
+ done: jest.fn(),
30
+ registerBeforeHook: jest.fn(),
31
+ doneRoute: {},
32
+ });
33
+
34
+ beforeEach(() => {
35
+ jest.clearAllMocks();
36
+ });
37
+
38
+ it('should mount and initialize data correctly in create mode', () => {
39
+ const value = baseValue();
40
+ const wrapper = shallowMount(Index, {
41
+ props: {
42
+ value,
43
+ mode: 'create'
44
+ },
45
+ global: {
46
+ mocks: {
47
+ $store: mockStore(value.spec),
48
+ $fetchState: { pending: false },
49
+ $route: { name: 'test-route' },
50
+ }
51
+ }
52
+ });
53
+
54
+ expect(wrapper.vm.suffixYaml).toBe('');
55
+ });
56
+
57
+ it('should correctly process email configs with smarthost on edit mode', () => {
58
+ const valueWithSmarthost = baseValue();
59
+
60
+ valueWithSmarthost.spec.email_configs = [{ smarthost: 'smtp.example.com:587' }];
61
+ const wrapper = shallowMount(Index, {
62
+ props: {
63
+ value: valueWithSmarthost,
64
+ mode: _EDIT
65
+ },
66
+ global: {
67
+ mocks: {
68
+ $store: mockStore(),
69
+ $fetchState: { pending: false },
70
+ $route: { name: 'test-route' },
71
+ }
72
+ }
73
+ });
74
+
75
+ expect(wrapper.vm.value.spec.email_configs[0].host).toBe('smtp.example.com');
76
+ expect(wrapper.vm.value.spec.email_configs[0].port).toBe('587');
77
+ expect(wrapper.vm.value.spec.email_configs[0].smarthost).toBeUndefined();
78
+ });
79
+
80
+ it('should call saveOverride which calls save method on success', async() => {
81
+ const wrapper = shallowMount(Index, {
82
+ props: {
83
+ value: baseValue(),
84
+ mode: _EDIT,
85
+ },
86
+ global: {
87
+ mocks: {
88
+ $store: mockStore(),
89
+ $fetchState: { pending: false },
90
+ $route: { name: 'test-route' },
91
+ }
92
+ },
93
+ });
94
+
95
+ const spy = jest.spyOn(wrapper.vm, 'save');
96
+ const buttonDone = jest.fn();
97
+
98
+ wrapper.vm.saveOverride(buttonDone);
99
+ expect(spy).toHaveBeenCalledTimes(1);
100
+ });
101
+
102
+ it('should call saveOverride which populates errors on yaml error', async() => {
103
+ const wrapper = shallowMount(Index, {
104
+ props: {
105
+ value: baseValue(),
106
+ mode: _EDIT,
107
+ },
108
+ global: {
109
+ mocks: {
110
+ $store: mockStore(),
111
+ $fetchState: { pending: false },
112
+ $route: { name: 'test-route' },
113
+ }
114
+ },
115
+ });
116
+
117
+ const spy = jest.spyOn(wrapper.vm, 'save');
118
+
119
+ wrapper.vm.yamlError = 'Invalid YAML';
120
+ const buttonDone = jest.fn();
121
+
122
+ wrapper.vm.saveOverride(buttonDone);
123
+
124
+ expect(wrapper.vm.errors).toContain('Invalid YAML');
125
+ expect(spy).not.toHaveBeenCalled();
126
+ expect(buttonDone).toHaveBeenCalledWith(false);
127
+ });
128
+
129
+ it('should call createSmarthost and update email configs', () => {
130
+ const value = baseValue();
131
+
132
+ value.spec.email_configs = [{ host: 'smtp.example.com', port: '587' }];
133
+
134
+ const wrapper = shallowMount(Index, {
135
+ props: {
136
+ value,
137
+ mode: _EDIT
138
+ },
139
+ global: {
140
+ mocks: {
141
+ $store: mockStore(),
142
+ $fetchState: { pending: false },
143
+ $route: { name: 'test-route' },
144
+ }
145
+ }
146
+ });
147
+
148
+ wrapper.vm.createSmarthost();
149
+ expect(value.spec.email_configs[0].smarthost).toBe('smtp.example.com:587');
150
+ expect(value.spec.email_configs[0].host).toBeUndefined();
151
+ expect(value.spec.email_configs[0].port).toBeUndefined();
152
+ });
153
+ });
@@ -0,0 +1,115 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import Tls from '@shell/edit/monitoring.coreos.com.receiver/tls.vue';
3
+ import { LabeledInput } from '@components/Form/LabeledInput';
4
+ import { Banner } from '@components/Banner';
5
+
6
+ describe('shell/edit/monitoring.coreos.com.receiver/tls.vue', () => {
7
+ const mockValue = {
8
+ tls_config: {
9
+ ca_file: 'ca.pem', cert_file: 'cert.pem', key_file: 'key.pem'
10
+ }
11
+ };
12
+ const mockMode = 'edit';
13
+
14
+ it('should mount correctly', () => {
15
+ const wrapper = shallowMount(Tls, {
16
+ props: {
17
+ value: mockValue,
18
+ mode: mockMode,
19
+ },
20
+ });
21
+
22
+ expect(wrapper.exists()).toBe(true);
23
+ });
24
+
25
+ it('should initialize tls_config if it does not exist', () => {
26
+ const wrapper = shallowMount(Tls, {
27
+ props: {
28
+ value: {},
29
+ mode: mockMode,
30
+ },
31
+ });
32
+
33
+ expect(wrapper.props().value.tls_config).toBeDefined();
34
+ expect(wrapper.props().value.tls_config).toStrictEqual({});
35
+ });
36
+
37
+ it('should render all LabeledInput components with correct labels and modes', () => {
38
+ const wrapper = shallowMount(Tls, {
39
+ props: {
40
+ value: mockValue,
41
+ mode: mockMode,
42
+ },
43
+ });
44
+
45
+ const inputs = wrapper.findAllComponents(LabeledInput);
46
+
47
+ expect(inputs).toHaveLength(3);
48
+
49
+ const labels = [
50
+ '%monitoring.receiver.tls.caFilePath.label%',
51
+ '%monitoring.receiver.tls.certFilePath.label%',
52
+ '%monitoring.receiver.tls.keyFilePath.label%',
53
+ ];
54
+
55
+ inputs.forEach((input, i) => {
56
+ expect(input.props('label')).toBe(labels[i]);
57
+ expect(input.props('mode')).toBe(mockMode);
58
+ });
59
+ });
60
+
61
+ it('should bind LabeledInput values correctly', () => {
62
+ const wrapper = shallowMount(Tls, {
63
+ props: {
64
+ value: mockValue,
65
+ mode: mockMode,
66
+ },
67
+ });
68
+
69
+ const inputs = wrapper.findAllComponents(LabeledInput);
70
+
71
+ expect(inputs[0].props('value')).toBe(mockValue.tls_config.ca_file);
72
+ expect(inputs[1].props('value')).toBe(mockValue.tls_config.cert_file);
73
+ expect(inputs[2].props('value')).toBe(mockValue.tls_config.key_file);
74
+ });
75
+
76
+ it('should update the value when LabeledInput emits an update', async() => {
77
+ const wrapper = shallowMount(Tls, {
78
+ props: {
79
+ value: {
80
+ tls_config: {
81
+ ca_file: '', cert_file: '', key_file: ''
82
+ }
83
+ },
84
+ mode: mockMode,
85
+ },
86
+ });
87
+
88
+ const inputs = wrapper.findAllComponents(LabeledInput);
89
+ const newCaFile = 'new-ca.pem';
90
+ const newCertFile = 'new-cert.pem';
91
+ const newKeyFile = 'new-key.pem';
92
+
93
+ await inputs[0].vm.$emit('update:value', newCaFile);
94
+ await inputs[1].vm.$emit('update:value', newCertFile);
95
+ await inputs[2].vm.$emit('update:value', newKeyFile);
96
+
97
+ expect(wrapper.props().value.tls_config.ca_file).toBe(newCaFile);
98
+ expect(wrapper.props().value.tls_config.cert_file).toBe(newCertFile);
99
+ expect(wrapper.props().value.tls_config.key_file).toBe(newKeyFile);
100
+ });
101
+
102
+ it('should display the informational banner', () => {
103
+ const wrapper = shallowMount(Tls, {
104
+ props: {
105
+ value: mockValue,
106
+ mode: mockMode,
107
+ },
108
+ });
109
+
110
+ const banner = wrapper.findComponent(Banner);
111
+
112
+ expect(banner.exists()).toBe(true);
113
+ expect(banner.props('color')).toBe('info');
114
+ });
115
+ });
@@ -0,0 +1,86 @@
1
+
2
+ import { shallowMount } from '@vue/test-utils';
3
+ import Email from '@shell/edit/monitoring.coreos.com.receiver/types/email.vue';
4
+ import TLS from '@shell/edit/monitoring.coreos.com.receiver/tls.vue';
5
+ import { LabeledInput } from '@components/Form/LabeledInput';
6
+ import { Checkbox } from '@components/Form/Checkbox';
7
+ import { _EDIT } from '@shell/config/query-params';
8
+
9
+ describe('component: Email', () => {
10
+ const mockStore = {
11
+ getters: {
12
+ 'i18n/t': (key: string) => key,
13
+ 'i18n/exists': () => true,
14
+ },
15
+ };
16
+
17
+ const requiredProps = {
18
+ mode: _EDIT,
19
+ value: {},
20
+ };
21
+
22
+ it('should render all child components', () => {
23
+ const wrapper = shallowMount(Email, {
24
+ props: requiredProps,
25
+ global: { mocks: mockStore },
26
+ });
27
+
28
+ const labeledInputs = wrapper.findAllComponents(LabeledInput);
29
+ const checkboxes = wrapper.findAllComponents(Checkbox);
30
+ const tls = wrapper.findComponent(TLS);
31
+
32
+ expect(labeledInputs).toHaveLength(6);
33
+ expect(checkboxes).toHaveLength(2);
34
+ expect(tls.exists()).toBe(true);
35
+ });
36
+
37
+ it('should pass down the mode prop to child components', () => {
38
+ const wrapper = shallowMount(Email, {
39
+ props: requiredProps,
40
+ global: { mocks: mockStore },
41
+ });
42
+
43
+ const labeledInputs = wrapper.findAllComponents(LabeledInput);
44
+ const checkboxes = wrapper.findAllComponents(Checkbox);
45
+ const tls = wrapper.findComponent(TLS);
46
+
47
+ labeledInputs.forEach((input) => {
48
+ expect(input.props().mode).toBe(_EDIT);
49
+ });
50
+
51
+ checkboxes.forEach((checkbox) => {
52
+ expect(checkbox.props().mode).toBe(_EDIT);
53
+ });
54
+
55
+ expect(tls.props().mode).toBe(_EDIT);
56
+ });
57
+
58
+ it('should initialize send_resolved and require_tls to false if not present', () => {
59
+ const value = {};
60
+ const wrapper = shallowMount(Email, {
61
+ props: {
62
+ ...requiredProps,
63
+ value,
64
+ },
65
+ global: { mocks: mockStore },
66
+ });
67
+
68
+ expect(wrapper.props().value.send_resolved).toBe(false);
69
+ expect(wrapper.props().value.require_tls).toBe(false);
70
+ });
71
+
72
+ it('should emit an input event when TLS component emits an update:value event', async() => {
73
+ const wrapper = shallowMount(Email, {
74
+ props: requiredProps,
75
+ global: { mocks: mockStore },
76
+ });
77
+
78
+ const tls = wrapper.findComponent(TLS);
79
+ const updatedValue = { smarthost: 'new-value' };
80
+
81
+ await tls.vm.$emit('update:value', updatedValue);
82
+
83
+ expect(wrapper.emitted('input')).toHaveLength(1);
84
+ expect(wrapper.emitted('input')?.[0][0]).toStrictEqual(updatedValue);
85
+ });
86
+ });