Skip to content

Commit f4b910e

Browse files
xingzhang-suselsongsuse
authored andcommitted
Provide sample case for verifying key-value pair of constants in select > options
1 parent b7ceb66 commit f4b910e

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

pkg/sbomscanner/edit/__tests__/sbomscanner.kubewarden.io.registry.spec.ts

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,38 @@ import { shallowMount, Wrapper, flushPromises } from '@vue/test-utils';
22
import CruRegistry from '../sbomscanner.kubewarden.io.registry.vue';
33
import { SECRET } from '@shell/config/types';
44
import { SECRET_TYPES } from '@shell/config/secret';
5-
6-
jest.mock('@sbomscanner/constants', () => ({
7-
REGISTRY_TYPE: {
8-
OCI_DISTRIBUTION: 'oci-distribution',
9-
NO_CATALOG: 'no-catalog',
10-
},
11-
REGISTRY_TYPE_OPTIONS: [
12-
{ label: 'OCI', value: 'oci-distribution' },
13-
{ label: 'No Catalog', value: 'no-catalog' },
14-
],
15-
SCAN_INTERVAL_OPTIONS: [
16-
{ label: 'Manual', value: 'manual' },
17-
{ label: 'Daily', value: '24h' },
18-
],
19-
SCAN_INTERVALS: {
20-
MANUAL: 'manual',
21-
DAILY: '24h',
22-
},
23-
}));
5+
import { SCAN_INTERVALS, REGISTRY_TYPE } from '../../constants';
246

257
jest.mock('@sbomscanner/types', () => ({
268
PRODUCT_NAME: 'kubewarden',
279
PAGE: { REGISTRIES: 'registries' },
2810
LOCAT_HOST: [],
2911
}));
3012

31-
const { REGISTRY_TYPE, SCAN_INTERVALS } = require('@sbomscanner/constants');
13+
const LabeledSelectStub = {
14+
name: 'LabeledSelect',
15+
template: `
16+
<select :data-testid="dataTestid" @change="$emit('input', value)" :required="required">
17+
<option
18+
v-for="opt in options"
19+
:key="opt[optionKey]"
20+
:value="opt[optionKey]"
21+
>
22+
{{ opt[optionLabel] }}
23+
</option>
24+
</select>
25+
`,
26+
props: ['value', 'options', 'optionKey', 'optionLabel', 'required', 'dataTestid'],
27+
};
28+
29+
const { REGISTRY_TYPE } = require('@sbomscanner/constants');
3230

3331
const stubs = {
3432
CruResource: { name: 'CruResource', template: '<div><slot /></div>' },
3533
NameNsDescription: true,
3634
LabeledInput: true,
37-
LabeledSelect: true,
3835
Banner: { name: 'Banner', template: '<div><slot /></div>' },
36+
LabeledSelect: LabeledSelectStub
3937
};
4038

4139
const t = (key: string) => key;
@@ -350,7 +348,10 @@ describe('CruRegistry', () => {
350348
await wrapper.vm.$nextTick();
351349
const repoSelect = wrapper.find('[data-testid="registry-scanning-repository-names"]');
352350

353-
expect(repoSelect.attributes('required')).toBe('true');
351+
expect(repoSelect.exists()).toBe(true);
352+
const requiredAttr = repoSelect.attributes('required');
353+
354+
expect(requiredAttr).toBe('');
354355
});
355356

356357
it('should NOT mark repositories as required when type is OCI_DISTRIBUTION', async() => {
@@ -360,7 +361,26 @@ describe('CruRegistry', () => {
360361
const repoSelect = wrapper.find('[data-testid="registry-scanning-repository-names"]');
361362
const requiredAttr = repoSelect.attributes('required');
362363

363-
expect([undefined, 'false']).toContain(requiredAttr);
364+
expect(requiredAttr).toBe(undefined);
365+
});
366+
});
367+
368+
describe('registry scan interval select', () => {
369+
it('Confirm the key-value pair of constants in the select > options', async() => {
370+
wrapper = createWrapper({});
371+
372+
expect(wrapper.find('select[data-testid="registry-scanning-interval-select"] option[value="1h"]').exists()).toBe(true);
373+
expect(wrapper.find('select[data-testid="registry-scanning-interval-select"] option[value="1h"]').text()).toBe('Every 1 hour');
374+
expect(wrapper.find('select[data-testid="registry-scanning-interval-select"] option[value="3h"]').exists()).toBe(true);
375+
expect(wrapper.find('select[data-testid="registry-scanning-interval-select"] option[value="3h"]').text()).toBe('Every 3 hours');
376+
expect(wrapper.find('select[data-testid="registry-scanning-interval-select"] option[value="6h"]').exists()).toBe(true);
377+
expect(wrapper.find('select[data-testid="registry-scanning-interval-select"] option[value="6h"]').text()).toBe('Every 6 hours');
378+
expect(wrapper.find('select[data-testid="registry-scanning-interval-select"] option[value="12h"]').exists()).toBe(true);
379+
expect(wrapper.find('select[data-testid="registry-scanning-interval-select"] option[value="12h"]').text()).toBe('Every 12 hours');
380+
expect(wrapper.find('select[data-testid="registry-scanning-interval-select"] option[value="24h"]').exists()).toBe(true);
381+
expect(wrapper.find('select[data-testid="registry-scanning-interval-select"] option[value="24h"]').text()).toBe('Every 24 hours');
382+
expect(wrapper.find('select[data-testid="registry-scanning-interval-select"] option[value="0s"]').exists()).toBe(true);
383+
expect(wrapper.find('select[data-testid="registry-scanning-interval-select"] option[value="0s"]').text()).toBe('Manual Scan');
364384
});
365385
});
366386
});

0 commit comments

Comments
 (0)