@birhaus/test-utils
Version:
BIRHAUS Testing & Validation Framework - Comprehensive testing utilities for cognitive load, accessibility, and BIRHAUS principle compliance
117 lines (115 loc) • 3.54 kB
TypeScript
/**
* BIRHAUS Miller's Law Validator
*
* Automated testing utilities to validate Miller's Law (7±2) compliance
* across all BIRHAUS components and applications.
*
* Features:
* - Navigation item counting and validation
* - Form field cognitive load analysis
* - Select option overflow detection
* - Tab count validation (4-3-1 rule)
* - Real-time cognitive load monitoring
*/
interface MillersLawViolation {
type: 'navigation' | 'form' | 'select' | 'tabs' | 'actions';
element: Element;
count: number;
maxRecommended: number;
severity: 'low' | 'medium' | 'high' | 'critical';
message: string;
messageEs: string;
birhausPrinciple: number;
suggestions: string[];
}
interface MillersLawTestOptions {
maxNavigationItems?: number;
maxFormFields?: number;
maxSelectOptions?: number;
maxTabs?: number;
maxActions?: number;
strict?: boolean;
includeDisabled?: boolean;
checkHidden?: boolean;
navigationSelector?: string;
formSelector?: string;
selectSelector?: string;
tabSelector?: string;
actionSelector?: string;
}
declare class MillersLawValidator {
private options;
constructor(options?: MillersLawTestOptions);
/**
* Validate all Miller's Law compliance issues in the current DOM
*/
validateAll(container?: HTMLElement): MillersLawViolation[];
/**
* Validate navigation items (BIRHAUS Principle #1)
*/
validateNavigation(container?: HTMLElement): MillersLawViolation[];
/**
* Validate form field counts (BIRHAUS Principle #4)
*/
validateForms(container?: HTMLElement): MillersLawViolation[];
/**
* Validate select option counts
*/
validateSelects(container?: HTMLElement): MillersLawViolation[];
/**
* Validate tab counts (BIRHAUS 4-3-1 Rule)
*/
validateTabs(container?: HTMLElement): MillersLawViolation[];
/**
* Validate action button counts
*/
validateActions(container?: HTMLElement): MillersLawViolation[];
/**
* Get navigation items from a navigation element
*/
private getNavigationItems;
/**
* Get form fields from a form element
*/
private getFormFields;
/**
* Get options from a select element
*/
private getSelectOptions;
/**
* Get tabs from a tab container
*/
private getTabs;
/**
* Get action buttons from a container
*/
private getActions;
/**
* Filter elements based on options (hidden, disabled, etc.)
*/
private filterElements;
/**
* Calculate severity based on how much the count exceeds the limit
*/
private getSeverity;
}
/**
* Test helper functions for common assertions
*/
/**
* Assert that Miller's Law is followed for navigation
*/
declare function expectNavigationCompliance(container?: HTMLElement, maxItems?: number): void;
/**
* Assert that forms follow Miller's Law for field count
*/
declare function expectFormCompliance(container?: HTMLElement, maxFields?: number): void;
/**
* Assert that the 4-3-1 rule is followed for tabs
*/
declare function expectTabCompliance(container?: HTMLElement, maxTabs?: number): void;
/**
* Assert overall Miller's Law compliance
*/
declare function expectMillersLawCompliance(container?: HTMLElement, options?: MillersLawTestOptions): void;
export { type MillersLawTestOptions, MillersLawValidator, type MillersLawViolation, expectFormCompliance, expectMillersLawCompliance, expectNavigationCompliance, expectTabCompliance };