-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure longhorn UI proxy link to contain dynamic namespace (#10263)
* Restructure longhorn UI proxy link to contain dynamic namespace * Update fetch to use findMatching
- Loading branch information
1 parent
9f6aa14
commit 983a70c
Showing
3 changed files
with
142 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
shell/pages/c/_cluster/longhorn/__tests__/longhorn.index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { shallowMount } from '@vue/test-utils'; | ||
|
||
import IconMessage from '@shell/components/IconMessage'; | ||
import LonghornOverview from '@shell/pages/c/_cluster/longhorn/index.vue'; | ||
|
||
const longhornFrontend = { | ||
id: 'default/longhorn-frontend', | ||
type: 'service', | ||
apiVersion: 'v1', | ||
kind: 'Service', | ||
metadata: { | ||
labels: { app: 'longhorn-ui' }, | ||
name: 'longhorn-frontend', | ||
namespace: 'default', | ||
} | ||
}; | ||
|
||
describe('page: LonghornOverview', () => { | ||
const commonMocks = { | ||
$fetchState: { pending: false }, | ||
$store: { | ||
dispatch: () => jest.fn, | ||
getters: { | ||
currentProduct: () => 'cluster', | ||
'cluster/findAll': () => jest.fn(), | ||
'cluster/schemaFor': () => jest.fn(), | ||
'cluster/matching': () => jest.fn(), | ||
'i18n/t': () => jest.fn(), | ||
}, | ||
}, | ||
}; | ||
|
||
const createWrapper = (overrides?: any) => { | ||
return shallowMount(LonghornOverview, { | ||
mocks: commonMocks, | ||
...overrides, | ||
}); | ||
}; | ||
|
||
it('initializes externalLinks as an empty array', () => { | ||
const wrapper = createWrapper({ | ||
stubs: { | ||
IconMessage: { template: '<span />' }, | ||
LazyImage: { template: '<span />' }, | ||
} | ||
}); | ||
|
||
expect(wrapper.vm.externalLinks).toStrictEqual([]); | ||
}); | ||
|
||
it('populates externalLinks proxy link correctly when uiServices contain service', async() => { | ||
const proxyUrl = `/k8s/clusters/_/api/v1/namespaces/${ longhornFrontend.metadata.namespace }/services/http:longhorn-frontend:80/proxy/`; | ||
|
||
interface LinkConfig { | ||
enabled: boolean; | ||
iconSrc: string; | ||
label: string; | ||
description: string; | ||
link: string; | ||
} | ||
|
||
const wrapper = createWrapper({ | ||
computed: { currentCluster: () => ({ id: '_' }) }, | ||
stubs: { | ||
Banner: { template: '<span />' }, | ||
LazyImage: { template: '<span />' }, | ||
} | ||
}); | ||
|
||
wrapper.setData({ uiServices: [longhornFrontend] }); | ||
|
||
await wrapper.vm.$nextTick(); | ||
|
||
const containsProxyUrl = wrapper.vm.externalLinks.find((link: LinkConfig) => link.link); | ||
|
||
expect(containsProxyUrl).toBeTruthy(); | ||
expect(containsProxyUrl.link).toStrictEqual(proxyUrl); | ||
}); | ||
|
||
it('displays IconMessage when externalLinks array is empty', () => { | ||
const wrapper = createWrapper({ stubs: { LazyImage: { template: '<span />' } } }); | ||
|
||
expect(wrapper.vm.externalLinks).toStrictEqual([]); | ||
|
||
const iconMessage = wrapper.findComponent(IconMessage); | ||
|
||
expect(iconMessage.exists()).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters