import { TestBed } from '@angular/core/testing'; import { of } from 'rxjs'; import { ApiClientService } from '@boilerplate/api-client'; import { ItemsPageComponent } from './items.page'; describe('ItemsPageComponent', () => { it('keeps the save button disabled while the typed form is invalid', async () => { await TestBed.configureTestingModule({ imports: [ItemsPageComponent], providers: [ { provide: ApiClientService, useValue: { items: () => of({ items: [], total: 0, page: 1, pageSize: 20 }), }, }, ], }).compileComponents(); const fixture = TestBed.createComponent(ItemsPageComponent); fixture.detectChanges(); expect(fixture.componentInstance.form.invalid).toBe(true); fixture.componentInstance.form.controls.name.setValue('Neues Item'); expect(fixture.componentInstance.form.valid).toBe(true); }); it('loads items with pagination parameters and changes pages', async () => { const calls: { search?: string; page?: number; pageSize?: number }[] = []; await TestBed.configureTestingModule({ imports: [ItemsPageComponent], providers: [ { provide: ApiClientService, useValue: { items: (query: { search?: string; page?: number; pageSize?: number } = {}) => { calls.push(query); return of({ items: [ { id: `item-${query.page ?? 1}`, name: 'Item', description: null, status: 'active', version: 1, createdAt: '2026-07-16T08:00:00.000Z', updatedAt: '2026-07-16T08:00:00.000Z', deletedAt: null, }, ], total: 30, page: query.page ?? 1, pageSize: query.pageSize ?? 20, }); }, }, }, ], }).compileComponents(); const fixture = TestBed.createComponent(ItemsPageComponent); fixture.detectChanges(); expect(calls[0]).toEqual({ search: '', page: 1, pageSize: 20 }); fixture.componentInstance.goToPage(2); fixture.detectChanges(); expect(calls[1]).toEqual({ search: '', page: 2, pageSize: 20 }); expect(fixture.componentInstance.page()).toBe(2); expect((fixture.nativeElement as HTMLElement).textContent).toContain('Seite 2 von 2'); }); });