fix: rewrite layout.nav.test to match actual RootLayout props
Remove tests for non-existent 'nav' slot prop and rewrite tests to match the actual RootLayout implementation. The RootLayout component only accepts children, not a nav prop. Updated tests verify the actual component behavior with ClientProviders wrapper. Fixes 2 TS2322 errors in layout.nav.test.tsx. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,54 +1,33 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import RootLayout from '../layout'
|
||||
|
||||
// Mock AppNavBar to verify it receives the nav prop
|
||||
const MockAppNavBar = ({ navSlot }: { navSlot?: React.ReactNode }) => (
|
||||
<div data-testid="app-nav-bar">
|
||||
{navSlot && <div data-testid="nav-slot-content">{navSlot}</div>}
|
||||
</div>
|
||||
)
|
||||
|
||||
jest.mock('../../components/AppNavBar', () => ({
|
||||
AppNavBar: MockAppNavBar,
|
||||
// Mock ClientProviders
|
||||
vi.mock('../../components/ClientProviders', () => ({
|
||||
ClientProviders: ({ children }: { children: React.ReactNode }) => (
|
||||
<div data-testid="client-providers">{children}</div>
|
||||
),
|
||||
}))
|
||||
|
||||
// Mock all context providers
|
||||
jest.mock('../../contexts/AbacusDisplayContext', () => ({
|
||||
AbacusDisplayProvider: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
}))
|
||||
|
||||
jest.mock('../../contexts/UserProfileContext', () => ({
|
||||
UserProfileProvider: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
}))
|
||||
|
||||
jest.mock('../../contexts/GameModeContext', () => ({
|
||||
GameModeProvider: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
}))
|
||||
|
||||
jest.mock('../../contexts/FullscreenContext', () => ({
|
||||
FullscreenProvider: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
}))
|
||||
|
||||
describe('RootLayout with nav slot', () => {
|
||||
it('passes nav slot to AppNavBar', () => {
|
||||
const navContent = <div>Memory Lightning</div>
|
||||
describe('RootLayout', () => {
|
||||
it('renders children with ClientProviders', () => {
|
||||
const pageContent = <div>Page content</div>
|
||||
|
||||
render(<RootLayout nav={navContent}>{pageContent}</RootLayout>)
|
||||
render(<RootLayout>{pageContent}</RootLayout>)
|
||||
|
||||
expect(screen.getByTestId('app-nav-bar')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('nav-slot-content')).toBeInTheDocument()
|
||||
expect(screen.getByText('Memory Lightning')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('client-providers')).toBeInTheDocument()
|
||||
expect(screen.getByText('Page content')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('works without nav slot', () => {
|
||||
const pageContent = <div>Page content</div>
|
||||
it('renders html and body tags', () => {
|
||||
const pageContent = <div>Test content</div>
|
||||
|
||||
render(<RootLayout nav={null}>{pageContent}</RootLayout>)
|
||||
const { container } = render(<RootLayout>{pageContent}</RootLayout>)
|
||||
|
||||
expect(screen.getByTestId('app-nav-bar')).toBeInTheDocument()
|
||||
expect(screen.queryByTestId('nav-slot-content')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('Page content')).toBeInTheDocument()
|
||||
const html = container.querySelector('html')
|
||||
const body = container.querySelector('body')
|
||||
|
||||
expect(html).toBeInTheDocument()
|
||||
expect(html).toHaveAttribute('lang', 'en')
|
||||
expect(body).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user