-
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 5554ea7
Showing
2 changed files
with
119 additions
and
13 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
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,81 @@ | ||
import { shallowMount } from '@vue/test-utils'; | ||
|
||
import { Banner } from '@components/Banner'; | ||
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 = { | ||
$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: { | ||
Banner: { template: '<span />' }, | ||
LazyImage: { template: '<span />' }, | ||
} | ||
}); | ||
|
||
expect(wrapper.vm.externalLinks).toStrictEqual([]); | ||
}); | ||
|
||
it('populates externalLinks proxy link correctly when uiService is valid', async() => { | ||
const wrapper = createWrapper({ | ||
computed: { | ||
currentCluster: () => ({ id: '_' }), | ||
uiService: () => longhornFrontend | ||
}, | ||
stubs: { | ||
Banner: { template: '<span />' }, | ||
LazyImage: { template: '<span />' }, | ||
} | ||
}); | ||
|
||
const proxyUrl = `/k8s/clusters/_/api/v1/namespaces/${ longhornFrontend.metadata.namespace }/services/http:longhorn-frontend:80/proxy/`; | ||
|
||
await wrapper.vm.$nextTick(); | ||
|
||
const containsProxyUrl = wrapper.vm.externalLinks.find((link) => link.link); | ||
|
||
expect(containsProxyUrl).toBeTruthy(); | ||
expect(containsProxyUrl.link).toStrictEqual(proxyUrl); | ||
}); | ||
|
||
it('displays error banner when externalLinks array is empty', () => { | ||
const wrapper = createWrapper({ stubs: { LazyImage: { template: '<span />' } } }); | ||
|
||
expect(wrapper.vm.externalLinks).toStrictEqual([]); | ||
|
||
const banner = wrapper.findComponent(Banner); | ||
|
||
expect(banner.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