diff --git a/projects/wc/src/app/components/generic-ui/list-view/list-view.component.spec.ts b/projects/wc/src/app/components/generic-ui/list-view/list-view.component.spec.ts index 4c52d77..57d1120 100644 --- a/projects/wc/src/app/components/generic-ui/list-view/list-view.component.spec.ts +++ b/projects/wc/src/app/components/generic-ui/list-view/list-view.component.spec.ts @@ -55,6 +55,9 @@ describe('ListViewComponent', () => { listView: { fields: [], }, + detailView: { + fields: [], + }, }, }, })) as any; @@ -128,6 +131,59 @@ describe('ListViewComponent', () => { expect(navSpy).toHaveBeenCalledWith('res1'); }); + it('should not navigate when detailView is not defined', () => { + const newFixture = TestBed.createComponent(ListViewComponent); + const newComponent = newFixture.componentInstance; + + newComponent.context = (() => ({ + resourceDefinition: { + plural: 'clusters', + kind: 'Cluster', + group: 'core.k8s.io', + ui: { + listView: { + fields: [], + }, + }, + }, + })) as any; + + const resource = { metadata: { name: 'res1' } }; + const navSpy = jest.fn(); + newComponent.LuigiClient = (() => ({ + linkManager: () => ({ + navigate: navSpy, + }), + })) as any; + + newComponent.navigateToResource(resource as any); + expect(navSpy).not.toHaveBeenCalled(); + }); + + it('should not navigate when ui is not defined', () => { + const newFixture = TestBed.createComponent(ListViewComponent); + const newComponent = newFixture.componentInstance; + + newComponent.context = (() => ({ + resourceDefinition: { + plural: 'clusters', + kind: 'Cluster', + group: 'core.k8s.io', + }, + })) as any; + + const resource = { metadata: { name: 'res1' } }; + const navSpy = jest.fn(); + newComponent.LuigiClient = (() => ({ + linkManager: () => ({ + navigate: navSpy, + }), + })) as any; + + newComponent.navigateToResource(resource as any); + expect(navSpy).not.toHaveBeenCalled(); + }); + it('should open create resource modal', () => { const openSpy = jest.fn(); (component as any).createModal = () => ({ open: openSpy }); diff --git a/projects/wc/src/app/components/generic-ui/list-view/list-view.component.ts b/projects/wc/src/app/components/generic-ui/list-view/list-view.component.ts index bcde99f..e1b426e 100644 --- a/projects/wc/src/app/components/generic-ui/list-view/list-view.component.ts +++ b/projects/wc/src/app/components/generic-ui/list-view/list-view.component.ts @@ -169,6 +169,11 @@ export class ListViewComponent implements OnInit { } navigateToResource(resource: Resource) { + const resourceDefinition = this.getResourceDefinition(); + if (!resourceDefinition.ui?.detailView) { + return; + } + if (!resource.metadata.name) { this.LuigiClient().uxManager().showAlert({ text: 'Resource name is not defined',