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>
This commit is contained in:
Ember
2025-11-12 21:54:54 +08:00
committed by GitHub
parent 9e5688609e
commit bfb409e8a1
4 changed files with 423 additions and 13 deletions

32
web/src/test/setup.ts Normal file
View File

@@ -0,0 +1,32 @@
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()
})