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.

1.9 KB
Raw Blame
import { render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { useState } from 'react'
import FloatRightContainer from '../index'

it('opens mobile content in a named drawer and closes it through the supplied action', async () => {
  const user = userEvent.setup()
  const onClose = vi.fn()
  function Harness() {
    const [open, setOpen] = useState(false)
    return (
      <>
        <button type="button" onClick={() => setOpen(true)}>
          Open panel
        </button>
        <FloatRightContainer
          presentation="drawer"
          isOpen={open}
          title="Mobile panel"
          showClose
          onClose={() => {
            setOpen(false)
            onClose()
          }}
        >
          Mobile content
        </FloatRightContainer>
      </>
    )
  }
  render(<Harness />)
  await user.click(screen.getByRole('button', { name: 'Open panel' }))
  expect(await screen.findByRole('dialog', { name: 'Mobile panel' })).toBeInTheDocument()
  expect(screen.getByText('Mobile content')).toBeVisible()
  await user.click(screen.getByRole('button', { name: 'common.operation.close' }))
  await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
  expect(onClose).toHaveBeenCalledOnce()
})

it('shows desktop content inline only while open', () => {
  const { rerender } = render(
    <FloatRightContainer presentation="inline" isOpen onClose={vi.fn()} title="Drawer title">
      Desktop content
    </FloatRightContainer>,
  )
  expect(screen.getByText('Desktop content')).toBeVisible()
  expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
  expect(screen.queryByText('Drawer title')).not.toBeInTheDocument()
  rerender(
    <FloatRightContainer presentation="inline" isOpen={false} onClose={vi.fn()}>
      Desktop content
    </FloatRightContainer>,
  )
  expect(screen.queryByText('Desktop content')).not.toBeInTheDocument()
})