Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

2.1 KB
Raw Blame
import type { Dependency } from '@/app/components/plugins/types'
import { render, screen } from '@testing-library/react'
import { useStore as usePluginDependencyStore } from '@/app/components/workflow/plugin-dependency/store'

const mocks = vi.hoisted(() => ({
  guardAgentV2Route: vi.fn(),
}))

vi.mock('@/app/components/plugins/install-plugin/install-bundle', () => ({
  default: ({ fromDSLPayload }: { fromDSLPayload: Dependency[] }) => (
    <div role="dialog" aria-label="Install missing plugins">
      {`bundle-size:${fromDSLPayload.length}`}
    </div>
  ),
}))

vi.mock('../feature-guard', () => ({
  guardAgentV2Route: () => mocks.guardAgentV2Route(),
}))

describe('RosterLayout', () => {
  beforeEach(() => {
    mocks.guardAgentV2Route.mockReset()
    usePluginDependencyStore.setState({ dependencies: [] })
  })

  it('should show the missing-plugin installer across Agent routes', async () => {
    usePluginDependencyStore.setState({
      dependencies: [
        {
          type: 'marketplace',
          value: {
            organization: 'langgenius',
            plugin: 'sample-plugin',
            version: '1.0.0',
            plugin_unique_identifier: 'langgenius/sample-plugin:1.0.0',
          },
        },
      ],
    })
    const { default: RosterLayout } = await import('../layout')

    render(
      <RosterLayout>
        <div>Agent route content</div>
      </RosterLayout>,
    )

    expect(screen.getByRole('dialog', { name: 'Install missing plugins' })).toHaveTextContent(
      'bundle-size:1',
    )
    expect(screen.getByText('Agent route content')).toBeInTheDocument()
    expect(mocks.guardAgentV2Route).toHaveBeenCalledOnce()
  })

  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()
  })
})