From 55b842a0200b969278a1428d8df58be4b75d3450 Mon Sep 17 00:00:00 2001 From: Dai Yuzeng Date: Wed, 5 Jul 2023 10:53:58 +0800 Subject: [PATCH 1/3] HARVESTER: only change priority by select component --- shell/components/form/PodAffinity.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/components/form/PodAffinity.vue b/shell/components/form/PodAffinity.vue index 38c8dede5fc..70ae8c932bc 100644 --- a/shell/components/form/PodAffinity.vue +++ b/shell/components/form/PodAffinity.vue @@ -286,7 +286,7 @@ export default { }, priorityDisplay(term) { - return term.weight ? this.t('workload.scheduling.affinity.preferred') : this.t('workload.scheduling.affinity.required'); + return 'weight' in term ? this.t('workload.scheduling.affinity.preferred') : this.t('workload.scheduling.affinity.required'); }, changeNamespaceMode(val, term, idx) { @@ -468,7 +468,7 @@ export default { />
Date: Thu, 6 Jul 2023 14:24:31 -0700 Subject: [PATCH 2/3] apply weight input fix to node affinity and add unit tests --- shell/components/form/NodeAffinity.vue | 4 +- .../form/__tests__/NodeAffinity.test.ts | 38 +++++++++++++++ .../form/__tests__/PodAffinity.test.ts | 46 +++++++++++++++++++ 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 shell/components/form/__tests__/NodeAffinity.test.ts create mode 100644 shell/components/form/__tests__/PodAffinity.test.ts diff --git a/shell/components/form/NodeAffinity.vue b/shell/components/form/NodeAffinity.vue index 27ce7a2fe4e..26ff09b7cf7 100644 --- a/shell/components/form/NodeAffinity.vue +++ b/shell/components/form/NodeAffinity.vue @@ -156,7 +156,7 @@ export default { }, priorityDisplay(term) { - return term.weight ? this.t('workload.scheduling.affinity.preferred') : this.t('workload.scheduling.affinity.required'); + return 'weight' in term ? this.t('workload.scheduling.affinity.preferred') : this.t('workload.scheduling.affinity.required'); }, updateExpressions(row, expressions) { @@ -212,7 +212,7 @@ export default { />
{ + it('should display the weight input when the priority is preferred', () => { + const nodeAffinity = { + preferredDuringSchedulingIgnoredDuringExecution: [{ + preference: { matchExpressions: [] }, + weight: 1 + }], + requiredDuringSchedulingIgnoredDuringExecution: { nodeSelectorTerms: [{ matchExpressions: [] }] } + }; + const wrapper = mount(NodeAffinity, { propsData: { mode: _CREATE, value: nodeAffinity } }); + + expect(wrapper.find('[data-testid="node-affinity-weight-index0"]').exists()).toBeTruthy(); + expect(wrapper.find('[data-testid="node-affinity-weight-index1"]').exists()).toBeFalsy(); + }); + + it('should display the weight input when the value is cleared', async() => { + const nodeAffinity = { + preferredDuringSchedulingIgnoredDuringExecution: [{ + preference: { matchExpressions: [] }, + weight: 1 + }], + }; + + const wrapper = mount(NodeAffinity, { propsData: { mode: _CREATE, value: nodeAffinity } }); + + const weightInput = wrapper.find('[data-testid="node-affinity-weight-index0"]'); + + weightInput.setValue(''); + + await wrapper.vm.$nextTick(); + + expect(wrapper.find('[data-testid="node-affinity-weight-index0"]').exists()).toBeTruthy(); + }); +}); diff --git a/shell/components/form/__tests__/PodAffinity.test.ts b/shell/components/form/__tests__/PodAffinity.test.ts new file mode 100644 index 00000000000..33e872a12ec --- /dev/null +++ b/shell/components/form/__tests__/PodAffinity.test.ts @@ -0,0 +1,46 @@ +import { mount } from '@vue/test-utils'; +import PodAffinity from '@shell/components/form/PodAffinity.vue'; +import { _CREATE } from '@shell/config/query-params'; + +describe('component: PodAffinity', () => { + it('should display the weight input when the priority is preferred', () => { + const podAffinity = { + preferredDuringSchedulingIgnoredDuringExecution: [{ + podAffinityTerm: { topologyKey: 'test topology key 1' }, + weight: 1 + }], + requiredDuringSchedulingIgnoredDuringExecution: [{ topologyKey: 'test topology key 2' }] + }; + const wrapper = mount(PodAffinity, { + propsData: { + mode: _CREATE, field: 'overrideAffinity', value: { overrideAffinity: { podAffinity } } + } + }); + + expect(wrapper.find('[data-testid="pod-affinity-weight-index0"]').exists()).toBeTruthy(); + expect(wrapper.find('[data-testid="pod-affinity-weight-index1"]').exists()).toBeFalsy(); + }); + + it('should display the weight input when the value is cleared', async() => { + const podAffinity = { + preferredDuringSchedulingIgnoredDuringExecution: [{ + podAffinityTerm: { topologyKey: 'test topology key 1' }, + weight: 1 + }], + }; + + const wrapper = mount(PodAffinity, { + propsData: { + mode: _CREATE, field: 'overrideAffinity', value: { overrideAffinity: { podAffinity } } + } + }); + + const weightInput = wrapper.find('[data-testid="pod-affinity-weight-index0"]'); + + weightInput.setValue(''); + + await wrapper.vm.$nextTick(); + + expect(wrapper.find('[data-testid="pod-affinity-weight-index0"]').exists()).toBeTruthy(); + }); +}); From 2122a0ffe4796acdcced490a3a453251e5bbf7a9 Mon Sep 17 00:00:00 2001 From: Nancy Butler <42977925+mantis-toboggan-md@users.noreply.github.com> Date: Thu, 6 Jul 2023 14:27:32 -0700 Subject: [PATCH 3/3] fix node affinity unit test name --- shell/components/form/__tests__/NodeAffinity.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/components/form/__tests__/NodeAffinity.test.ts b/shell/components/form/__tests__/NodeAffinity.test.ts index c9a34fdbc7a..527d990389f 100644 --- a/shell/components/form/__tests__/NodeAffinity.test.ts +++ b/shell/components/form/__tests__/NodeAffinity.test.ts @@ -2,7 +2,7 @@ import { mount } from '@vue/test-utils'; import NodeAffinity from '@shell/components/form/NodeAffinity.vue'; import { _CREATE } from '@shell/config/query-params'; -describe('component: PodAffinity', () => { +describe('component: NodeAffinity', () => { it('should display the weight input when the priority is preferred', () => { const nodeAffinity = { preferredDuringSchedulingIgnoredDuringExecution: [{