mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 15:51:00 +00:00
69 lines
2.8 KiB
TypeScript
69 lines
2.8 KiB
TypeScript
// 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';
|
|
import { useNativeHandoff } from './nativeHandoff/useNativeHandoff';
|
|
|
|
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,
|
|
openApp: vi.fn(),
|
|
switchAccount: vi.fn(),
|
|
};
|
|
|
|
beforeEach(() => {
|
|
vi.mocked(useNativeHandoff).mockReturnValue({ ...base });
|
|
});
|
|
|
|
describe('NativeHandoffPage', () => {
|
|
it('FE-NATIVE-HANDOFF-PAGE-001: asks before handing the session to the app', () => {
|
|
render(<NativeHandoffPage />);
|
|
expect(
|
|
screen.getByText('You are signed in as maria. Open the TREK app to finish signing in there.')
|
|
).toBeInTheDocument();
|
|
fireEvent.click(screen.getByRole('button', { name: 'Open the TREK app' }));
|
|
expect(base.openApp).toHaveBeenCalled();
|
|
fireEvent.click(screen.getByRole('button', { name: 'Use a different account' }));
|
|
expect(base.switchAccount).toHaveBeenCalled();
|
|
});
|
|
|
|
it('FE-NATIVE-HANDOFF-PAGE-002: shows the failure and keeps the button while sending disabled', () => {
|
|
vi.mocked(useNativeHandoff).mockReturnValue({ ...base, status: 'failed' });
|
|
const { rerender } = render(<NativeHandoffPage />);
|
|
expect(screen.getByRole('alert')).toHaveTextContent('Signing in did not work. Please try again.');
|
|
|
|
vi.mocked(useNativeHandoff).mockReturnValue({ ...base, status: 'sending' });
|
|
rerender(<NativeHandoffPage />);
|
|
expect(screen.getByRole('button', { name: 'Open the TREK app' })).toBeDisabled();
|
|
});
|
|
|
|
it('FE-NATIVE-HANDOFF-PAGE-003: spins while the session is being checked', () => {
|
|
vi.mocked(useNativeHandoff).mockReturnValue({ ...base, ready: false });
|
|
render(<NativeHandoffPage />);
|
|
expect(screen.queryByRole('button')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-NATIVE-HANDOFF-PAGE-004: says so when the link is broken', () => {
|
|
vi.mocked(useNativeHandoff).mockReturnValue({ ...base, valid: false, ready: false });
|
|
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();
|
|
});
|
|
});
|