57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
/**
|
|
* Overridable staff-auth mock with spies.
|
|
*
|
|
* tests/setup.ts stubs @/components/context/staff-auth-context with this
|
|
* factory so screens that read the staff session mount. Tests can flip the
|
|
* state in a beforeEach; reset with resetStaffAuthMock().
|
|
*/
|
|
|
|
import type { ReactNode } from 'react'
|
|
|
|
export interface StaffAuthMockState {
|
|
isLoggedIn: boolean
|
|
isLoading: boolean
|
|
staff: unknown
|
|
/** Region of the signed-in staff member; suites opt in by setting this. */
|
|
regionId: number | null
|
|
isLoggingIn: boolean
|
|
loginError: string | null
|
|
login: jest.Mock
|
|
logout: jest.Mock
|
|
}
|
|
|
|
export const staffAuthMock: StaffAuthMockState = {
|
|
isLoggedIn: true,
|
|
isLoading: false,
|
|
staff: { id: 1, name: 'shafi' },
|
|
regionId: null,
|
|
isLoggingIn: false,
|
|
loginError: null,
|
|
login: jest.fn(async () => {}),
|
|
logout: jest.fn(),
|
|
}
|
|
|
|
export function resetStaffAuthMock() {
|
|
staffAuthMock.isLoggedIn = true
|
|
staffAuthMock.isLoading = false
|
|
staffAuthMock.staff = { id: 1, name: 'shafi' }
|
|
staffAuthMock.regionId = null
|
|
staffAuthMock.isLoggingIn = false
|
|
staffAuthMock.loginError = null
|
|
}
|
|
|
|
export function staffAuthContextMock() {
|
|
return {
|
|
StaffAuthProvider: ({ children }: { children?: ReactNode }) => children ?? null,
|
|
useStaffAuth: () => ({
|
|
isLoggedIn: staffAuthMock.isLoggedIn,
|
|
isLoading: staffAuthMock.isLoading,
|
|
staff: staffAuthMock.staff,
|
|
regionId: staffAuthMock.regionId,
|
|
isLoggingIn: staffAuthMock.isLoggingIn,
|
|
loginError: staffAuthMock.loginError,
|
|
login: staffAuthMock.login,
|
|
logout: staffAuthMock.logout,
|
|
}),
|
|
}
|
|
}
|