Skip to content

Commit 64ee240

Browse files
fix(mosaic): disable phone verification cancel while pending
1 parent 1c8f888 commit 64ee240

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

‎.changeset/quiet-phones-wait.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/mosaic': patch
3+
---
4+
5+
Disable Cancel while verifying or resending a phone verification code in `UserProfile`.

‎packages/mosaic/src/features/user-profile/user-profile-phone-section/__tests__/user-profile-phone-section.feature.test.tsx‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { EnterpriseAccountConnectionJSON, PhoneNumberJSON } from '@clerk/sh
22
import { act, screen, waitFor, within } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import { http, HttpResponse } from 'msw';
5-
import { describe, expect, it } from 'vitest';
5+
import { describe, expect, it, vi } from 'vitest';
66

77
import {
88
demandReverificationOnce,
@@ -159,6 +159,56 @@ describe('the user profile phone section', () => {
159159
expect(await screen.findByRole('button', { name: /Resend \(\d+\)/ })).toBeDisabled();
160160
});
161161

162+
it('disables Cancel while verifying a phone code and allows cancellation after an error', async () => {
163+
const { actor } = await renderSection();
164+
await addPhone(actor, '8015550100');
165+
const attempt = holdRequests('post', '/v1/me/phone_numbers/:id/attempt_verification');
166+
167+
try {
168+
await enterCode(actor, '000000');
169+
await waitFor(() => expect(attempt.requests).toHaveLength(1));
170+
expect(screen.getByRole('button', { name: 'Cancel' })).toBeDisabled();
171+
expect(screen.getByRole('dialog', { name: 'Verify your phone number' })).toBeVisible();
172+
} finally {
173+
attempt.release();
174+
}
175+
176+
expect(await screen.findByText('Incorrect code')).toBeVisible();
177+
const cancel = screen.getByRole('button', { name: 'Cancel' });
178+
expect(cancel).toBeEnabled();
179+
await actor.click(cancel);
180+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
181+
});
182+
183+
it('disables Cancel while resending a phone code and allows cancellation once sent', async ({ onTestFinished }) => {
184+
vi.useFakeTimers({ shouldAdvanceTime: true });
185+
onTestFinished(() => vi.useRealTimers());
186+
await renderSection();
187+
const actor = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
188+
await addPhone(actor, '8015550100');
189+
await screen.findByRole('textbox', { name: 'Verification code' });
190+
const prepare = holdRequests('post', '/v1/me/phone_numbers/:id/prepare_verification');
191+
192+
try {
193+
for (let second = 0; second < 30; second++) {
194+
await act(() => vi.advanceTimersByTimeAsync(1000));
195+
}
196+
const resend = screen.getByRole('button', { name: /Resend/ });
197+
await waitFor(() => expect(resend).toBeEnabled());
198+
await actor.click(resend);
199+
await waitFor(() => expect(prepare.requests).toHaveLength(1));
200+
expect(screen.getByRole('button', { name: 'Cancel' })).toBeDisabled();
201+
expect(screen.getByRole('dialog', { name: 'Verify your phone number' })).toBeVisible();
202+
} finally {
203+
prepare.release();
204+
}
205+
206+
const cancel = screen.getByRole('button', { name: 'Cancel' });
207+
await waitFor(() => expect(cancel).toBeEnabled());
208+
await actor.click(cancel);
209+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
210+
});
211+
162212
it('verifies a number that was left unverified', async () => {
163213
const pending = fapiPhoneNumber({ id: 'idn_new', phone_number: '+18015550199' });
164214
const { actor } = await renderSection(signedIn([HOME, pending]));

‎packages/mosaic/src/features/user-profile/user-profile-phone.steps.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export function VerifyPhoneStep(props: VerifyPhoneStepProps) {
183183
<Card.Footer>
184184
{props.secondaryAction ?? (
185185
<Dialog.Close
186+
disabled={props.isPending || props.isResending}
186187
render={
187188
<Button
188189
variant='outline'

0 commit comments

Comments
 (0)