-LAN- 85cda47c70
feat: knowledge pipeline (#25360)
Signed-off-by: -LAN- <laipz8200@outlook.com>
Co-authored-by: twwu <twwu@dify.ai>
Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
Co-authored-by: jyong <718720800@qq.com>
Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com>
Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com>
Co-authored-by: lyzno1 <yuanyouhuilyz@gmail.com>
Co-authored-by: quicksand <quicksandzn@gmail.com>
Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com>
Co-authored-by: lyzno1 <92089059+lyzno1@users.noreply.github.com>
Co-authored-by: zxhlyh <jasonapring2015@outlook.com>
Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Joel <iamjoel007@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: nite-knite <nkCoding@gmail.com>
Co-authored-by: Hanqing Zhao <sherry9277@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Harry <xh001x@hotmail.com>
2025-09-18 12:49:10 +08:00

122 lines
3.9 KiB
TypeScript

import React from 'react'
import { cleanup, fireEvent, render } from '@testing-library/react'
import '@testing-library/jest-dom'
import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger } from '.'
afterEach(cleanup)
describe('PortalToFollowElem', () => {
describe('Context and Provider', () => {
test('should throw error when using context outside provider', () => {
// Suppress console.error for this test
const originalError = console.error
console.error = jest.fn()
expect(() => {
render(
<PortalToFollowElemTrigger>Trigger</PortalToFollowElemTrigger>,
)
}).toThrow('PortalToFollowElem components must be wrapped in <PortalToFollowElem />')
console.error = originalError
})
test('should not throw when used within provider', () => {
expect(() => {
render(
<PortalToFollowElem>
<PortalToFollowElemTrigger>Trigger</PortalToFollowElemTrigger>
</PortalToFollowElem>,
)
}).not.toThrow()
})
})
describe('PortalToFollowElemTrigger', () => {
test('should render children correctly', () => {
const { getByText } = render(
<PortalToFollowElem>
<PortalToFollowElemTrigger>Trigger Text</PortalToFollowElemTrigger>
</PortalToFollowElem>,
)
expect(getByText('Trigger Text')).toBeInTheDocument()
})
test('should handle asChild prop correctly', () => {
const { getByRole } = render(
<PortalToFollowElem>
<PortalToFollowElemTrigger asChild >
<button>Button Trigger</button>
</PortalToFollowElemTrigger>
</PortalToFollowElem>,
)
expect(getByRole('button')).toHaveTextContent('Button Trigger')
})
})
describe('PortalToFollowElemContent', () => {
test('should not render content when closed', () => {
const { queryByText } = render(
<PortalToFollowElem open={false} >
<PortalToFollowElemTrigger>Trigger</PortalToFollowElemTrigger>
<PortalToFollowElemContent>Popup Content</PortalToFollowElemContent>
</PortalToFollowElem>,
)
expect(queryByText('Popup Content')).not.toBeInTheDocument()
})
test('should render content when open', () => {
const { getByText } = render(
<PortalToFollowElem open={true} >
<PortalToFollowElemTrigger>Trigger </PortalToFollowElemTrigger>
<PortalToFollowElemContent>Popup Content</PortalToFollowElemContent>
</PortalToFollowElem>,
)
expect(getByText('Popup Content')).toBeInTheDocument()
})
})
describe('Controlled behavior', () => {
test('should call onOpenChange when interaction happens', () => {
const handleOpenChange = jest.fn()
const { getByText } = render(
<PortalToFollowElem onOpenChange={handleOpenChange} >
<PortalToFollowElemTrigger>Hover Me</PortalToFollowElemTrigger>
<PortalToFollowElemContent>Content</PortalToFollowElemContent>
</PortalToFollowElem>,
)
fireEvent.mouseEnter(getByText('Hover Me'))
expect(handleOpenChange).toHaveBeenCalled()
fireEvent.mouseLeave(getByText('Hover Me'))
expect(handleOpenChange).toHaveBeenCalled()
})
})
describe('Configuration options', () => {
test('should accept placement prop', () => {
// Since we can't easily test actual positioning, we'll check if the prop is passed correctly
const useFloatingMock = jest.spyOn(require('@floating-ui/react'), 'useFloating')
render(
<PortalToFollowElem placement='top-start' >
<PortalToFollowElemTrigger>Trigger</PortalToFollowElemTrigger>
</PortalToFollowElem>,
)
expect(useFloatingMock).toHaveBeenCalledWith(
expect.objectContaining({
placement: 'top-start',
}),
)
useFloatingMock.mockRestore()
})
})
})