-
Notifications
You must be signed in to change notification settings - Fork 302
Added the ability to remove namespaces from projects entirely, not just move them between projects. #16334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Added the ability to remove namespaces from projects entirely, not just move them between projects. #16334
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,223 @@ | ||
| import { shallowMount, VueWrapper } from '@vue/test-utils'; | ||
| import MoveNamespaceDialog from '@shell/dialog/MoveNamespaceDialog.vue'; | ||
|
|
||
| const t = (key: string): string => key; | ||
|
|
||
| describe('component: MoveNamespaceDialog', () => { | ||
| let wrapper: VueWrapper<any>; | ||
|
|
||
| const mockProjects = [ | ||
| { | ||
| shortId: 'p-abc123', | ||
| nameDisplay: 'Project A', | ||
| spec: { clusterName: 'local' } | ||
| }, | ||
| { | ||
| shortId: 'p-def456', | ||
| nameDisplay: 'Project B', | ||
| spec: { clusterName: 'local' } | ||
| }, | ||
| { | ||
| shortId: 'p-other', | ||
| nameDisplay: 'Other Cluster Project', | ||
| spec: { clusterName: 'other-cluster' } | ||
| } | ||
| ]; | ||
|
|
||
| const createMockNamespace = (projectId: string | null = null) => { | ||
| const namespace: any = { | ||
| nameDisplay: 'test-namespace', | ||
| projectId, | ||
| project: projectId ? { shortId: projectId } : null, | ||
| setLabel: jest.fn(), | ||
| setAnnotation: jest.fn(), | ||
| save: jest.fn().mockResolvedValue({}), | ||
| }; | ||
|
|
||
| return namespace; | ||
| }; | ||
|
|
||
| const mountComponent = (propsData = {}, options = {}) => { | ||
| const store = { | ||
| dispatch: jest.fn().mockResolvedValue(mockProjects), | ||
| getters: { currentCluster: { id: 'local' } } | ||
| }; | ||
|
|
||
| const defaultProps = { | ||
| resources: [createMockNamespace('p-abc123')], | ||
| movingCb: jest.fn(), | ||
| registerBackgroundClosing: jest.fn(), | ||
| }; | ||
|
|
||
| return shallowMount(MoveNamespaceDialog, { | ||
| propsData: { | ||
| ...defaultProps, | ||
| ...propsData, | ||
| }, | ||
| global: { | ||
| mocks: { | ||
| $store: store, | ||
| t, | ||
| }, | ||
| }, | ||
| ...options, | ||
| }); | ||
| }; | ||
|
|
||
| afterEach(() => { | ||
| if (wrapper) { | ||
| wrapper.unmount(); | ||
| } | ||
| }); | ||
|
|
||
| describe('projectOptions', () => { | ||
| it('should include "None" option as first item', async() => { | ||
| wrapper = mountComponent(); | ||
| await wrapper.vm.$options.fetch.call(wrapper.vm); | ||
|
|
||
| const options = wrapper.vm.projectOptions; | ||
|
|
||
| expect(options[0]).toStrictEqual({ | ||
| value: '', | ||
| label: 'moveModal.noProject' | ||
| }); | ||
| }); | ||
|
|
||
| it('should include projects from current cluster', async() => { | ||
| // Use a namespace not in any project so no projects get excluded | ||
| const namespace = createMockNamespace(null); | ||
|
|
||
| wrapper = mountComponent({ resources: [namespace] }); | ||
| await wrapper.vm.$options.fetch.call(wrapper.vm); | ||
|
|
||
| const options = wrapper.vm.projectOptions; | ||
| const projectLabels = options.map((o: any) => o.label); | ||
|
|
||
| expect(projectLabels).toContain('Project A'); | ||
| expect(projectLabels).toContain('Project B'); | ||
| }); | ||
|
|
||
| it('should exclude projects from other clusters', async() => { | ||
| wrapper = mountComponent(); | ||
| await wrapper.vm.$options.fetch.call(wrapper.vm); | ||
|
|
||
| const options = wrapper.vm.projectOptions; | ||
| const projectLabels = options.map((o: any) => o.label); | ||
|
|
||
| expect(projectLabels).not.toContain('Other Cluster Project'); | ||
| }); | ||
|
|
||
| it('should exclude current project of namespaces being moved', async() => { | ||
| const namespace = createMockNamespace('p-abc123'); | ||
|
|
||
| wrapper = mountComponent({ resources: [namespace] }); | ||
| await wrapper.vm.$options.fetch.call(wrapper.vm); | ||
|
|
||
| const options = wrapper.vm.projectOptions; | ||
| const projectValues = options.map((o: any) => o.value); | ||
|
|
||
| expect(projectValues).not.toContain('p-abc123'); | ||
| expect(projectValues).toContain('p-def456'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('targetProject default value', () => { | ||
| it('should default to empty string (None option)', () => { | ||
| wrapper = mountComponent(); | ||
|
|
||
| expect(wrapper.vm.targetProject).toBe(''); | ||
| }); | ||
| }); | ||
|
|
||
| describe('move button disabled state', () => { | ||
| it('should be enabled when targetProject is empty string (None)', () => { | ||
| wrapper = mountComponent(); | ||
| wrapper.vm.targetProject = ''; | ||
|
|
||
| // The button should be enabled when targetProject !== null | ||
| expect(wrapper.vm.targetProject === null).toBe(false); | ||
| }); | ||
|
|
||
| it('should be enabled when targetProject is a project id', () => { | ||
| wrapper = mountComponent(); | ||
| wrapper.vm.targetProject = 'p-def456'; | ||
|
|
||
| expect(wrapper.vm.targetProject === null).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('move method', () => { | ||
| it('should clear labels and annotations when targetProject is empty (None)', async() => { | ||
| const namespace = createMockNamespace('p-abc123'); | ||
|
|
||
| wrapper = mountComponent({ resources: [namespace] }); | ||
| await wrapper.vm.$options.fetch.call(wrapper.vm); | ||
|
|
||
| wrapper.vm.targetProject = ''; | ||
|
|
||
| const finish = jest.fn(); | ||
|
|
||
| await wrapper.vm.move(finish); | ||
|
|
||
| expect(namespace.setLabel).toHaveBeenCalledWith('field.cattle.io/projectId', null); | ||
| expect(namespace.setAnnotation).toHaveBeenCalledWith('field.cattle.io/projectId', null); | ||
| expect(namespace.save).toHaveBeenCalledWith(); | ||
| expect(finish).toHaveBeenCalledWith(true); | ||
| }); | ||
|
|
||
| it('should set labels and annotations when moving to a project', async() => { | ||
| const namespace = createMockNamespace('p-abc123'); | ||
|
|
||
| wrapper = mountComponent({ resources: [namespace] }); | ||
| await wrapper.vm.$options.fetch.call(wrapper.vm); | ||
|
|
||
| wrapper.vm.targetProject = 'p-def456'; | ||
|
|
||
| const finish = jest.fn(); | ||
|
|
||
| await wrapper.vm.move(finish); | ||
|
|
||
| expect(namespace.setLabel).toHaveBeenCalledWith('field.cattle.io/projectId', 'p-def456'); | ||
| expect(namespace.setAnnotation).toHaveBeenCalledWith('field.cattle.io/projectId', 'local:p-def456'); | ||
| expect(namespace.save).toHaveBeenCalledWith(); | ||
| expect(finish).toHaveBeenCalledWith(true); | ||
| }); | ||
|
|
||
| it('should handle multiple namespaces', async() => { | ||
| const namespace1 = createMockNamespace('p-abc123'); | ||
| const namespace2 = createMockNamespace('p-abc123'); | ||
|
|
||
| wrapper = mountComponent({ resources: [namespace1, namespace2] }); | ||
| await wrapper.vm.$options.fetch.call(wrapper.vm); | ||
|
|
||
| wrapper.vm.targetProject = ''; | ||
|
|
||
| const finish = jest.fn(); | ||
|
|
||
| await wrapper.vm.move(finish); | ||
|
|
||
| expect(namespace1.setLabel).toHaveBeenCalledWith('field.cattle.io/projectId', null); | ||
| expect(namespace1.setAnnotation).toHaveBeenCalledWith('field.cattle.io/projectId', null); | ||
| expect(namespace2.setLabel).toHaveBeenCalledWith('field.cattle.io/projectId', null); | ||
| expect(namespace2.setAnnotation).toHaveBeenCalledWith('field.cattle.io/projectId', null); | ||
| expect(namespace1.save).toHaveBeenCalledWith(); | ||
| expect(namespace2.save).toHaveBeenCalledWith(); | ||
| }); | ||
|
|
||
| it('should call finish with false when save fails', async() => { | ||
| const namespace = createMockNamespace('p-abc123'); | ||
|
|
||
| jest.spyOn(namespace, 'save').mockImplementation().mockRejectedValue(new Error('Save failed')); | ||
| wrapper = mountComponent({ resources: [namespace] }); | ||
| await wrapper.vm.$options.fetch.call(wrapper.vm); | ||
|
|
||
| wrapper.vm.targetProject = ''; | ||
|
|
||
| const finish = jest.fn(); | ||
|
|
||
| await wrapper.vm.move(finish); | ||
|
|
||
| expect(finish).toHaveBeenCalledWith(false); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.