mirror of https://github.com/rancher/dashboard.git
Fleet add FleetOCIStorageSecret.test unit test
Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
This commit is contained in:
parent
6c677c7dab
commit
dbabbf71b0
|
|
@ -89,14 +89,6 @@ export default {
|
|||
return this.ociSecrets.find((secret) => secret.name === defaultSecretName);
|
||||
},
|
||||
|
||||
secretsList() {
|
||||
if (this.defaultSecret) {
|
||||
return this.ociSecrets.filter((secret) => secret.id !== this.defaultSecret.id);
|
||||
}
|
||||
|
||||
return this.ociSecrets;
|
||||
},
|
||||
|
||||
options() {
|
||||
const out = [{
|
||||
label: this.t('generic.none'),
|
||||
|
|
@ -110,14 +102,16 @@ export default {
|
|||
});
|
||||
}
|
||||
|
||||
if (this.secretsList.length > 0) {
|
||||
const customSecrets = this.defaultSecret ? this.ociSecrets.filter((secret) => secret.id !== this.defaultSecret.id) : this.ociSecrets;
|
||||
|
||||
if (customSecrets.length > 0) {
|
||||
out.push({
|
||||
kind: 'title',
|
||||
label: this.t(`fleet.gitRepo.ociStorageSecret.options.${ this.allowDefault ? 'chooseCustom' : 'chooseExisting' }`),
|
||||
disabled: true
|
||||
});
|
||||
|
||||
this.secretsList.forEach((secret) => {
|
||||
customSecrets.forEach((secret) => {
|
||||
out.push({
|
||||
label: secret.name,
|
||||
value: secret
|
||||
|
|
@ -166,6 +160,7 @@ export default {
|
|||
|
||||
<template>
|
||||
<LabeledSelect
|
||||
data-testid="fleet-oci-storage-secret-list"
|
||||
:label="t('fleet.gitRepo.ociStorageSecret.label')"
|
||||
:mode="mode"
|
||||
:value="selected"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,213 @@
|
|||
import { mount } from '@vue/test-utils';
|
||||
import flushPromises from 'flush-promises';
|
||||
import { SECRET_TYPES } from '@shell/config/secret';
|
||||
import { FLEET as FLEET_ANNOTATIONS } from '@shell/config/labels-annotations';
|
||||
import FleetOCIStorageSecret from '@shell/components/fleet/FleetOCIStorageSecret.vue';
|
||||
import { _CREATE, _EDIT } from '@shell/config/query-params';
|
||||
|
||||
const workspaces = [
|
||||
{
|
||||
id: 'fleet-local',
|
||||
metadata: { annotations: { [FLEET_ANNOTATIONS.OCI_STORAGE_SECRET_DEFAULT]: 'secret-1' } }
|
||||
},
|
||||
{
|
||||
id: 'fleet-default',
|
||||
metadata: { annotations: { } }
|
||||
},
|
||||
{
|
||||
id: 'fleet-custom-workspace',
|
||||
metadata: { annotations: { [FLEET_ANNOTATIONS.OCI_STORAGE_SECRET_DEFAULT]: 'secret-6' } }
|
||||
},
|
||||
];
|
||||
|
||||
const secrets = [
|
||||
{
|
||||
id: 'fleet-local/secret-1',
|
||||
name: 'secret-1',
|
||||
_type: SECRET_TYPES.FLEET_OCI_STORAGE,
|
||||
metadata: {
|
||||
namespace: 'fleet-local',
|
||||
annotations: { [FLEET_ANNOTATIONS.OCI_STORAGE_SECRET_GENERATED]: false }
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'fleet-local/secret-2',
|
||||
name: 'secret-2',
|
||||
_type: SECRET_TYPES.FLEET_OCI_STORAGE,
|
||||
metadata: {
|
||||
namespace: 'fleet-local',
|
||||
annotations: { [FLEET_ANNOTATIONS.OCI_STORAGE_SECRET_GENERATED]: 'true' }
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'fleet-default/secret-3',
|
||||
name: 'secret-3',
|
||||
_type: SECRET_TYPES.FLEET_OCI_STORAGE,
|
||||
metadata: {
|
||||
namespace: 'fleet-default',
|
||||
annotations: { [FLEET_ANNOTATIONS.OCI_STORAGE_SECRET_GENERATED]: false }
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'fleet-default/secret-4',
|
||||
name: 'secret-4',
|
||||
_type: SECRET_TYPES.FLEET_OCI_STORAGE,
|
||||
metadata: {
|
||||
namespace: 'fleet-default',
|
||||
annotations: { [FLEET_ANNOTATIONS.OCI_STORAGE_SECRET_GENERATED]: 'true' }
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'fleet-custom-workspace/secret-5',
|
||||
name: 'secret-5',
|
||||
_type: SECRET_TYPES.FLEET_OCI_STORAGE,
|
||||
metadata: { namespace: 'fleet-custom-workspace' }
|
||||
},
|
||||
{
|
||||
id: 'fleet-custom-workspace/secret-6',
|
||||
name: 'secret-6',
|
||||
_type: SECRET_TYPES.FLEET_OCI_STORAGE,
|
||||
metadata: { namespace: 'fleet-custom-workspace' }
|
||||
}
|
||||
];
|
||||
|
||||
describe('component: FleetOCIStorageSecret', () => {
|
||||
describe('mode: create', () => {
|
||||
const mode = _CREATE;
|
||||
|
||||
it('displays empty options', () => {
|
||||
const wrapper = mount(FleetOCIStorageSecret, {
|
||||
props: {
|
||||
workspace: 'fleet-local',
|
||||
secret: null,
|
||||
mode,
|
||||
},
|
||||
data() {
|
||||
return { secrets: [], workspaces };
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.vm.options).toHaveLength(1);
|
||||
expect(wrapper.vm.options[0].label).toContain('none');
|
||||
});
|
||||
|
||||
it('displays default and None options', () => {
|
||||
const wrapper = mount(FleetOCIStorageSecret, {
|
||||
props: {
|
||||
workspace: 'fleet-local',
|
||||
secret: null,
|
||||
mode,
|
||||
},
|
||||
data() {
|
||||
return { secrets, workspaces };
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.vm.options).toHaveLength(2);
|
||||
expect(wrapper.vm.options[0].label).toContain('none');
|
||||
|
||||
expect(wrapper.vm.options[1].label).toContain('secret-1');
|
||||
expect(wrapper.vm.options[1].label).toContain('default');
|
||||
});
|
||||
|
||||
it('displays custom secrets options', () => {
|
||||
const wrapper = mount(FleetOCIStorageSecret, {
|
||||
props: {
|
||||
workspace: 'fleet-default',
|
||||
secret: null,
|
||||
mode,
|
||||
},
|
||||
data() {
|
||||
return { secrets, workspaces };
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.vm.options).toHaveLength(3);
|
||||
expect(wrapper.vm.options[0].label).toContain('none');
|
||||
|
||||
expect(wrapper.vm.options[1].label).toContain('chooseCustom');
|
||||
expect(wrapper.vm.options[2].label).toContain('secret-3');
|
||||
expect(wrapper.vm.options[2].label).not.toContain('default');
|
||||
});
|
||||
|
||||
it('displays all options', () => {
|
||||
const wrapper = mount(FleetOCIStorageSecret, {
|
||||
props: {
|
||||
workspace: 'fleet-custom-workspace',
|
||||
secret: null,
|
||||
mode,
|
||||
},
|
||||
data() {
|
||||
return { secrets, workspaces };
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.vm.options).toHaveLength(4);
|
||||
expect(wrapper.vm.options[0].label).toContain('none');
|
||||
|
||||
expect(wrapper.vm.options[1].label).toContain('secret-6');
|
||||
expect(wrapper.vm.options[1].label).toContain('default');
|
||||
|
||||
expect(wrapper.vm.options[2].label).toContain('chooseCustom');
|
||||
expect(wrapper.vm.options[3].label).toContain('secret-5');
|
||||
});
|
||||
|
||||
it('select default if default secret exists', async() => {
|
||||
const wrapper = mount(FleetOCIStorageSecret, {
|
||||
props: {
|
||||
workspace: '',
|
||||
secret: null,
|
||||
mode,
|
||||
},
|
||||
data() {
|
||||
return { secrets, workspaces };
|
||||
},
|
||||
});
|
||||
|
||||
wrapper.setProps({ workspace: 'fleet-local' });
|
||||
await flushPromises();
|
||||
|
||||
expect(wrapper.emitted('update:value')?.[0][0]).toBe('secret-1');
|
||||
});
|
||||
|
||||
it('select none if default secret not exists', async() => {
|
||||
const wrapper = mount(FleetOCIStorageSecret, {
|
||||
props: {
|
||||
workspace: '',
|
||||
secret: null,
|
||||
mode,
|
||||
},
|
||||
data() {
|
||||
return { secrets, workspaces };
|
||||
},
|
||||
});
|
||||
|
||||
wrapper.setProps({ workspace: 'fleet-default' });
|
||||
await flushPromises();
|
||||
|
||||
expect(wrapper.emitted('update:value')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('mode: edit', () => {
|
||||
const mode = _EDIT;
|
||||
|
||||
it('displays selected secret', async() => {
|
||||
const wrapper = mount(FleetOCIStorageSecret, {
|
||||
props: {
|
||||
workspace: 'fleet-local',
|
||||
secret: 'test',
|
||||
mode,
|
||||
},
|
||||
data() {
|
||||
return { secrets, workspaces };
|
||||
},
|
||||
});
|
||||
|
||||
const secretSelector = wrapper.find('[data-testid="fleet-oci-storage-secret-list"]');
|
||||
|
||||
expect(wrapper.vm.selected).toBe('test');
|
||||
expect(secretSelector.element.textContent).toContain('test');
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue