Skip to content

Commit bdecd18

Browse files
test(mosaic): isolate MFA picker interaction in security panel
1 parent 9672458 commit bdecd18

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

‎packages/mosaic/src/features/user-profile/__tests__/user-profile-security-panel.view.test.tsx‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,36 +76,45 @@ describe('UserProfileSecurityPanelView', () => {
7676
).toBeInTheDocument();
7777
});
7878

79+
it('adds an available MFA method through the picker', async () => {
80+
const onAddMfaMethod = vi.fn();
81+
const user = userEvent.setup();
82+
83+
renderView({
84+
mfaMethods: [
85+
{ id: 'sms_1', type: 'sms', description: '+1 801-888-8181' },
86+
{ id: 'backup_1', type: 'backup-codes' },
87+
],
88+
onAddMfaMethod,
89+
addableMfaMethods: ['authenticator'],
90+
});
91+
92+
await user.click(screen.getByRole('button', { name: 'Add verification method' }));
93+
expect(screen.queryByRole('button', { name: /SMS verification Get a code/ })).not.toBeInTheDocument();
94+
await user.click(screen.getByRole('button', { name: /Authenticator app Get codes/ }));
95+
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
96+
expect(onAddMfaMethod).toHaveBeenCalledWith('authenticator');
97+
});
98+
7999
it('forwards security actions', async () => {
80100
const onAddPasskey = vi.fn();
81101
const onRenamePasskey = vi.fn(() => Promise.resolve());
82102
const onRemovePasskey = vi.fn();
83-
const onAddMfaMethod = vi.fn();
84103
const onSignOutDevice = vi.fn();
85104
const onSignOutAllOtherDevices = vi.fn();
86105
const onDeleteAccount = vi.fn(() => Promise.resolve());
87106
const user = userEvent.setup();
88107

89108
renderView({
90-
mfaMethods: [
91-
{ id: 'sms_1', type: 'sms', description: '+1 801-888-8181' },
92-
{ id: 'backup_1', type: 'backup-codes' },
93-
],
94109
onAddPasskey,
95110
onRenamePasskey,
96111
onRemovePasskey,
97-
onAddMfaMethod,
98-
addableMfaMethods: ['authenticator'],
99112
onSignOutDevice,
100113
onSignOutAllOtherDevices,
101114
onDeleteAccount,
102115
});
103116

104117
await user.click(screen.getByRole('button', { name: 'Add passkey' }));
105-
await user.click(screen.getByRole('button', { name: 'Add verification method' }));
106-
expect(screen.queryByRole('button', { name: /SMS verification Get a code/ })).not.toBeInTheDocument();
107-
await user.click(screen.getByRole('button', { name: /Authenticator app Get codes/ }));
108-
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
109118
await user.click(screen.getByRole('button', { name: 'Sign out of all devices' }));
110119
await user.click(within(screen.getByRole('alertdialog')).getByRole('button', { name: 'Sign out' }));
111120
await waitFor(() => expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument());
@@ -137,7 +146,6 @@ describe('UserProfileSecurityPanelView', () => {
137146
expect(onAddPasskey).toHaveBeenCalledOnce();
138147
expect(onRenamePasskey).toHaveBeenCalledWith('passkey_1', 'Work laptop');
139148
expect(onRemovePasskey).toHaveBeenCalledWith('passkey_1');
140-
expect(onAddMfaMethod).toHaveBeenCalledWith('authenticator');
141149
expect(onSignOutDevice).toHaveBeenCalledWith('mobile');
142150
expect(onSignOutAllOtherDevices).toHaveBeenCalledOnce();
143151
expect(onDeleteAccount).toHaveBeenCalledOnce();

0 commit comments

Comments
 (0)