unit tests

This commit is contained in:
Bastian Wagner
2026-02-13 15:12:54 +01:00
parent ea947caf54
commit 2eafa21baf
20 changed files with 662 additions and 8064 deletions

View File

@@ -1,34 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RemoveManagerPopupComponent } from './remove-manager-popup.component';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
describe('RemoveManagerPopupComponent', () => {
let component: RemoveManagerPopupComponent;
let fixture: ComponentFixture<RemoveManagerPopupComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [RemoveManagerPopupComponent],
providers: [
{
provide: MatDialogRef,
useValue: []
},
{
provide: MAT_DIALOG_DATA,
useValue: ''
},
]
})
.compileComponents();
fixture = TestBed.createComponent(RemoveManagerPopupComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -1,68 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SystemManagerComponent } from './system-manager.component';
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { AgGridAngular } from 'ag-grid-angular';
import { ApiService } from '../../../../shared/api.service';
import { HotToastService } from '@ngxpert/hot-toast';
import { MockApiService } from '../../../../../../mocks/services/mock.api.service';
import { GridReadyEvent } from 'ag-grid-community';
import { AuthService } from '../../../../core/auth/auth.service';
import { MockAuthService } from '../../../../../../mocks/services/mock.auth.service';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('SystemManagerComponent', () => {
let component: SystemManagerComponent;
let fixture: ComponentFixture<SystemManagerComponent>;
let api: ApiService;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SystemManagerComponent, AgGridAngular, MatDialogModule, NoopAnimationsModule],
providers: [
HotToastService,
{ provide: ApiService, useClass: MockApiService },
{
provide: MatDialogRef,
useValue: []
},
{
provide: MAT_DIALOG_DATA,
useValue: []
},
{ provide: AuthService, useClass: MockAuthService }
]
})
.compileComponents();
fixture = TestBed.createComponent(SystemManagerComponent);
component = fixture.componentInstance;
api = component['api']
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should initialize gridApi and gridColumnApi on gridReady and fill data', () => {
// Mock des GridReadyEvent
let mockData = [{ id: 1, name: 'Test' }];
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(api.getSystemManagers).toHaveBeenCalled();
expect(component.gridApi.setGridOption).toHaveBeenCalled();
});
});

View File

@@ -1,66 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { CreateSystemComponent } from './create.component';
import { ApiService } from '../../../shared/api.service';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { of, throwError } from 'rxjs';
import { HotToastService } from '@ngxpert/hot-toast';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MockApiService } from '../../../../../mocks/services/mock.api.service';
describe('CreateComponent', () => {
let component: CreateSystemComponent;
let fixture: ComponentFixture<CreateSystemComponent>;
let apiService: ApiService;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [CreateSystemComponent, NoopAnimationsModule, FormsModule, ReactiveFormsModule],
providers: [
HotToastService,
{ provide: ApiService, useClass: MockApiService },
{
provide: MatDialogRef,
useValue: []
},
{
provide: MAT_DIALOG_DATA,
useValue: []
}
]
})
.compileComponents();
fixture = TestBed.createComponent(CreateSystemComponent);
component = fixture.componentInstance;
apiService = component['api'];
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should call apiService.createSystem when createSystem is called', () => {
expect(apiService.createSystem).not.toHaveBeenCalled();
component.createForm.setValue({ name: 'Test System' });
component.save();
expect(apiService.createSystem).toHaveBeenCalledWith({ name: 'Test System' });
});
it('should handle success response correctly', () => {
jest.spyOn(apiService, 'createSystem').mockReturnValue(of({}));
const toastSpy = jest.spyOn(component['toast'], 'observe');
component.createForm.setValue({ name: 'Test System' });
component.save();
expect(toastSpy).toHaveBeenCalled();
});
it('should handle error response correctly', () => {
jest.spyOn(apiService, 'createSystem').mockReturnValue(throwError(() => new Error('Test Error')));
const toastSpy = jest.spyOn(component['toast'], 'observe');
component.save();
expect(toastSpy).toHaveBeenCalled();
});
});

View File

@@ -1,54 +0,0 @@
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('SystemcomponentComponent', () => {
let component: SystemComponent;
let mockApiService: MockApiService;
beforeEach(async () => {
mockApiService = new MockApiService();
await TestBed.configureTestingModule({
imports: [SystemComponent],
providers: [
{ provide: ApiService, useValue: mockApiService }
]
}).compileComponents();
const fixture = TestBed.createComponent(SystemComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
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();
}