Files
keyvault/client/src/app/modules/keys/components/archive/archive.component.spec.ts
Bastian Wagner 819af7455b Testing
2024-11-28 16:59:23 +01:00

62 lines
1.9 KiB
TypeScript

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HotToastService, provideHotToastConfig } from '@ngxpert/hot-toast';
import { from, map, of } from 'rxjs';
import { GridReadyEvent } from 'ag-grid-community';
import { MatDialog } from '@angular/material/dialog';
import { ArchiveComponent } from './archive.component';
import { ApiService } from '../../../../shared/api.service';
import { MockApiService } from '../../../../../../mocks/services/mock.api.service';
// Mocking the dependencies
jest.mock('@ngxpert/hot-toast', () => ({
HotToastService: jest.fn(),
}));
describe('ArchiveComponent', () => {
let component: ArchiveComponent;
let fixture: ComponentFixture<ArchiveComponent>;
const mockGridReadyEvent: GridReadyEvent = {
api: { setGridOption: jest.fn(), addEventListener: jest.fn() },
columnApi: { someColumnApiMethod: jest.fn() },
type: 'gridReady',
} as any;
const mockHotToastService = {
observe: jest.fn().mockImplementation(() => ({
loading: 'speichern...',
success: 'Änderungen gespeichert',
error: 'Änderungen konnten nicht gespeichert werden!',
subscribe: jest.fn().mockReturnValue(of([]))
}))
};
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ArchiveComponent, ],
providers: [
{ provide: HotToastService, useValue: mockHotToastService },
{ provide: ApiService, useClass: MockApiService },
]
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(ArchiveComponent);
component = fixture.componentInstance;
fixture.detectChanges();
component.onGridReady(mockGridReadyEvent);
});
it('should create the archive', () => {
expect(component).toBeTruthy();
});
it('should load the data on start', () => {
expect(component['api'].getKeyArchive).toHaveBeenCalled();
});
});