Skip to content

Commit c5d0d4c

Browse files
makdenissmakdeniss
authored andcommitted
fix: fix code coverage (#339)
1 parent c412cdc commit c5d0d4c

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

projects/wc/src/app/components/generic-ui/list-view/delete-resource-confirmation-modal/delete-resource-modal.component.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
44
import { ComponentFixture, TestBed } from '@angular/core/testing';
55
import { ReactiveFormsModule } from '@angular/forms';
66

7-
// jest.mock('@ui5/webcomponents-ngx', () => ({}), { virtual: true });
8-
97
describe('DeleteResourceModalComponent', () => {
108
let component: DeleteResourceModalComponent;
119
let fixture: ComponentFixture<DeleteResourceModalComponent>;

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { LuigiCoreService } from '@openmfp/portal-ui-lib';
33
import { ResourceService } from '@platform-mesh/portal-ui-lib/services';
4-
import { of } from 'rxjs';
4+
import { of, throwError } from 'rxjs';
55
import { ListViewComponent } from './list-view.component';
66

77
describe('ListViewComponent', () => {
@@ -73,6 +73,16 @@ describe('ListViewComponent', () => {
7373
expect(mockLuigiCoreService.showAlert).not.toHaveBeenCalled();
7474
});
7575

76+
it('should show alert when delete errors', () => {
77+
const resource = { metadata: { name: 'bad' } } as any;
78+
mockResourceService.delete.mockReturnValueOnce(throwError(() => new Error('boom')));
79+
component.delete(resource);
80+
expect(mockLuigiCoreService.showAlert).toHaveBeenCalled();
81+
const callArg = mockLuigiCoreService.showAlert.mock.calls[0][0];
82+
expect(callArg.text).toContain('bad');
83+
expect(callArg.type).toBe('error');
84+
});
85+
7686
it('should create a resource', () => {
7787
const resource = { metadata: { name: 'test' } };
7888

@@ -93,6 +103,25 @@ describe('ListViewComponent', () => {
93103
expect(navSpy).toHaveBeenCalledWith('res1');
94104
});
95105

106+
it('should open create resource modal', () => {
107+
const openSpy = jest.fn();
108+
(component as any).createModal = () => ({ open: openSpy });
109+
component.openCreateResourceModal();
110+
expect(openSpy).toHaveBeenCalled();
111+
});
112+
113+
it('should open delete resource modal and stop event propagation', () => {
114+
const event = { stopPropagation: jest.fn() } as any;
115+
const resource = { metadata: { name: 'to-delete' } } as any;
116+
const openSpy = jest.fn();
117+
(component as any).deleteModal = () => ({ open: openSpy });
118+
119+
component.openDeleteResourceModal(event, resource);
120+
121+
expect(event.stopPropagation).toHaveBeenCalled();
122+
expect(openSpy).toHaveBeenCalledWith(resource);
123+
});
124+
96125
it('should check create view fields existence', () => {
97126
component.resourceDefinition.ui.createView = {
98127
fields: [{ property: 'any' }],

0 commit comments

Comments
 (0)