frontend-toegevoegd

This commit is contained in:
2026-10-27 15:34:56 +01:00
parent 777d9f199d
commit 02337fafaa
43 changed files with 10548 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
import { TestBed } from '@angular/core/testing';
import { HttpErrorResponse } from '@angular/common/http';
import { of, throwError } from 'rxjs';
import { SchoolApi } from '../core/school-api';
import { EntityEditor } from './entity-editor';
import { EditorTarget } from '../core/api-models';
describe('EntityEditor', () => {
const api = { saveSchool: vi.fn(), saveGroup: vi.fn(), saveDancer: vi.fn(), saveShow: vi.fn() };
beforeEach(() => {
vi.resetAllMocks();
TestBed.configureTestingModule({
imports: [EntityEditor],
providers: [{ provide: SchoolApi, useValue: api }],
});
});
function editor(target: EditorTarget) {
const fixture = TestBed.createComponent(EntityEditor);
fixture.componentRef.setInput('target', target);
fixture.componentRef.setInput('schoolId', 7);
fixture.componentInstance.ngOnInit();
return fixture.componentInstance;
}
it('rejects blank names and invalid age ranges before calling the API', async () => {
const component = editor({ kind: 'group' });
component.name = ' ';
expect(component.validDetails()).toBe(false);
component.name = 'Teens';
component.startAge = 18;
component.endAge = 12;
await component.save();
expect(api.saveGroup).not.toHaveBeenCalled();
component.endAge = 18.5;
expect(component.validDetails()).toBe(false);
});
it('does not accept a future birth date', () => {
const component = editor({ kind: 'dancer' });
component.name = 'Sam';
component.date = '2999-01-01';
expect(component.validDetails()).toBe(false);
});
it('trims the school name and emits saved only after success', async () => {
api.saveSchool.mockReturnValue(of({ id: 0 }));
const component = editor({ kind: 'school' });
component.name = ' Studio ';
const saved = vi.fn();
component.saved.subscribe(saved);
await component.save();
expect(api.saveSchool).toHaveBeenCalledWith({ name: 'Studio' }, undefined);
expect(saved).toHaveBeenCalledOnce();
expect(component.busy()).toBe(false);
});
it('keeps the editor open and preserves input when saving fails', async () => {
api.saveSchool.mockReturnValue(throwError(() => new HttpErrorResponse({ status: 0 })));
const component = editor({ kind: 'school' });
component.name = 'Studio';
const saved = vi.fn();
component.saved.subscribe(saved);
await component.save();
expect(saved).not.toHaveBeenCalled();
expect(component.name).toBe('Studio');
expect(component.error()).toContain('niet bereikbaar');
expect(component.busy()).toBe(false);
});
});