mirror of
https://github.com/langgenius/dify.git
synced 2026-06-26 06:41:10 +08:00
Merge 672c9052b4 into bb921bcc45
This commit is contained in:
commit
0fe1e6df24
@ -48,9 +48,6 @@ vi.mock('../content-switch', () => ({
|
||||
},
|
||||
}))
|
||||
vi.mock('copy-to-clipboard', () => ({ default: vi.fn() }))
|
||||
vi.mock('@/app/components/base/markdown', () => ({
|
||||
Markdown: ({ content }: { content: string }) => <div className="markdown-body">{content}</div>,
|
||||
}))
|
||||
|
||||
// Mock ResizeObserver and capture lifecycle for targeted coverage
|
||||
const observeMock = vi.fn()
|
||||
@ -132,13 +129,20 @@ describe('Question component', () => {
|
||||
it('should render the question content container and default avatar when hideAvatar is false', () => {
|
||||
const { container } = renderWithProvider(makeItem())
|
||||
|
||||
const markdown = container.querySelector('.markdown-body')
|
||||
expect(markdown).toBeInTheDocument()
|
||||
expect(screen.getByTestId('question-content')).toHaveTextContent('This is the question content')
|
||||
|
||||
const avatar = container.querySelector('.size-10') || container.querySelector('.size-10.shrink-0')
|
||||
expect(avatar).toBeTruthy()
|
||||
})
|
||||
|
||||
it('should render user-entered HTML as plain text', () => {
|
||||
renderWithProvider(makeItem({ content: '<button class="primary-button">Confirm</button>' }))
|
||||
|
||||
const content = screen.getByTestId('question-content')
|
||||
expect(content).toHaveTextContent('<button class="primary-button">Confirm</button>')
|
||||
expect(content.querySelector('button.primary-button')).toBeNull()
|
||||
})
|
||||
|
||||
it('should hide avatar when hideAvatar is true', () => {
|
||||
const { container } = renderWithProvider(makeItem(), vi.fn() as unknown as OnRegenerate, { hideAvatar: true })
|
||||
const avatar = container.querySelector('.size-10')
|
||||
@ -223,9 +227,9 @@ describe('Question component', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should cancel editing and revert to original markdown when cancel is clicked', async () => {
|
||||
it('should cancel editing and revert to original text when cancel is clicked', async () => {
|
||||
const user = userEvent.setup()
|
||||
const { container } = renderWithProvider(makeItem())
|
||||
renderWithProvider(makeItem())
|
||||
|
||||
const editBtn = screen.getByRole('button', { name: 'common.operation.edit' })
|
||||
await user.click(editBtn)
|
||||
@ -239,8 +243,7 @@ describe('Question component', () => {
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByRole('textbox')).not.toBeInTheDocument()
|
||||
const md = container.querySelector('.markdown-body')
|
||||
expect(md).toBeInTheDocument()
|
||||
expect(screen.getByTestId('question-content')).toHaveTextContent('This is the question content')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@ import { useTranslation } from 'react-i18next'
|
||||
import Textarea from 'react-textarea-autosize'
|
||||
import { FileList } from '@/app/components/base/file-uploader'
|
||||
import { User } from '@/app/components/base/icons/src/public/avatar'
|
||||
import { Markdown } from '@/app/components/base/markdown'
|
||||
import ActionButton from '../../action-button'
|
||||
import { CssTransform } from '../embedded-chatbot/theme/utils'
|
||||
import ContentSwitch from './content-switch'
|
||||
@ -206,7 +205,7 @@ const Question: FC<QuestionProps> = ({
|
||||
)
|
||||
}
|
||||
{!isEditing
|
||||
? <Markdown content={content} />
|
||||
? <div className="whitespace-pre-wrap break-words">{content}</div>
|
||||
: (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="max-h-[158px] overflow-x-hidden overflow-y-auto pr-1">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user