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.2 KB
Raw Blame
import { cleanup, render, screen } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vite-plus/test'
import DeprecationNotice from '../deprecation-notice'

vi.mock('@/next/link', () => ({
  default: ({ children, href }: { children: React.ReactNode; href: string }) => (
    <a data-testid="link" href={href}>
      {children}
    </a>
  ),
}))

describe('DeprecationNotice', () => {
  beforeEach(() => {
    vi.clearAllMocks()
  })

  afterEach(() => {
    cleanup()
  })

  it('returns null when status is not "deleted"', () => {
    const { container } = render(
      <DeprecationNotice
        status="active"
        deprecatedReason="business_adjustments"
        alternativePluginId="alt-plugin"
        alternativePluginURL="/plugins/alt-plugin"
      />,
    )
    expect(container.firstChild).toBeNull()
  })

  it('renders deprecation notice when status is "deleted"', () => {
    render(
      <DeprecationNotice
        status="deleted"
        deprecatedReason=""
        alternativePluginId=""
        alternativePluginURL=""
      />,
    )
    expect(screen.getByText('plugin.detailPanel.deprecation.noReason')).toBeInTheDocument()
  })

  it('renders with valid reason and alternative plugin', () => {
    render(
      <DeprecationNotice
        status="deleted"
        deprecatedReason="business_adjustments"
        alternativePluginId="better-plugin"
        alternativePluginURL="/plugins/better-plugin"
      />,
    )
    expect(screen.getByText('plugin.detailPanel.deprecation.fullMessage')).toBeInTheDocument()
  })

  it('renders only reason without alternative plugin', () => {
    render(
      <DeprecationNotice
        status="deleted"
        deprecatedReason="no_maintainer"
        alternativePluginId=""
        alternativePluginURL=""
      />,
    )
    expect(screen.getByText(/plugin\.detailPanel\.deprecation\.onlyReason/)).toBeInTheDocument()
  })

  it('renders no-reason message for invalid reason', () => {
    render(
      <DeprecationNotice
        status="deleted"
        deprecatedReason="unknown_reason"
        alternativePluginId=""
        alternativePluginURL=""
      />,
    )
    expect(screen.getByText('plugin.detailPanel.deprecation.noReason')).toBeInTheDocument()
  })
})