/**
 * Rule: delete-reflects-in-list
 *
 * Mirror of create-reflects-in-list, for the delete path. Seeds an
 * entity via backend POST, asserts it appears in the list, then
 * deletes it via backend DELETE and asserts it disappears. The
 * disappear-after-delete check exercises the full state-sync chain:
 * backend publishes a Deleted event → WebSocket pushes to frontend
 * → useEntitySync invalidates the ['entities', modelName] query key
 * → React Query refetches → the list view re-renders without the
 * deleted row.
 *
 * If any link in that chain is broken (e.g. the mutation hook
 * forgets to invalidate, or the WebSocket bridge drops the event),
 * this test is the one that catches it.
 *
 * One TestCase per seedable model.
 */
import { pickDisplayAttribute, buildSeedData } from './_shared.js';
export const RULE_ID = 'delete-reflects-in-list';
export const deleteReflectsInList = (spec) => {
    const cases = [];
    for (const model of spec.models) {
        const display = pickDisplayAttribute(model);
        if (!display)
            continue;
        const marker = `ct-delete-${model.name}`;
        const seedData = buildSeedData(model, marker);
        if (!seedData)
            continue;
        const displayValue = seedData[display.name];
        if (typeof displayValue !== 'string')
            continue;
        cases.push({
            ruleId: RULE_ID,
            specElement: model.name,
            name: `[${RULE_ID}] deleting a ${model.name} removes it from its list view`,
            steps: [
                { action: 'bootRuntime' },
                { action: 'navigateToModel', modelName: model.name },
                {
                    action: 'createEntity',
                    modelName: model.name,
                    data: seedData,
                    bindAs: '{ id, data: created }',
                    uniqueField: display.name,
                },
                {
                    action: 'expectEntityInList',
                    modelName: model.name,
                    displayExpr: `String(created[${JSON.stringify(display.name)}])`,
                },
                { action: 'deleteEntity', modelName: model.name, idExpr: 'id' },
                {
                    action: 'expectEntityAbsent',
                    modelName: model.name,
                    displayExpr: `String(created[${JSON.stringify(display.name)}])`,
                },
            ],
        });
    }
    return cases;
};
//# sourceMappingURL=delete-reflects-in-list.js.map