1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69import { axe, toHaveNoViolations } from 'jest-axe';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { AccountForm } from '~/components/forms';
import * as useAuthModule from '~/hooks/useAuth';
import { Account } from '~/routes';
import { render, screen } from '../../customRender';
vi.mock('~/hooks/useAuth', () => ({
useAuth: vi.fn(),
}));
const mockUseAuth = (overrides = {}) => {
vi.mocked(useAuthModule.useAuth).mockReturnValue({
signUp: vi.fn(),
confirmSignUp: vi.fn(),
resendSignUpCode: vi.fn(),
signIn: vi.fn(),
signOut: vi.fn(),
deleteUser: vi.fn(),
user: null,
isAuthenticated: false,
needsConfirmation: false,
pendingUsername: null,
loading: false,
error: null,
...overrides,
});
};
expect.extend(toHaveNoViolations);
describe('Account Page and Form', () => {
beforeEach(() => {
vi.clearAllMocks();
mockUseAuth();
});
it('renders correctly and is accessible', async () => {
const { container } = render(<Account />);
expect(screen.getByText('Your Account')).toBeInTheDocument();
const results = await axe(container);
expect(results).toHaveNoViolations();
});
it('form inputs are present and disabled', async () => {
mockUseAuth({user: {email: 'johndoe@example.com'}});
render(<AccountForm />);
const firstNameInput = screen.getByRole('textbox', { name: /first name/i });
expect(firstNameInput).toBeDisabled();
const lastNameInput = screen.getByRole('textbox', { name: /last name/i });
expect(lastNameInput).toBeDisabled();
const emailInput = await screen.findByRole('textbox', { name: /email/i });
expect(emailInput).toHaveValue('johndoe@example.com');
expect(emailInput).toBeDisabled();
});
it('update account button is present and disabled', () => {
render(<AccountForm />);
const updateButton = screen.getByRole('button', { name: /Update Account/i });
expect(updateButton).toBeInTheDocument();
expect(updateButton).toBeDisabled();
});
});