# Data Test ID Implementation Guide ## Overview To make our Playwright tests more reliable and maintainable, we should add `data-testid` attributes to key UI elements. This prevents tests from breaking when CSS classes or text content changes. ## Current Test Status ✅ **Working Tests** (using current selectors): - `smoke.spec.ts` - Basic functionality validation - `auth-realistic.spec.ts` - Authentication flows using form elements ⚠️ **Enhanced Tests** (require data-testid attributes): - `auth.spec.ts` - Full authentication suite - `navigation.spec.ts` - Navigation and routing - `theme.spec.ts` - Theme switching - `responsive.spec.ts` - Responsive design - `components.spec.ts` - UI components ## Implementation Plan ### Phase 1: Critical Elements (Authentication) Add these data-testid attributes to `/src/pages/LoginPage.tsx`: ```tsx // Email input // Password input // Password toggle button // Theme toggle ``` ### Phase 3: Layout Elements Add these to `/src/components/layout/AppLayout.tsx`: ```tsx // Skip to content link // Main content area
// Mobile overlay
// Breadcrumb navigation
// Loading components
``` ## Testing Naming Conventions ### Standard Patterns - **Pages**: `{page-name}-page` (e.g., `dashboard-page`, `events-page`) - **Navigation**: `nav-{item}` (e.g., `nav-dashboard`, `nav-events`) - **Forms**: `{field}-input`, `{field}-error` (e.g., `email-input`, `email-error`) - **Buttons**: `{action}-button` (e.g., `login-button`, `submit-button`) - **User Interface**: `user-{element}` (e.g., `user-menu`, `user-avatar`) - **Theme**: `theme-toggle`, `theme-{variant}` - **Modal**: `modal-{action}` (e.g., `modal-close`, `modal-confirm`) - **Cards**: `{type}-card-{id}` (e.g., `event-card-123`) ### Component Props Pattern For reusable components, accept data-testid as a prop: ```tsx interface ButtonProps { 'data-testid'?: string; // ... other props } export function Button({ 'data-testid': testId, ...props }: ButtonProps) { return