Add Site Safety Assistant (ssa) role replacing reporter, supervisor and capa_owner. Portals move under /ssa (overview, my-reports, incidents, capas). Update RLS, schema, API role checks, notification recipients, nav and tests. Add db/ops/2026-11-06-merge-roles-into-ssa.sql (not yet applied; needs owner go-ahead and a pg_dump first). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
78 lines
3.4 KiB
TypeScript
78 lines
3.4 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { render, screen, fireEvent } from '@testing-library/react'
|
|
|
|
const push = vi.fn()
|
|
const refresh = vi.fn()
|
|
vi.mock('next/navigation', () => ({
|
|
usePathname: () => '/hse/capa',
|
|
useRouter: () => ({ push, refresh }),
|
|
}))
|
|
vi.mock('@/components/notifications/bell', () => ({ NotificationBell: () => <button aria-label="Notifications" /> }))
|
|
|
|
import { AppShell } from '@/components/layout/app-shell'
|
|
|
|
beforeEach(() => {
|
|
push.mockClear()
|
|
refresh.mockClear()
|
|
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: true }))
|
|
})
|
|
|
|
describe('AppShell', () => {
|
|
it('has a 56px dark top bar, a grey sidebar and the page content', () => {
|
|
const { container } = render(<AppShell role="hse" userName="Ada Lovelace"><p>page body</p></AppShell>)
|
|
expect(container.querySelector('header')?.className).toContain('h-14')
|
|
expect(container.querySelector('header')?.className).toContain('bg-topbar')
|
|
expect(container.querySelector('aside')?.className).toContain('bg-rule')
|
|
expect(container.querySelector('aside')?.className).toContain('w-60')
|
|
expect(screen.getByText('page body')).toBeTruthy()
|
|
expect(screen.getByText('Setia HSE')).toBeTruthy()
|
|
})
|
|
|
|
it('marks the active sidebar item with aria-current on a white ringed item', () => {
|
|
render(<AppShell role="hse" userName="Ada"><span /></AppShell>)
|
|
const active = screen.getAllByRole('link', { name: /CAPA/ }).find(a => a.getAttribute('aria-current') === 'page')!
|
|
expect(active.className).toContain('bg-surface')
|
|
expect(active.className).toContain('shadow-chip')
|
|
})
|
|
|
|
it('shows a GET search form that targets the incident list for HSE roles', () => {
|
|
const { container } = render(<AppShell role="hse" userName="Ada"><span /></AppShell>)
|
|
const form = container.querySelector('header form')!
|
|
expect(form.getAttribute('action')).toBe('/hse/incidents')
|
|
expect(form.getAttribute('method')).toBe('get')
|
|
expect((form.querySelector('input') as HTMLInputElement).name).toBe('q')
|
|
})
|
|
|
|
it('focuses the search box on Cmd-K', () => {
|
|
render(<AppShell role="hse" userName="Ada"><span /></AppShell>)
|
|
fireEvent.keyDown(document, { key: 'k', metaKey: true })
|
|
expect(document.activeElement?.getAttribute('name')).toBe('q')
|
|
})
|
|
|
|
it('hides the search box for roles without an incident list', () => {
|
|
const { container } = render(<AppShell role="ssa" userName="Ada"><span /></AppShell>)
|
|
expect(container.querySelector('header form')).toBeNull()
|
|
})
|
|
|
|
it('shows the user chip, version label, and logs out', async () => {
|
|
render(<AppShell role="hse" userName="Ada Lovelace"><span /></AppShell>)
|
|
expect(screen.getAllByText('AL').length).toBeGreaterThan(0)
|
|
expect(screen.getByText('v1.2.2')).toBeTruthy()
|
|
fireEvent.click(screen.getAllByRole('button', { name: /Log ?out/i })[0])
|
|
await Promise.resolve()
|
|
expect(fetch).toHaveBeenCalledWith('/api/auth/logout', { method: 'POST' })
|
|
})
|
|
|
|
it('renders a mobile tab bar that is hidden from md up', () => {
|
|
const { container } = render(<AppShell role="hse" userName="Ada"><span /></AppShell>)
|
|
const nav = container.querySelector('nav[aria-label="Mobile"]')!
|
|
expect(nav.className).toContain('md:hidden')
|
|
expect(nav.className).toContain('border-t')
|
|
})
|
|
|
|
it('has no 2px rules', () => {
|
|
const { container } = render(<AppShell role="admin" userName="Ada"><span /></AppShell>)
|
|
expect(container.innerHTML).not.toMatch(/border-[a-z]?-?2\b/)
|
|
})
|
|
})
|