feat: add MFA/TOTP auth, PII encryption, agents/leads/inquiries modules, and comprehensive tests
- Add TOTP-based MFA with setup, verify, disable, backup codes, and challenge flow - Add PII field encryption middleware with AES-256-GCM and deterministic search hashes - Add agents, inquiries, and leads domain modules with entities, events, value objects - Add web dashboard pages for inquiries and leads with detail dialogs - Add 30+ component tests (valuation, charts, listings, search, providers, UI) - Add Prisma migrations for encryption hash columns and MFA TOTP support - Fix all ESLint errors (unused imports, duplicate imports, lint auto-fixes) - Update dependencies and lock file - Clean up obsolete exploration/QA docs, add audit documentation Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
66
apps/web/components/ui/__tests__/language-switcher.spec.tsx
Normal file
66
apps/web/components/ui/__tests__/language-switcher.spec.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { LanguageSwitcher } from '../language-switcher';
|
||||
|
||||
// Mock next-intl
|
||||
vi.mock('next-intl', () => ({
|
||||
useLocale: () => 'vi',
|
||||
useTranslations: () => (key: string) => {
|
||||
const translations: Record<string, string> = {
|
||||
label: 'Ngôn ngữ',
|
||||
vi: 'Tiếng Việt',
|
||||
en: 'English',
|
||||
};
|
||||
return translations[key] ?? key;
|
||||
},
|
||||
}));
|
||||
|
||||
// Mock i18n navigation
|
||||
const mockReplace = vi.fn();
|
||||
vi.mock('@/i18n/navigation', () => ({
|
||||
useRouter: () => ({
|
||||
replace: mockReplace,
|
||||
}),
|
||||
usePathname: () => '/search',
|
||||
}));
|
||||
|
||||
describe('LanguageSwitcher', () => {
|
||||
beforeEach(() => {
|
||||
mockReplace.mockClear();
|
||||
});
|
||||
|
||||
it('renders a button', () => {
|
||||
render(<LanguageSwitcher />);
|
||||
expect(screen.getByRole('button')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('has correct aria-label', () => {
|
||||
render(<LanguageSwitcher />);
|
||||
expect(screen.getByRole('button')).toHaveAttribute(
|
||||
'aria-label',
|
||||
expect.stringContaining('Ngôn ngữ'),
|
||||
);
|
||||
});
|
||||
|
||||
it('shows next locale label (EN when current is VI)', () => {
|
||||
render(<LanguageSwitcher />);
|
||||
// The button should display the label for "en" since current is "vi"
|
||||
expect(screen.getByText(/EN/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls router.replace when clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<LanguageSwitcher />);
|
||||
|
||||
await user.click(screen.getByRole('button'));
|
||||
expect(mockReplace).toHaveBeenCalledWith('/search', { locale: 'en' });
|
||||
});
|
||||
|
||||
it('has screen reader text', () => {
|
||||
render(<LanguageSwitcher />);
|
||||
const srText = document.querySelector('.sr-only');
|
||||
expect(srText).toBeInTheDocument();
|
||||
expect(srText).toHaveTextContent('English');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user