forked from rancher/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automation: No matching clusters msg fix (rancher#9864)
* Remove conditional chaining in template * Prevent app to break if no setting available * Prevent to break if no mgmt cluster * Prevent sidebar to break if no kube cluster * Prevent breaking if no product available * Prevent sort utils to break if no value is provided * Add markup comments * Replace getter mapping * Prevent error if missing label for the inspected cluster * Add tests for sidebar
- Loading branch information
Showing
4 changed files
with
159 additions
and
16 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
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,120 @@ | ||
import { mount, Wrapper } from '@vue/test-utils'; | ||
import TopLevelMenu from '@shell/components/nav/TopLevelMenu'; | ||
|
||
// DISCLAIMER: This should not be added here, although we have several store requests which are irrelevant | ||
const defaultStore = { | ||
'management/byId': jest.fn(), | ||
'management/schemaFor': jest.fn(), | ||
'i18n/t': jest.fn(), | ||
'features/get': jest.fn(), | ||
'prefs/theme': jest.fn(), | ||
defaultClusterId: jest.fn(), | ||
clusterId: jest.fn(), | ||
'type-map/activeProducts': [], | ||
}; | ||
|
||
describe('topLevelMenu', () => { | ||
it('should display clusters', () => { | ||
const wrapper: Wrapper<InstanceType<typeof TopLevelMenu>> = mount(TopLevelMenu, { | ||
mocks: { | ||
$store: { | ||
getters: { | ||
'management/all': () => [{ name: 'whatever' }], | ||
...defaultStore | ||
}, | ||
}, | ||
}, | ||
stubs: ['BrandImage', 'nuxt-link'] | ||
}); | ||
|
||
const cluster = wrapper.find('[data-testid="top-level-menu-cluster-0"]'); | ||
|
||
expect(cluster.exists()).toBe(true); | ||
}); | ||
|
||
describe('searching a term', () => { | ||
describe('should displays a no results message if have clusters but', () => { | ||
it('given no matching clusters', () => { | ||
const wrapper: Wrapper<InstanceType<typeof TopLevelMenu>> = mount(TopLevelMenu, { | ||
data: () => ({ clusterFilter: 'whatever' }), | ||
mocks: { | ||
$store: { | ||
getters: { | ||
'management/all': () => [{ nameDisplay: 'something else' }], | ||
...defaultStore | ||
}, | ||
}, | ||
}, | ||
stubs: ['BrandImage', 'nuxt-link'] | ||
}); | ||
|
||
const noResults = wrapper.find('[data-testid="top-level-menu-no-results"]'); | ||
|
||
expect(noResults.exists()).toBe(true); | ||
}); | ||
|
||
it('given no matched pinned clusters', () => { | ||
const wrapper: Wrapper<InstanceType<typeof TopLevelMenu>> = mount(TopLevelMenu, { | ||
data: () => ({ clusterFilter: 'whatever' }), | ||
mocks: { | ||
$store: { | ||
getters: { | ||
'management/all': () => [{ nameDisplay: 'something else', pinned: true }], | ||
...defaultStore | ||
}, | ||
}, | ||
}, | ||
stubs: ['BrandImage', 'nuxt-link'] | ||
}); | ||
|
||
const noResults = wrapper.find('[data-testid="top-level-menu-no-results"]'); | ||
|
||
expect(noResults.exists()).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('should not displays a no results message', () => { | ||
it('given matching clusters', () => { | ||
const search = 'you found me'; | ||
const wrapper: Wrapper<InstanceType<typeof TopLevelMenu>> = mount(TopLevelMenu, { | ||
data: () => ({ clusterFilter: search }), | ||
mocks: { | ||
$store: { | ||
getters: { | ||
'management/all': () => [{ nameDisplay: search }], | ||
...defaultStore | ||
}, | ||
}, | ||
}, | ||
stubs: ['BrandImage', 'nuxt-link'] | ||
}); | ||
|
||
const noResults = wrapper.find('[data-testid="top-level-menu-no-results"]'); | ||
|
||
expect(wrapper.vm.clustersFiltered).toHaveLength(1); | ||
expect(noResults.exists()).toBe(false); | ||
}); | ||
|
||
it('given clusters with status pinned', () => { | ||
const search = 'you found me'; | ||
const wrapper: Wrapper<InstanceType<typeof TopLevelMenu>> = mount(TopLevelMenu, { | ||
data: () => ({ clusterFilter: search }), | ||
mocks: { | ||
$store: { | ||
getters: { | ||
'management/all': () => [{ nameDisplay: search, pinned: true }], | ||
...defaultStore | ||
}, | ||
}, | ||
}, | ||
stubs: ['BrandImage', 'nuxt-link'] | ||
}); | ||
|
||
const noResults = wrapper.find('[data-testid="top-level-menu-no-results"]'); | ||
|
||
expect(wrapper.vm.pinFiltered).toHaveLength(1); | ||
expect(noResults.exists()).toBe(false); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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