HR-ATS-Portal/frontend/src/__smoke__/entry.jsx

117 lines
4.1 KiB
JavaScript

/* Test-only entry. Kept inside src/ so every import resolves through Vite's
module graph exactly as it does in the app — one React instance, one router
instance, one query client. Not shipped: excluded from the build because
nothing in the app imports it. */
import React from 'react'
import { act } from 'react'
import { createRoot } from 'react-dom/client'
import { MemoryRouter, Navigate, Route, Routes } from 'react-router-dom'
import { QueryClientProvider } from '@tanstack/react-query'
import { queryClient } from '../lib/queryClient'
import { initializeCache } from '../data/seedQueries'
import ThemeProvider, { initTheme } from '../theme/ThemeProvider'
import ToastProvider from '../ui/Toast'
import AuthProvider from '../auth/AuthProvider'
import AppLayout from '../app/AppLayout'
import RequireAuth from '../auth/RequireAuth'
import { ROUTES as TABLE } from '../app/routes'
import Login from '../pages/Login'
import Signup from '../pages/Signup'
import ForgotPassword from '../pages/ForgotPassword'
import ConfirmEmail from '../pages/ConfirmEmail'
import Dashboard from '../screens/Dashboard'
import Inbox from '../screens/Inbox'
import Matching from '../screens/Matching'
import Jobs from '../screens/Jobs'
import Candidates from '../screens/Candidates'
import TalentPool from '../screens/TalentPool'
import Pipeline from '../screens/Pipeline'
import CvImport from '../screens/CvImport'
import JobBoard from '../screens/JobBoard'
import RecruiterHub from '../screens/RecruiterHub'
import Talent from '../screens/Talent'
import Tasks from '../screens/Tasks'
import AiAssistant from '../screens/AiAssistant'
import Interviews from '../screens/Interviews'
import Requisitions from '../screens/Requisitions'
import Assessments from '../screens/Assessments'
import Offers from '../screens/Offers'
import Managers from '../screens/Managers'
import Calendar from '../screens/Calendar'
import Reports from '../screens/Reports'
import Analytics from '../screens/Analytics'
import AiStudio from '../screens/AiStudio'
import Notifications from '../screens/Notifications'
import Rbac from '../screens/Rbac'
import Settings from '../screens/Settings'
import Help from '../screens/Help'
const SCREENS = {
dashboard: Dashboard, inbox: Inbox, matching: Matching, jobs: Jobs, candidates: Candidates,
talentpool: TalentPool, pipeline: Pipeline, import: CvImport, jobboard: JobBoard,
recruiterhub: RecruiterHub, talent: Talent, tasks: Tasks, aiassistant: AiAssistant,
interviews: Interviews, requisitions: Requisitions, assessments: Assessments, offers: Offers,
managers: Managers, calendar: Calendar, reports: Reports, analytics: Analytics,
aistudio: AiStudio, notifications: Notifications, rbac: Rbac,
settings: Settings, help: Help,
}
const PAGES = {
'/auth/login': Login,
'/auth/signup': Signup,
'/auth/forgot-password': ForgotPassword,
'/auth/confirm-email': ConfirmEmail,
}
export const ALL_ROUTES = [
...Object.keys(PAGES),
...TABLE.map((r) => `/${r.path}`),
]
export function boot() {
initTheme()
initializeCache(queryClient)
}
/** Mount one route, wait for effects to settle, return its rendered text. */
export async function renderRoute(path, container) {
const h = React.createElement
const isAuth = path.startsWith('/auth/')
const def = TABLE.find((r) => `/${r.path}` === path)
const Screen = isAuth ? PAGES[path] : SCREENS[def.path]
const inner = isAuth
? h(Route, { path, element: h(Screen) })
: h(
Route,
{ element: h(RequireAuth, null, h(AppLayout)) },
h(Route, { path, element: h(Screen) }),
)
const tree = h(
QueryClientProvider, { client: queryClient },
h(ThemeProvider, null,
h(ToastProvider, null,
h(MemoryRouter, { initialEntries: [path] },
h(AuthProvider, null,
h(Routes, null, inner, h(Route, { path: '*', element: h(Navigate, { to: path, replace: true }) })),
),
),
),
),
)
const root = createRoot(container)
try {
await act(async () => { root.render(tree) })
await act(async () => { await new Promise((r) => setTimeout(r, 40)) })
return container.textContent || ''
} finally {
await act(async () => { root.unmount() })
}
}