-
Notifications
You must be signed in to change notification settings - Fork 462
Expand file tree
/
Copy pathSignUpVerifyEmail.test.tsx
More file actions
142 lines (119 loc) · 5.77 KB
/
Copy pathSignUpVerifyEmail.test.tsx
File metadata and controls
142 lines (119 loc) · 5.77 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { waitFor } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { bindCreateFixtures } from '@/test/create-fixtures';
import { render, screen } from '@/test/utils';
import { SignUpVerifyEmail } from '../SignUpVerifyEmail';
const { createFixtures } = bindCreateFixtures('SignUp');
describe('SignUpVerifyEmail', () => {
it('renders the component', async () => {
const { wrapper } = await createFixtures();
render(<SignUpVerifyEmail />, { wrapper });
screen.getByText(/verify/i);
});
it('shows the email associated with the sign up', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withEmailAddress({ required: true });
f.startSignUpWithEmailAddress({ emailAddress: 'test@clerk.com' });
});
fixtures.signUp.prepareEmailAddressVerification.mockRejectedValue(null);
const { findByText } = render(<SignUpVerifyEmail />, { wrapper });
await waitFor(async () => expect(await findByText('test@clerk.com')).toBeInTheDocument());
});
it('shows the verify with link message', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withEmailAddress({ required: true, verifications: ['email_link'] });
f.startSignUpWithEmailAddress({ emailAddress: 'test@clerk.com' });
});
fixtures.signUp.createEmailLinkFlow.mockImplementation(
() =>
({
startEmailLinkFlow: vi.fn(() => new Promise(() => ({}))),
cancelEmailLinkFlow: vi.fn(() => new Promise(() => ({}))),
}) as any,
);
const { findByText } = render(<SignUpVerifyEmail />, { wrapper });
await waitFor(async () => expect(await findByText(/Verification Link/i)).toBeInTheDocument());
});
it('shows the verify with code message', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withEmailAddress({ required: true, verifications: ['email_code'] });
f.startSignUpWithEmailAddress({ emailAddress: 'test@clerk.com' });
});
fixtures.signUp.prepareEmailAddressVerification.mockRejectedValue(null);
const { findByText } = render(<SignUpVerifyEmail />, { wrapper });
await waitFor(async () => expect(await findByText(/Verify your email/i)).toBeInTheDocument());
await waitFor(async () =>
expect(await findByText(/Enter the verification code sent to your email/i)).toBeInTheDocument(),
);
});
it('does not prepare a new email code when the persisted email verification is pending', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withEmailAddress({ required: true, verifications: ['email_code'] });
f.startSignUpWithEmailAddress({
emailAddress: 'pending-code@clerk.com',
supportEmailLink: false,
supportEmailCode: true,
});
});
fixtures.signUp.prepareEmailAddressVerification.mockResolvedValue(fixtures.signUp);
const { findByText } = render(<SignUpVerifyEmail />, { wrapper });
await waitFor(async () => expect(await findByText(/Verify your email/i)).toBeInTheDocument());
expect(fixtures.signUp.prepareEmailAddressVerification).not.toHaveBeenCalled();
});
it('prepares a new email code when the persisted email verification is expired', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withEmailAddress({ required: true, verifications: ['email_code'] });
f.startSignUpWithEmailAddress({
emailAddress: 'expired-code@clerk.com',
supportEmailLink: false,
supportEmailCode: true,
emailVerificationStatus: 'expired',
});
});
fixtures.signUp.prepareEmailAddressVerification.mockRejectedValue(null);
render(<SignUpVerifyEmail />, { wrapper });
await waitFor(() =>
expect(fixtures.signUp.prepareEmailAddressVerification).toHaveBeenCalledWith({ strategy: 'email_code' }),
);
});
it('clicking on the edit icon navigates to the previous route', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withEmailAddress({ required: true });
f.startSignUpWithEmailAddress({ emailAddress: 'test@clerk.com' });
});
fixtures.signUp.prepareEmailAddressVerification.mockRejectedValue(null);
const { userEvent } = render(<SignUpVerifyEmail />, { wrapper });
await userEvent.click(
screen.getByRole('button', {
name: /edit/i,
}),
);
expect(fixtures.router.navigate).toHaveBeenCalledWith('../', { searchParams: new URLSearchParams() });
});
it('Resend link button exists', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withEmailAddress({ required: true, verifications: ['email_link'] });
f.startSignUpWithEmailAddress({ emailAddress: 'test@clerk.com' });
});
fixtures.signUp.createEmailLinkFlow.mockImplementation(
() =>
({
startEmailLinkFlow: vi.fn(() => new Promise(() => ({}))),
cancelEmailLinkFlow: vi.fn(() => new Promise(() => ({}))),
}) as any,
);
const { findByText } = render(<SignUpVerifyEmail />, { wrapper });
await waitFor(async () => expect((await findByText(/Resend/i)).tagName.toUpperCase()).toBe('BUTTON'));
});
it('Resend code button exists', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withEmailAddress({ required: true, verifications: ['email_code'] });
f.startSignUpWithEmailAddress({ emailAddress: 'test@clerk.com' });
});
fixtures.signUp.prepareEmailAddressVerification.mockRejectedValue(null);
const { findByText } = render(<SignUpVerifyEmail />, { wrapper });
await waitFor(async () => expect((await findByText(/Resend/i)).tagName.toUpperCase()).toBe('BUTTON'));
});
it.todo('Resend link button is pressable after 60 seconds');
it.todo('Resend code button is pressable after 30 seconds');
});