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.4 KB
Raw Blame
import { render } from 'vitest-browser-react'
import { IconButton } from '../../icon-button'
import {
  Drawer,
  DrawerBackdrop,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerPopup,
  DrawerPortal,
  DrawerTitle,
  DrawerTrigger,
  DrawerViewport,
} from '../index'

const asHTMLElement = (element: HTMLElement | SVGElement) => element as HTMLElement

describe('Drawer wrapper', () => {
  describe('User Interactions', () => {
    it('should open a portalled drawer and close it with a composed close button', async () => {
      const screen = await render(
        <Drawer>
          <DrawerTrigger>Open settings</DrawerTrigger>
          <DrawerPortal>
            <DrawerBackdrop data-testid="drawer-backdrop" />
            <DrawerViewport>
              <DrawerPopup>
                <DrawerTitle>Settings</DrawerTitle>
                <DrawerDescription>Configure the current workspace.</DrawerDescription>
                <DrawerContent>
                  <p>Workspace controls</p>
                  <DrawerClose
                    render={
                      <IconButton aria-label="Close drawer" size="lg">
                        <span aria-hidden="true" className="i-ri-close-line size-4" />
                      </IconButton>
                    }
                  />
                </DrawerContent>
              </DrawerPopup>
            </DrawerViewport>
          </DrawerPortal>
        </Drawer>,
      )

      expect(document.body.querySelector('[role="dialog"]')).not.toBeInTheDocument()

      await screen.getByRole('button', { name: 'Open settings' }).click()

      await vi.waitFor(() => {
        expect(document.body.querySelector('[role="dialog"]')).toBeInTheDocument()
      })

      const dialog = asHTMLElement(document.body.querySelector('[role="dialog"]')!)
      expect(document.body).toContainElement(dialog)
      expect(screen.container).not.toContainElement(dialog)
      await expect
        .element(screen.getByRole('dialog', { name: 'Settings' }))
        .toHaveAccessibleDescription('Configure the current workspace.')
      await expect.element(screen.getByText('Workspace controls')).toBeInTheDocument()
      await expect.element(screen.getByTestId('drawer-backdrop')).toBeInTheDocument()

      await screen.getByRole('button', { name: 'Close drawer' }).click()

      await vi.waitFor(() => {
        expect(document.body.querySelector('[role="dialog"]')).not.toBeInTheDocument()
      })
    })
  })
})