chore(web): enhance frontend tests (#29859)

This commit is contained in:
yyh
2025-12-18 16:46:12 +08:00
committed by GitHub
parent 9bb5670711
commit 9f24cff9dd
2 changed files with 191 additions and 9 deletions

View File

@@ -77,24 +77,53 @@ describe('ViewAnnotationModal', () => {
fetchHitHistoryListMock.mockResolvedValue({ data: [], total: 0 })
})
it('should render annotation tab and allow saving updated content', async () => {
it('should render annotation tab and allow saving updated query', async () => {
// Arrange
const { props } = renderComponent()
await waitFor(() => {
expect(fetchHitHistoryListMock).toHaveBeenCalled()
})
// Act
fireEvent.click(screen.getByTestId('edit-query'))
// Assert
await waitFor(() => {
expect(props.onSave).toHaveBeenCalledWith('query-updated', props.item.answer)
})
})
it('should render annotation tab and allow saving updated answer', async () => {
// Arrange
const { props } = renderComponent()
fireEvent.click(screen.getByTestId('edit-answer'))
await waitFor(() => {
expect(props.onSave).toHaveBeenCalledWith(props.item.question, 'answer-updated')
expect(fetchHitHistoryListMock).toHaveBeenCalled()
})
// Act
fireEvent.click(screen.getByTestId('edit-answer'))
// Assert
await waitFor(() => {
expect(props.onSave).toHaveBeenCalledWith(props.item.question, 'answer-updated')
},
)
})
it('should switch to hit history tab and show no data message', async () => {
// Arrange
const { props } = renderComponent()
await waitFor(() => {
expect(fetchHitHistoryListMock).toHaveBeenCalled()
})
// Act
fireEvent.click(screen.getByText('appAnnotation.viewModal.hitHistory'))
// Assert
expect(await screen.findByText('appAnnotation.viewModal.noHitHistory')).toBeInTheDocument()
expect(mockFormatTime).toHaveBeenCalledWith(props.item.created_at, 'appLog.dateTimeFormat')
})