Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ describe('ListViewComponent', () => {
listView: {
fields: [],
},
detailView: {
fields: [],
},
},
},
})) as any;
Expand Down Expand Up @@ -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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down