UNPKG

@birhaus/test-utils

Version:

BIRHAUS v3.0 Radical Minimalist Testing Framework - Glass morphism validators, generous spacing tests, and v3 component validation utilities

103 lines (101 loc) 3.5 kB
/** * BIRHAUS Undo Pattern Validator * * Testing utilities for BIRHAUS Principle #5: "Undo over confirm" * * Features: * - Confirmation dialog detection (anti-pattern) * - Undo functionality validation * - Undo timeout testing * - Destructive action pattern verification * - Spanish-first undo messaging */ interface UndoPatternViolation { type: 'confirmation-dialog' | 'missing-undo' | 'invalid-timeout' | 'poor-undo-ux' | 'missing-spanish'; element: Element; severity: 'minor' | 'moderate' | 'serious' | 'critical'; message: string; messageEs: string; actionType?: 'delete' | 'destructive' | 'irreversible'; birhausPrinciple: number; suggestions: string[]; } interface UndoTestOptions { detectConfirmationDialogs?: boolean; validateUndoPresence?: boolean; validateUndoTimeout?: boolean; validateUndoMessaging?: boolean; defaultUndoTimeout?: number; maxUndoTimeout?: number; minUndoTimeout?: number; destructiveSelectors?: string[]; destructiveTexts?: string[]; requireSpanishUndoMessages?: boolean; confirmationSelectors?: string[]; undoSelectors?: string[]; destructiveActionSelectors?: string[]; } interface UndoTestResult { undoAvailable: boolean; undoTimeout: number; undoMessage: string; undoMessageSpanish: boolean; undoTriggered: boolean; originalState: any; undoState: any; } declare class UndoPatternValidator { private options; private readonly confirmationPatterns; private readonly destructivePatterns; constructor(options?: UndoTestOptions); /** * Validate all undo pattern compliance */ validateAll(container?: HTMLElement): Promise<UndoPatternViolation[]>; /** * Detect confirmation dialogs (anti-pattern) */ detectConfirmationDialogs(container: HTMLElement): UndoPatternViolation[]; /** * Validate undo functionality is present for destructive actions */ validateUndoPresence(container: HTMLElement): UndoPatternViolation[]; /** * Validate undo messaging and timeout settings */ validateUndoMessaging(container: HTMLElement): UndoPatternViolation[]; /** * Test undo functionality for a specific action */ testUndoFunctionality(actionElement: Element, container?: HTMLElement): Promise<UndoTestResult>; private findDestructiveActions; private checkUndoSupport; private getActionType; private hasTimeoutInfo; private hasSpanishUndoMessage; extractUndoTimeout(element: Element): number; private isSpanishUndoMessage; private captureState; private statesEqual; } /** * Test helper functions for undo pattern assertions */ /** * Assert no confirmation dialogs are present */ declare function expectNoConfirmationDialogs(container?: HTMLElement): void; /** * Assert destructive actions have undo functionality */ declare function expectUndoForDestructiveActions(container?: HTMLElement): void; /** * Test undo functionality for a specific action */ declare function expectUndoWorks(actionElement: Element, container?: HTMLElement): Promise<void>; /** * Assert undo timeout is reasonable */ declare function expectReasonableUndoTimeout(undoElement: Element, minMs?: number, maxMs?: number): void; export { UndoPatternValidator, type UndoPatternViolation, type UndoTestOptions, type UndoTestResult, expectNoConfirmationDialogs, expectReasonableUndoTimeout, expectUndoForDestructiveActions, expectUndoWorks };