Files
carmanagement/apps/admin/src/components/PublicShell.test.ts
T
root 0c9f3f8635 fix: resolve TS18046 errors for React 19 element props type
React 19 types React.ReactElement props as unknown instead of any. Test
helper functions that access element.props.children, .className, or .href
need explicit props type parameters on React.ReactElement and isValidElement.

Changes:
- admin/PublicShell.test.ts: add WithChildren type, use React.ReactElement<WithChildren>
- dashboard/PublicShell.test.ts: same pattern for childTypes and contentWrapper
- dashboard/StatCard.test.ts: add ElementWithClass type for className access
- dashboard/public-auth-pages.test.ts: add ElementWithHref type for href access

No any, @ts-ignore, or type assertion bypass used.
2026-06-28 01:21:36 -04:00

34 lines
1.4 KiB
TypeScript

import React, { isValidElement } from 'react'
import { describe, expect, it, vi } from 'vitest'
vi.mock('@/components/PublicHeader', () => ({ default: function MockAdminHeader() { return React.createElement('admin-header') } }))
vi.mock('@/components/PublicFooter', () => ({ default: function MockAdminFooter() { return React.createElement('admin-footer') } }))
import PublicShell from './PublicShell'
type WithChildren = { children?: React.ReactNode }
function childTypes(node: React.ReactElement<WithChildren>): string[] {
return React.Children.toArray(node.props.children).filter(isValidElement).map((child) => {
const type = child.type as any
if (typeof type === 'string') return type
return type.displayName ?? type.name ?? 'anonymous'
})
}
describe('admin PublicShell', () => {
it('always renders the admin public chrome around children', () => {
const shell = PublicShell({ children: React.createElement('section', { id: 'login' }) })
expect(childTypes(shell)).toEqual(['MockAdminHeader', 'div', 'MockAdminFooter'])
})
it('uses a flex column root so footer placement stays stable', () => {
const shell = PublicShell({ children: React.createElement('section') })
expect(shell.props.className).toContain('flex')
expect(shell.props.className).toContain('min-h-screen')
expect(shell.props.className).toContain('flex-col')
})
})