mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 07:40:59 +00:00
test(native): the handoff page's fixture knows the passkey step, and the hook test keeps the real API client around its passkey mocks
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// FE-NATIVE-HANDOFF-PAGE-001 to FE-NATIVE-HANDOFF-PAGE-004
|
||||
// FE-NATIVE-HANDOFF-PAGE-001 to FE-NATIVE-HANDOFF-PAGE-005
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { fireEvent, render, screen } from '../../tests/helpers/render';
|
||||
import NativeHandoffPage from './NativeHandoffPage';
|
||||
@@ -8,6 +8,9 @@ vi.mock('./nativeHandoff/useNativeHandoff', () => ({ useNativeHandoff: vi.fn() }
|
||||
|
||||
const base = {
|
||||
valid: true,
|
||||
passkeyStep: false,
|
||||
continueWithPasskey: vi.fn(),
|
||||
otherSignIn: vi.fn(),
|
||||
ready: true,
|
||||
userName: 'maria',
|
||||
status: 'idle' as const,
|
||||
@@ -52,4 +55,14 @@ describe('NativeHandoffPage', () => {
|
||||
render(<NativeHandoffPage />);
|
||||
expect(screen.getByText('Signing in did not work. Please try again.')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-NATIVE-HANDOFF-PAGE-005: asks for the passkey itself when the app started a passkey sign-in', () => {
|
||||
vi.mocked(useNativeHandoff).mockReturnValue({ ...base, passkeyStep: true, ready: false });
|
||||
render(<NativeHandoffPage />);
|
||||
const buttons = screen.getAllByRole('button');
|
||||
fireEvent.click(buttons[0]);
|
||||
expect(base.continueWithPasskey).toHaveBeenCalled();
|
||||
fireEvent.click(buttons[1]);
|
||||
expect(base.otherSignIn).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,9 +22,13 @@ vi.mock('../../native/browserSignIn', () => ({
|
||||
}));
|
||||
|
||||
vi.mock('@simplewebauthn/browser', () => ({ startAuthentication: vi.fn() }));
|
||||
vi.mock('../../api/client', () => ({
|
||||
authApi: { passkey: { loginOptions: vi.fn(), loginVerify: vi.fn() } },
|
||||
}));
|
||||
vi.mock('../../api/client', async () => {
|
||||
const actual = await vi.importActual<typeof import('../../api/client')>('../../api/client');
|
||||
return {
|
||||
...actual,
|
||||
authApi: { ...actual.authApi, passkey: { ...actual.authApi.passkey, loginOptions: vi.fn(), loginVerify: vi.fn() } },
|
||||
};
|
||||
});
|
||||
|
||||
const challenge = 'ab'.repeat(32);
|
||||
const realLocation = window.location;
|
||||
|
||||
Reference in New Issue
Block a user