Skip to content

Commit 50766aa

Browse files
committed
feat: add check for detailView property before navigation
1 parent 3fef38d commit 50766aa

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

projects/wc/src/app/components/generic-ui/list-view/list-view.component.spec.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ describe('ListViewComponent', () => {
5555
listView: {
5656
fields: [],
5757
},
58+
detailView: {
59+
fields: [],
60+
},
5861
},
5962
},
6063
})) as any;
@@ -128,6 +131,59 @@ describe('ListViewComponent', () => {
128131
expect(navSpy).toHaveBeenCalledWith('res1');
129132
});
130133

134+
it('should not navigate when detailView is not defined', () => {
135+
const newFixture = TestBed.createComponent(ListViewComponent);
136+
const newComponent = newFixture.componentInstance;
137+
138+
newComponent.context = (() => ({
139+
resourceDefinition: {
140+
plural: 'clusters',
141+
kind: 'Cluster',
142+
group: 'core.k8s.io',
143+
ui: {
144+
listView: {
145+
fields: [],
146+
},
147+
},
148+
},
149+
})) as any;
150+
151+
const resource = { metadata: { name: 'res1' } };
152+
const navSpy = jest.fn();
153+
newComponent.LuigiClient = (() => ({
154+
linkManager: () => ({
155+
navigate: navSpy,
156+
}),
157+
})) as any;
158+
159+
newComponent.navigateToResource(resource as any);
160+
expect(navSpy).not.toHaveBeenCalled();
161+
});
162+
163+
it('should not navigate when ui is not defined', () => {
164+
const newFixture = TestBed.createComponent(ListViewComponent);
165+
const newComponent = newFixture.componentInstance;
166+
167+
newComponent.context = (() => ({
168+
resourceDefinition: {
169+
plural: 'clusters',
170+
kind: 'Cluster',
171+
group: 'core.k8s.io',
172+
},
173+
})) as any;
174+
175+
const resource = { metadata: { name: 'res1' } };
176+
const navSpy = jest.fn();
177+
newComponent.LuigiClient = (() => ({
178+
linkManager: () => ({
179+
navigate: navSpy,
180+
}),
181+
})) as any;
182+
183+
newComponent.navigateToResource(resource as any);
184+
expect(navSpy).not.toHaveBeenCalled();
185+
});
186+
131187
it('should open create resource modal', () => {
132188
const openSpy = jest.fn();
133189
(component as any).createModal = () => ({ open: openSpy });

projects/wc/src/app/components/generic-ui/list-view/list-view.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ export class ListViewComponent implements OnInit {
169169
}
170170

171171
navigateToResource(resource: Resource) {
172+
const resourceDefinition = this.getResourceDefinition();
173+
if (!resourceDefinition.ui?.detailView) {
174+
return;
175+
}
176+
172177
if (!resource.metadata.name) {
173178
this.LuigiClient().uxManager().showAlert({
174179
text: 'Resource name is not defined',

0 commit comments

Comments
 (0)