-
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
- Loading branch information
1 parent
4cca5fa
commit 11affd2
Showing
3 changed files
with
144 additions
and
20 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
90 changes: 90 additions & 0 deletions
90
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,90 @@ | ||
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: '_' }), | ||
uiServices: () => [longhornFrontend] | ||
}, | ||
stubs: { | ||
Banner: { template: '<span />' }, | ||
LazyImage: { template: '<span />' }, | ||
} | ||
}); | ||
|
||
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