mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-01 08:13:37 +00:00
refactor: extract sanitizeForTestId to shared utility
Address PR review comments by: - Creating shared sanitizeForTestId utility in apps/ui/src/lib/utils.ts - Updating ProjectSwitcherItem to use the shared utility - Adding matching helper to test utils for E2E tests - Updating all E2E tests to use the sanitization helper This ensures the component and tests use identical sanitization logic, making tests robust against project names with special characters.
This commit is contained in:
@@ -1,5 +1,22 @@
|
||||
import { Page, Locator } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* Sanitize a string for use in data-testid selectors.
|
||||
* This mirrors the sanitizeForTestId function in apps/ui/src/lib/utils.ts
|
||||
* to ensure tests use the same sanitization logic as the component.
|
||||
*
|
||||
* @param name - The string to sanitize (e.g., project name)
|
||||
* @returns A sanitized string safe for CSS selectors
|
||||
*/
|
||||
export function sanitizeForTestId(name: string): string {
|
||||
return name
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/[^a-z0-9-]/g, '')
|
||||
.replace(/-+/g, '-')
|
||||
.replace(/^-|-$/g, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an element by its data-testid attribute
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user