testing
This commit is contained in:
@@ -1,23 +1,54 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { SystemComponent } from './system.component';
|
||||
import { ApiService } from '../../shared/api.service';
|
||||
import { GridReadyEvent } from 'ag-grid-community';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
describe('SystemComponent', () => {
|
||||
describe('SystemcomponentComponent', () => {
|
||||
let component: SystemComponent;
|
||||
let fixture: ComponentFixture<SystemComponent>;
|
||||
let mockApiService: MockApiService;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockApiService = new MockApiService();
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [SystemComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(SystemComponent);
|
||||
imports: [SystemComponent],
|
||||
providers: [
|
||||
{ provide: ApiService, useValue: mockApiService }
|
||||
]
|
||||
}).compileComponents();
|
||||
const fixture = TestBed.createComponent(SystemComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
it('should create the SystemComponent', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
|
||||
it('should initialize gridApi and gridColumnApi on gridReady and fill data', () => {
|
||||
// Mock des GridReadyEvent
|
||||
let mockData = [{ id: 1, name: 'Test' }];
|
||||
mockApiService.getSystems.mockReturnValue(of(mockData));
|
||||
const mockGridReadyEvent: GridReadyEvent = {
|
||||
api: { setGridOption: jest.fn() },
|
||||
columnApi: { someColumnApiMethod: jest.fn() },
|
||||
type: 'gridReady',
|
||||
} as any;
|
||||
|
||||
// Methode aufrufen
|
||||
component.onGridReady(mockGridReadyEvent);
|
||||
|
||||
// Assertions
|
||||
expect(component.gridApi).toBe(mockGridReadyEvent.api);
|
||||
expect(mockApiService.getSystems).toHaveBeenCalled();
|
||||
expect(component.gridApi.setGridOption).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
class MockApiService {
|
||||
getSystems = jest.fn();
|
||||
}
|
||||
Reference in New Issue
Block a user