Files
nofx/web/src/test/setup.ts
Ember bfb409e8a1 fix(web): unify password validation logic in RegisterPage (#943)
Remove duplicate password validation logic to ensure consistency.
Changes:
- Remove custom isStrongPassword function (RegisterPage.tsx:569-576)
- Use PasswordChecklist validation result (passwordValid state) instead
- Add comprehensive test suite with 28 test cases
- Configure Vitest with jsdom environment and setup file
Test Coverage:
- Password validation rules (length, uppercase, lowercase, number, special chars)
- Special character consistency (/[@#$%!&*?]/)
- Edge cases and boundary conditions
- Refactoring consistency verification
All 78 tests passing (25 + 25 + 28).
Co-authored-by: tinkle-community <tinklefund@gmail.com>
2025-11-12 21:54:54 +08:00

33 lines
708 B
TypeScript

import '@testing-library/jest-dom'
import { beforeAll, afterEach } from 'vitest'
// Mock localStorage
const localStorageMock = {
getItem: (key: string) => {
return localStorageMock._store[key] || null
},
setItem: (key: string, value: string) => {
localStorageMock._store[key] = value
},
removeItem: (key: string) => {
delete localStorageMock._store[key]
},
clear: () => {
localStorageMock._store = {}
},
_store: {} as Record<string, string>,
}
// Setup before all tests
beforeAll(() => {
Object.defineProperty(window, 'localStorage', {
value: localStorageMock,
writable: true,
})
})
// Clean up after each test
afterEach(() => {
localStorageMock.clear()
})