dify/web/app/(commonLayout)/agents/__tests__/layout.spec.tsx
Xiyuan Chen b56ac4af4d
feat: gate agent management behind the agent.manage permission (#39330)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
2026-07-23 07:34:07 +00:00

53 lines
1.4 KiB
TypeScript

import type { ReactNode } from 'react'
import { render, screen } from '@testing-library/react'
const mocks = vi.hoisted(() => ({
guardAgentV2Route: vi.fn(),
}))
vi.mock('../feature-guard', () => ({
guardAgentV2Route: () => mocks.guardAgentV2Route(),
}))
// Access control is covered by agents-access-guard.spec.tsx; this suite is
// about the feature-flag guard only.
vi.mock('../agents-access-guard', () => ({
AgentsAccessGuard: ({ children }: { children: ReactNode }) => <>{children}</>,
}))
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()
})
})