Skip to content

Commit 8ddc9a8

Browse files
test(mosaic): remove redundant MFA coverage and unused fixture
1 parent a129664 commit 8ddc9a8

12 files changed

Lines changed: 75 additions & 1057 deletions

‎packages/mosaic/src/features/user-profile/__tests__/user-profile-add-authenticator.dialog.test.tsx‎

Lines changed: 1 addition & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, screen, waitFor } from '@testing-library/react';
1+
import { render, screen } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
33
import { useState } from 'react';
44
import { describe, expect, it, vi } from 'vitest';
@@ -51,72 +51,6 @@ function VerificationExample({ onSubmit }: Pick<UserProfileAddAuthenticatorDialo
5151
}
5252

5353
describe('UserProfileAddAuthenticatorDialog', () => {
54-
it.each([undefined, 'Unable to prepare your authenticator.'])(
55-
'allows cancellation during preparation: %s',
56-
async setupErrorMessage => {
57-
const user = userEvent.setup();
58-
const { props } = renderView({ setup: undefined, setupErrorMessage });
59-
await user.click(screen.getByRole('button', { name: 'Cancel' }));
60-
expect(props.onOpenChange).toHaveBeenCalledWith(false);
61-
expect(props.onRetry).not.toHaveBeenCalled();
62-
expect(props.onSubmit).not.toHaveBeenCalled();
63-
},
64-
);
65-
66-
it('copies either manual credential through the caller and displays controlled copy feedback', async () => {
67-
const user = userEvent.setup();
68-
const onCopy = vi.fn();
69-
const { props, rerender } = renderView({ onCopy });
70-
await user.click(screen.getByRole('button', { name: 'Can’t scan? View setup key' }));
71-
const copyKey = screen.getByRole('button', { name: 'Copy setup key' });
72-
const copyUri = screen.getByRole('button', { name: 'Copy setup URI' });
73-
await user.click(copyKey);
74-
expect(onCopy).toHaveBeenCalledExactlyOnceWith(setup.secret);
75-
expect(props.onSubmit).not.toHaveBeenCalled();
76-
77-
rerender(
78-
<MosaicProvider>
79-
<UserProfileAddAuthenticatorDialog
80-
{...props}
81-
copyStatus='pending'
82-
/>
83-
</MosaicProvider>,
84-
);
85-
expect(copyKey).toHaveFocus();
86-
expect(copyKey).toHaveAttribute('aria-disabled', 'true');
87-
expect(copyUri).toHaveAttribute('aria-disabled', 'true');
88-
expect(screen.getByRole('status', { name: 'Copy feedback' })).toHaveTextContent('Copying…');
89-
await user.click(copyUri);
90-
await user.keyboard('{Enter}');
91-
expect(onCopy).toHaveBeenCalledOnce();
92-
93-
rerender(
94-
<MosaicProvider>
95-
<UserProfileAddAuthenticatorDialog
96-
{...props}
97-
copyErrorMessage='Could not copy. Please try again.'
98-
/>
99-
</MosaicProvider>,
100-
);
101-
expect(screen.getByRole('alert')).toHaveTextContent('Could not copy. Please try again.');
102-
expect(screen.getByRole('textbox', { name: 'Setup key' })).toHaveValue(setup.secret);
103-
await user.click(copyUri);
104-
expect(onCopy).toHaveBeenLastCalledWith(setup.uri);
105-
106-
rerender(
107-
<MosaicProvider>
108-
<UserProfileAddAuthenticatorDialog
109-
{...props}
110-
copyStatus='success'
111-
/>
112-
</MosaicProvider>,
113-
);
114-
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
115-
expect(screen.getByRole('status', { name: 'Copy feedback' })).toHaveTextContent('Copied');
116-
expect(screen.getByRole('dialog')).toBeVisible();
117-
expect(props.onOpenChange).not.toHaveBeenCalled();
118-
});
119-
12054
it('shows preparation, offers retry on failure, and waits for setup data before verification', async () => {
12155
const user = userEvent.setup();
12256
const { props, rerender } = renderView({ setup: undefined });
@@ -177,47 +111,6 @@ describe('UserProfileAddAuthenticatorDialog', () => {
177111
expect(props.onSubmit).toHaveBeenCalledExactlyOnceWith('123456');
178112
});
179113

180-
it.each(['typing', 'pasting'] as const)('submits a complete authenticator code after %s', async method => {
181-
const user = userEvent.setup();
182-
const onSubmit = vi.fn();
183-
render(<VerificationExample onSubmit={onSubmit} />);
184-
const dialog = screen.getByRole('dialog', { name: 'Add an authenticator app' });
185-
expect(screen.getByRole('img', { name: 'Authenticator setup QR code' })).toBeVisible();
186-
expect(screen.queryByRole('button', { name: /Resend/ })).not.toBeInTheDocument();
187-
await waitFor(() => expect(screen.getByRole('button', { name: 'Close', exact: true })).toHaveFocus());
188-
await user.click(screen.getByRole('textbox', { name: 'Verification code' }));
189-
190-
if (method === 'typing') {
191-
await user.keyboard('12345');
192-
expect(onSubmit).not.toHaveBeenCalled();
193-
await user.keyboard('6');
194-
} else {
195-
await user.paste('123456');
196-
}
197-
198-
expect(onSubmit).toHaveBeenCalledExactlyOnceWith('123456');
199-
expect(screen.getByRole('dialog')).toBe(dialog);
200-
});
201-
202-
it('submits the current code through Verify or the form and does not submit on Cancel', async () => {
203-
const user = userEvent.setup();
204-
const { props } = renderView({ code: '654321' });
205-
await user.click(screen.getByRole('button', { name: 'Verify', exact: true }));
206-
expect(props.onSubmit).toHaveBeenCalledExactlyOnceWith('654321');
207-
208-
const form = screen.getByRole('textbox', { name: 'Verification code' }).closest('form');
209-
if (!form) {
210-
throw new Error('Verification form missing');
211-
}
212-
form.requestSubmit();
213-
expect(props.onSubmit).toHaveBeenCalledTimes(2);
214-
expect(props.onSubmit).toHaveBeenLastCalledWith('654321');
215-
216-
await user.click(screen.getByRole('button', { name: 'Cancel' }));
217-
expect(props.onOpenChange).toHaveBeenCalledWith(false);
218-
expect(props.onSubmit).toHaveBeenCalledTimes(2);
219-
});
220-
221114
it('blocks incomplete and pending submissions, including native form submission', async () => {
222115
const user = userEvent.setup();
223116
const { props, rerender } = renderView({ code: '123' });
@@ -251,42 +144,6 @@ describe('UserProfileAddAuthenticatorDialog', () => {
251144
expect(props.onSubmit).not.toHaveBeenCalled();
252145
});
253146

254-
it('preserves the setup mode and code on failure, then clears feedback when retry begins', async () => {
255-
const user = userEvent.setup();
256-
const { props, rerender } = renderView({ code: '123456' });
257-
const dialog = screen.getByRole('dialog');
258-
await user.click(screen.getByRole('button', { name: 'Can’t scan? View setup key' }));
259-
260-
rerender(
261-
<MosaicProvider>
262-
<UserProfileAddAuthenticatorDialog
263-
{...props}
264-
errorMessage='That code has expired. Please try again.'
265-
/>
266-
</MosaicProvider>,
267-
);
268-
expect(screen.getByRole('dialog')).toBe(dialog);
269-
expect(screen.getByRole('textbox', { name: 'Setup key' })).toHaveValue(setup.secret);
270-
expect(screen.getByRole('textbox', { name: 'Setup URI' })).toHaveValue(setup.uri);
271-
const group = screen.getByRole('group', { name: 'Verification code' });
272-
expect(group).toHaveAccessibleDescription('That code has expired. Please try again.');
273-
expect(screen.getByRole('textbox', { name: 'Verification code' })).toHaveAttribute('aria-invalid', 'true');
274-
await user.click(screen.getByRole('button', { name: 'Verify', exact: true }));
275-
expect(props.onSubmit).toHaveBeenCalledExactlyOnceWith('123456');
276-
277-
rerender(
278-
<MosaicProvider>
279-
<UserProfileAddAuthenticatorDialog
280-
{...props}
281-
isPending
282-
/>
283-
</MosaicProvider>,
284-
);
285-
expect(group).not.toHaveAccessibleDescription();
286-
expect(screen.getByRole('textbox', { name: 'Verification code' })).not.toHaveAttribute('aria-invalid');
287-
expect(screen.getByRole('textbox', { name: 'Setup key' })).toHaveValue(setup.secret);
288-
});
289-
290147
it('keeps the entered code when switching between QR and manual setup', async () => {
291148
const user = userEvent.setup();
292149
const onSubmit = vi.fn();

‎packages/mosaic/src/features/user-profile/__tests__/user-profile-add-mfa.view.test.tsx‎

Lines changed: 0 additions & 67 deletions
This file was deleted.

‎packages/mosaic/src/features/user-profile/__tests__/user-profile-add-sms.dialog.test.tsx‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,6 @@ function renderView(overrides: Partial<UserProfileAddSmsDialogProps> = {}) {
3939
}
4040

4141
describe('UserProfileAddSmsDialog', () => {
42-
it('chooses an existing number with Select or requests a new number', async () => {
43-
const user = userEvent.setup();
44-
const { props } = renderView();
45-
const select = screen.getByRole('combobox', { name: 'Phone number +1 (801) 555-0100' });
46-
await waitFor(() => expect(select).toHaveFocus());
47-
48-
await user.click(select);
49-
await user.click(screen.getByRole('option', { name: '+1 (801) 555-0200' }));
50-
expect(props.onSelectedPhoneIdChange).toHaveBeenCalledWith('work');
51-
expect(props.onSubmit).not.toHaveBeenCalled();
52-
53-
await user.click(screen.getByRole('button', { name: 'Continue' }));
54-
expect(props.onSubmit).toHaveBeenCalledOnce();
55-
56-
await user.click(screen.getByRole('button', { name: 'Add a new phone number' }));
57-
expect(props.onAddPhone).toHaveBeenCalledOnce();
58-
});
59-
6042
it('adds and verifies a new number in the same dialog, preserving the number on Back', async () => {
6143
const user = userEvent.setup();
6244
const onVerify = vi.fn();

‎packages/mosaic/src/features/user-profile/__tests__/user-profile-authenticator-setup.view.test.tsx‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, screen, waitFor } from '@testing-library/react';
1+
import { render, screen } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
33
import { describe, expect, it } from 'vitest';
44

@@ -53,27 +53,4 @@ describe('Authenticator setup', () => {
5353
expect(screen.getByRole('textbox', { name: 'Setup key' })).toHaveValue(setup.secret);
5454
expect(screen.getByRole('textbox', { name: 'Setup URI' })).toHaveValue(setup.uri);
5555
});
56-
57-
it('supports keyboard toggling and starts with the QR code again after dismissal', async () => {
58-
const user = userEvent.setup();
59-
renderView();
60-
const trigger = screen.getByRole('button', { name: 'Set up authenticator' });
61-
await user.click(trigger);
62-
await user.tab();
63-
const toggle = screen.getByRole('button', { name: 'Can’t scan? View setup key' });
64-
expect(toggle).toHaveFocus();
65-
await user.keyboard('{Enter}');
66-
expect(screen.getByRole('textbox', { name: 'Setup key' })).toBeVisible();
67-
expect(screen.getByRole('button', { name: 'Scan QR code instead' })).toHaveFocus();
68-
await user.keyboard(' ');
69-
expect(screen.getByRole('img', { name: 'Authenticator setup QR code' })).toBeVisible();
70-
await user.keyboard('{Enter}');
71-
await user.keyboard('{Escape}');
72-
73-
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
74-
expect(trigger).toHaveFocus();
75-
await user.click(trigger);
76-
expect(screen.getByRole('img', { name: 'Authenticator setup QR code' })).toBeVisible();
77-
expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
78-
});
7956
});

0 commit comments

Comments
 (0)