@@ -2,7 +2,7 @@ import type { Theme } from '../../embedded-chatbot/theme/theme-context'
22import type { ChatConfig , ChatItem , OnRegenerate } from '../../types'
33import type { FileEntity } from '@/app/components/base/file-uploader/types'
44import { toast } from '@langgenius/dify-ui/toast'
5- import { act , fireEvent , render , screen , waitFor } from '@testing-library/react'
5+ import { act , fireEvent , render , screen , waitFor , within } from '@testing-library/react'
66import userEvent from '@testing-library/user-event'
77import copy from 'copy-to-clipboard'
88import * as React from 'react'
@@ -48,9 +48,6 @@ vi.mock('../content-switch', () => ({
4848 } ,
4949} ) )
5050vi . mock ( 'copy-to-clipboard' , ( ) => ( { default : vi . fn ( ) } ) )
51- vi . mock ( '@/app/components/base/markdown' , ( ) => ( {
52- Markdown : ( { content } : { content : string } ) => < div className = "markdown-body" > { content } </ div > ,
53- } ) )
5451
5552// Mock ResizeObserver and capture lifecycle for targeted coverage
5653const observeMock = vi . fn ( )
@@ -132,13 +129,23 @@ describe('Question component', () => {
132129 it ( 'should render the question content container and default avatar when hideAvatar is false' , ( ) => {
133130 const { container } = renderWithProvider ( makeItem ( ) )
134131
135- const markdown = container . querySelector ( '.markdown-body' )
136- expect ( markdown ) . toBeInTheDocument ( )
132+ expect ( screen . getByTestId ( 'question-content' ) ) . toHaveTextContent ( 'This is the question content' )
137133
138134 const avatar = container . querySelector ( '.size-10' ) || container . querySelector ( '.size-10.shrink-0' )
139135 expect ( avatar ) . toBeTruthy ( )
140136 } )
141137
138+ it ( 'should render user supplied HTML as plain text' , ( ) => {
139+ const content = '<button class="primary-button">Confirm</button>'
140+ renderWithProvider ( makeItem ( { content } ) )
141+
142+ const contentContainer = screen . getByTestId ( 'question-content' )
143+
144+ expect ( contentContainer ) . toHaveTextContent ( content )
145+ expect ( within ( contentContainer ) . queryByRole ( 'button' , { name : 'Confirm' } ) ) . not . toBeInTheDocument ( )
146+ expect ( contentContainer . querySelector ( '.primary-button' ) ) . not . toBeInTheDocument ( )
147+ } )
148+
142149 it ( 'should hide avatar when hideAvatar is true' , ( ) => {
143150 const { container } = renderWithProvider ( makeItem ( ) , vi . fn ( ) as unknown as OnRegenerate , { hideAvatar : true } )
144151 const avatar = container . querySelector ( '.size-10' )
@@ -223,9 +230,9 @@ describe('Question component', () => {
223230 } )
224231 } )
225232
226- it ( 'should cancel editing and revert to original markdown when cancel is clicked' , async ( ) => {
233+ it ( 'should cancel editing and revert to original text when cancel is clicked' , async ( ) => {
227234 const user = userEvent . setup ( )
228- const { container } = renderWithProvider ( makeItem ( ) )
235+ renderWithProvider ( makeItem ( ) )
229236
230237 const editBtn = screen . getByRole ( 'button' , { name : 'common.operation.edit' } )
231238 await user . click ( editBtn )
@@ -239,8 +246,7 @@ describe('Question component', () => {
239246
240247 await waitFor ( ( ) => {
241248 expect ( screen . queryByRole ( 'textbox' ) ) . not . toBeInTheDocument ( )
242- const md = container . querySelector ( '.markdown-body' )
243- expect ( md ) . toBeInTheDocument ( )
249+ expect ( screen . getByTestId ( 'question-content' ) ) . toHaveTextContent ( 'This is the question content' )
244250 } )
245251 } )
246252
0 commit comments