This commit is contained in:
Bastian Wagner
2024-11-28 11:45:36 +01:00
parent d398b37007
commit 22dc6033c9
25 changed files with 5018 additions and 550 deletions

View File

@@ -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();
}