dify/web/app/(commonLayout)/agents/__tests__/layout.spec.tsx
Stephen Zhou a84c2d36a3
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-12 15:57:46 +00:00

46 lines
1.1 KiB
TypeScript

import { render, screen } from '@testing-library/react'
const mocks = vi.hoisted(() => ({
guardAgentV2Route: vi.fn(),
}))
vi.mock('../feature-guard', () => ({
guardAgentV2Route: () => mocks.guardAgentV2Route(),
}))
describe('RosterLayout', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('should render children when Agent v2 is enabled', async () => {
const { default: RosterLayout } = await import('../layout')
render(
<RosterLayout>
<div>Roster content</div>
</RosterLayout>,
)
expect(mocks.guardAgentV2Route).toHaveBeenCalledTimes(1)
expect(screen.getByText('Roster content')).toBeInTheDocument()
})
it('should block rendering when the roster guard throws notFound', async () => {
mocks.guardAgentV2Route.mockImplementation(() => {
throw new Error('NEXT_NOT_FOUND')
})
const { default: RosterLayout } = await import('../layout')
expect(() =>
render(
<RosterLayout>
<div>Roster content</div>
</RosterLayout>,
),
).toThrow('NEXT_NOT_FOUND')
expect(mocks.guardAgentV2Route).toHaveBeenCalled()
})
})