|
|
|
|
@@ -1,51 +1,31 @@
|
|
|
|
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
|
|
|
import { KeysComponent } from './keys.component';
|
|
|
|
|
import { HotToastService, provideHotToastConfig } from '@ngxpert/hot-toast';
|
|
|
|
|
import { from, map, of } from 'rxjs';
|
|
|
|
|
import { HotToastService } from '@ngxpert/hot-toast';
|
|
|
|
|
import { of } from 'rxjs';
|
|
|
|
|
import { ApiService } from '../../shared/api.service';
|
|
|
|
|
import { GridReadyEvent } from 'ag-grid-community';
|
|
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
|
|
|
import { CreateKeyComponent } from './create/create.component';
|
|
|
|
|
import { MockApiService } from '../../../mocks/services/mock.api.service';
|
|
|
|
|
import { MockApiService } from '../../../../mocks/services/mock.api.service';
|
|
|
|
|
|
|
|
|
|
// Mocking the dependencies
|
|
|
|
|
jest.mock('@ngxpert/hot-toast', () => ({
|
|
|
|
|
HotToastService: jest.fn(),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
describe('KeysComponent', () => {
|
|
|
|
|
let component: KeysComponent;
|
|
|
|
|
let fixture: ComponentFixture<KeysComponent>;
|
|
|
|
|
|
|
|
|
|
const mockGridReadyEvent: GridReadyEvent = {
|
|
|
|
|
api: { setGridOption: jest.fn(), addEventListener: jest.fn() },
|
|
|
|
|
api: { setGridOption: jest.fn(), addEventListener: jest.fn(), getGridOption: 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([]))
|
|
|
|
|
}))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mockMatDialog = {
|
|
|
|
|
open: jest.fn().mockReturnValue({
|
|
|
|
|
afterClosed: jest.fn().mockReturnValue(of(true)),
|
|
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
await TestBed.configureTestingModule({
|
|
|
|
|
imports: [KeysComponent, ],
|
|
|
|
|
providers: [
|
|
|
|
|
{ provide: HotToastService, useValue: mockHotToastService },
|
|
|
|
|
{ provide: ApiService, useClass: MockApiService },
|
|
|
|
|
{ provide: MatDialog, useValue: mockMatDialog },
|
|
|
|
|
{ provide: MatDialog, useClass: MockMatDialog },
|
|
|
|
|
HotToastService
|
|
|
|
|
]
|
|
|
|
|
}).compileComponents();
|
|
|
|
|
});
|
|
|
|
|
@@ -78,7 +58,8 @@ describe('KeysComponent', () => {
|
|
|
|
|
expect(component['api'].deleteKey).toHaveBeenCalledWith(keyId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it.skip('should call updateKey on cellEditEnd when a value is changed', () => {
|
|
|
|
|
it('should call updateKey on cellEditEnd when a value is changed', () => {
|
|
|
|
|
|
|
|
|
|
const mockEvent = {
|
|
|
|
|
data: { id: '1', name: 'Old Name' },
|
|
|
|
|
oldValue: 'Old Name',
|
|
|
|
|
@@ -100,5 +81,29 @@ describe('KeysComponent', () => {
|
|
|
|
|
expect(component['api'].updateKey).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should reload Keys after creation', () => {
|
|
|
|
|
component['dialog'].open = jest.fn().mockReturnValue({
|
|
|
|
|
afterClosed: jest.fn().mockReturnValue(of(true)),
|
|
|
|
|
})
|
|
|
|
|
component.openCreateKey();
|
|
|
|
|
expect(component['dialog'].open).toHaveBeenCalled();
|
|
|
|
|
expect(component['api'].getKeys).toHaveBeenCalledTimes(2)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should not reload Keys after cancellation', () => {
|
|
|
|
|
component['dialog'].open = jest.fn().mockReturnValue({
|
|
|
|
|
afterClosed: jest.fn().mockReturnValue(of(null)),
|
|
|
|
|
})
|
|
|
|
|
component.openCreateKey();
|
|
|
|
|
expect(component['dialog'].open).toHaveBeenCalled();
|
|
|
|
|
expect(component['api'].getKeys).toHaveBeenCalledTimes(1)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
class MockMatDialog {
|
|
|
|
|
open = jest.fn().mockReturnValue({
|
|
|
|
|
afterClosed: jest.fn().mockReturnValue(of(true)),
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|