204 WP-NN/RB-NN comments named a closed ticket instead of the code they sit next to. git blame already records history and stays correct when code moves; the comment does not. This sweep removes the reference and keeps the sentence, across 95 files in apps/ and libs/ plus the behaviour-spec generator's header text. Eleven references stay: five story files justify an a11y disable per the README's rule, and one line in a11y.mdx documents that convention. Two sentences needed a rewrite, not a deletion, so the reference's meaning survives its removal. behaviour-spec.mdx is regenerated, not hand-edited. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
138 lines
4.9 KiB
TypeScript
138 lines
4.9 KiB
TypeScript
import { TestBed } from '@angular/core/testing';
|
|
import { describe, it, expect } from 'vitest';
|
|
import { Result, ok } from '@shared/kernel/fp';
|
|
import { BLOB_PRESENTER, BlobPresenter } from '@shared/application/blob-presenter';
|
|
import { StamRow, StamTable, toJson } from '@beheer/domain/stamdata';
|
|
import { StamdataAdapter } from '@beheer/infrastructure/stamdata.adapter';
|
|
import { StamdataStore } from './stamdata.store';
|
|
|
|
const table: StamTable = {
|
|
id: 'professions',
|
|
label: 'Opleiding → beroep',
|
|
temporal: false,
|
|
columns: [
|
|
{ name: 'program', type: 'text', isKey: true, options: [] },
|
|
{ name: 'beroep', type: 'text', isKey: false, options: [] },
|
|
],
|
|
};
|
|
const rows: StamRow[] = [{ program: 'geneeskunde', beroep: 'Arts' }];
|
|
|
|
/** A recording fake of BLOB_PRESENTER — records every call instead of touching the DOM,
|
|
which is what TE-006's seam is for: the store's success path becomes assertable. */
|
|
function fakeBlobPresenter() {
|
|
const opened: Blob[] = [];
|
|
const downloaded: { blob: Blob; filename: string }[] = [];
|
|
const presenter: BlobPresenter = {
|
|
open: (blob) => opened.push(blob),
|
|
download: (blob, filename) => downloaded.push({ blob, filename }),
|
|
};
|
|
return { presenter, opened, downloaded };
|
|
}
|
|
|
|
function setup(blobPresenter?: BlobPresenter): StamdataStore {
|
|
const adapter: Partial<StamdataAdapter> = {
|
|
list: (): Promise<Result<string, StamTable[]>> => Promise.resolve(ok([table])),
|
|
load: (): Promise<Result<string, { table: StamTable; rows: StamRow[] }>> =>
|
|
Promise.resolve(ok({ table, rows: rows.map((r) => ({ ...r })) })),
|
|
};
|
|
TestBed.configureTestingModule({
|
|
providers: [
|
|
{ provide: StamdataAdapter, useValue: adapter },
|
|
...(blobPresenter ? [{ provide: BLOB_PRESENTER, useValue: blobPresenter }] : []),
|
|
],
|
|
});
|
|
return TestBed.inject(StamdataStore);
|
|
}
|
|
|
|
describe('StamdataStore undo/redo', () => {
|
|
it('records a cell edit, undoes and redoes it', async () => {
|
|
const store = setup();
|
|
await store.load();
|
|
expect(store.canUndo()).toBe(false);
|
|
|
|
store.editCell(0, 'beroep', 'Chirurg');
|
|
expect(store.rows()[0]['beroep']).toBe('Chirurg');
|
|
expect(store.canUndo()).toBe(true);
|
|
|
|
store.undo();
|
|
expect(store.rows()[0]['beroep']).toBe('Arts');
|
|
expect(store.canRedo()).toBe(true);
|
|
|
|
store.redo();
|
|
expect(store.rows()[0]['beroep']).toBe('Chirurg');
|
|
expect(store.canRedo()).toBe(false);
|
|
});
|
|
|
|
it('records addRow and undoes it', async () => {
|
|
const store = setup();
|
|
await store.load();
|
|
store.addRow();
|
|
expect(store.rows().length).toBe(2);
|
|
store.undo();
|
|
expect(store.rows().length).toBe(1);
|
|
});
|
|
|
|
it('clears history when switching table', async () => {
|
|
const store = setup();
|
|
await store.load();
|
|
store.addRow();
|
|
expect(store.canUndo()).toBe(true);
|
|
await store.selectTable('professions');
|
|
expect(store.canUndo()).toBe(false);
|
|
});
|
|
});
|
|
|
|
// --- TE-006: download() ends in BLOB_PRESENTER.download, not raw DOM calls,
|
|
// so the seam makes both the guard's branches and the success path assertable. ---
|
|
|
|
describe('StamdataStore.download', () => {
|
|
it('does not call the presenter while the two-clause guard blocks (nothing dirty yet)', async () => {
|
|
// Given a freshly loaded table with no edits — canDownload() is false.
|
|
const { presenter, downloaded } = fakeBlobPresenter();
|
|
const store = setup(presenter);
|
|
await store.load();
|
|
expect(store.canDownload()).toBe(false);
|
|
|
|
// When download() is called...
|
|
store.download();
|
|
|
|
// Then the guard's true branch fires and the presenter is never reached.
|
|
expect(downloaded).toHaveLength(0);
|
|
});
|
|
|
|
it('does not call the presenter while previewing a date, even with edits', async () => {
|
|
// Given a loaded table with a real edit, but a preview date filter active.
|
|
const { presenter, downloaded } = fakeBlobPresenter();
|
|
const store = setup(presenter);
|
|
await store.load();
|
|
store.editCell(0, 'beroep', 'Chirurg');
|
|
store.setPreviewDate('2024-01-01');
|
|
expect(store.canDownload()).toBe(false);
|
|
|
|
// When download() is called...
|
|
store.download();
|
|
|
|
// Then the guard still blocks it.
|
|
expect(downloaded).toHaveLength(0);
|
|
});
|
|
|
|
it("passes toJson(...)'s exact output and the table id as the filename (success path)", async () => {
|
|
// Given a loaded table with a valid, dirty edit — canDownload() is true.
|
|
const { presenter, downloaded } = fakeBlobPresenter();
|
|
const store = setup(presenter);
|
|
await store.load();
|
|
store.editCell(0, 'beroep', 'Chirurg');
|
|
expect(store.canDownload()).toBe(true);
|
|
const expectedJson = toJson(store.table()!, store.rows());
|
|
|
|
// When download() is called...
|
|
store.download();
|
|
|
|
// Then the presenter receives exactly one call, with toJson's output reaching the
|
|
// file byte-for-byte and the table id as the file name.
|
|
expect(downloaded).toHaveLength(1);
|
|
expect(downloaded[0].filename).toBe('professions.json');
|
|
await expect(downloaded[0].blob.text()).resolves.toBe(expectedJson);
|
|
});
|
|
});
|