Skip to content

Commit 813539c

Browse files
momesginMo Mesgin
andauthored
Fix switch cluster icon behaviour (#17396)
* fix switch cluster icon behaviour * comment * update routeComboActive * update routeComboActive to cover special case * fix test --------- Co-authored-by: Mo Mesgin <mmesgin@Mos-M2-MacBook-Pro.local>
1 parent b519e90 commit 813539c

2 files changed

Lines changed: 139 additions & 4 deletions

File tree

shell/components/nav/TopLevelMenu.vue

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ export default {
9898
return count?.summary.count;
9999
},
100100
101+
routeComboActive() {
102+
if (!this.routeCombo) {
103+
return false;
104+
}
105+
106+
const ready = [...this.appBar.pinFiltered, ...this.appBar.clustersFiltered].filter((c) => c.ready);
107+
const readyCount = ready.length;
108+
109+
return readyCount > 1 || (readyCount === 1 && this.clusterId !== ready[0].id);
110+
},
111+
101112
// New
102113
search() {
103114
return (this.clusterFilter || '').toLowerCase();
@@ -386,7 +397,7 @@ export default {
386397
},
387398
388399
clusterMenuClick(ev, cluster) {
389-
if (this.routeCombo) {
400+
if (this.routeComboActive) {
390401
ev.preventDefault();
391402
392403
if (this.isCurrRouteClusterExplorer && this.productFromRoute === this.currentProduct?.name) {
@@ -446,7 +457,7 @@ export default {
446457
content = this.shown ? null : contentText;
447458
448459
// if key combo is pressed, then we update the tooltip as well
449-
} else if (this.routeCombo &&
460+
} else if (this.routeComboActive &&
450461
typeof item === 'object' &&
451462
!Array.isArray(item) &&
452463
item !== null &&
@@ -706,7 +717,7 @@ export default {
706717
<ClusterIconMenu
707718
v-clean-tooltip="getTooltipConfig(c, true)"
708719
:cluster="c"
709-
:route-combo="routeCombo"
720+
:route-combo="routeComboActive"
710721
class="rancher-provider-icon"
711722
/>
712723
<div
@@ -785,7 +796,7 @@ export default {
785796
<ClusterIconMenu
786797
v-clean-tooltip="getTooltipConfig(c, true)"
787798
:cluster="c"
788-
:route-combo="routeCombo"
799+
:route-combo="routeComboActive"
789800
class="rancher-provider-icon"
790801
/>
791802
<div

shell/components/nav/__tests__/TopLevelMenu.test.ts

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,4 +713,128 @@ describe('topLevelMenu', () => {
713713
expect(wrapper.vm.mgmtClusters).toStrictEqual([]);
714714
});
715715
});
716+
717+
describe('computed properties', () => {
718+
describe('routeComboActive', () => {
719+
it('should be true when routeCombo is true and there are multiple ready clusters', async() => {
720+
const wrapper: Wrapper<InstanceType<typeof TopLevelMenu>> = mount(TopLevelMenu, {
721+
global: {
722+
mocks: {
723+
$route: {},
724+
$store: {
725+
...generateStore([
726+
{
727+
nameDisplay: 'cluster1',
728+
id: 'an-id1',
729+
mgmt: { id: 'an-id1' },
730+
isReady: true
731+
},
732+
{
733+
nameDisplay: 'cluster2',
734+
id: 'an-id2',
735+
mgmt: { id: 'an-id2' },
736+
isReady: true
737+
}
738+
])
739+
}
740+
},
741+
stubs: ['BrandImage', 'router-link'],
742+
}
743+
});
744+
745+
await waitForIt();
746+
await wrapper.setData({ routeCombo: true });
747+
748+
expect(wrapper.vm.routeComboActive).toBe(true);
749+
});
750+
751+
it('should be false when routeCombo is false', async() => {
752+
const wrapper: Wrapper<InstanceType<typeof TopLevelMenu>> = mount(TopLevelMenu, {
753+
global: {
754+
mocks: {
755+
$route: {},
756+
$store: {
757+
...generateStore([
758+
{
759+
nameDisplay: 'cluster1',
760+
id: 'an-id1',
761+
mgmt: { id: 'an-id1' },
762+
isReady: true
763+
},
764+
{
765+
nameDisplay: 'cluster2',
766+
id: 'an-id2',
767+
mgmt: { id: 'an-id2' },
768+
isReady: true
769+
}
770+
])
771+
}
772+
},
773+
stubs: ['BrandImage', 'router-link'],
774+
}
775+
});
776+
777+
await waitForIt();
778+
await wrapper.setData({ routeCombo: false });
779+
780+
expect(wrapper.vm.routeComboActive).toBe(false);
781+
});
782+
783+
it('should be false when there is only one ready cluster and it is the current cluster', async() => {
784+
const store = generateStore([
785+
{
786+
nameDisplay: 'cluster1',
787+
id: 'an-id1',
788+
mgmt: { id: 'an-id1' },
789+
isReady: true
790+
}
791+
]);
792+
793+
store.getters.clusterId = 'an-id1' as any;
794+
795+
const wrapper: Wrapper<InstanceType<typeof TopLevelMenu>> = mount(TopLevelMenu, {
796+
global: {
797+
mocks: {
798+
$route: {},
799+
$store: store
800+
},
801+
stubs: ['BrandImage', 'router-link'],
802+
}
803+
});
804+
805+
await waitForIt();
806+
await wrapper.setData({ routeCombo: true });
807+
808+
expect(wrapper.vm.routeComboActive).toBe(false);
809+
});
810+
811+
it('should be true when there is only one ready cluster but it is not the current cluster', async() => {
812+
const store = generateStore([
813+
{
814+
nameDisplay: 'cluster1',
815+
id: 'an-id1',
816+
mgmt: { id: 'an-id1' },
817+
isReady: true
818+
}
819+
]);
820+
821+
store.getters.clusterId = 'some-other-cluster-id' as any;
822+
823+
const wrapper: Wrapper<InstanceType<typeof TopLevelMenu>> = mount(TopLevelMenu, {
824+
global: {
825+
mocks: {
826+
$route: {},
827+
$store: store
828+
},
829+
stubs: ['BrandImage', 'router-link'],
830+
}
831+
});
832+
833+
await waitForIt();
834+
await wrapper.setData({ routeCombo: true });
835+
836+
expect(wrapper.vm.routeComboActive).toBe(true);
837+
});
838+
});
839+
});
716840
});

0 commit comments

Comments
 (0)