Skip to content

Commit bbe902d

Browse files
Merge pull request #587 from microsoft/fix-tests
fix: Frontend tests
2 parents 950268c + 16ec8f9 commit bbe902d

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/frontend/src/components/Answer/Answer.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const mockCitations: Citation[] = [
7373
}
7474
]
7575
let mockAnswerProps: AskResponse = {
76-
answer: 'This is an example answer with citations [doc1] and [doc2] and [doc3].',
76+
answer: 'This is an example answer with citations [1] and [2] and [3].',
7777
message_id: '123',
7878
feedback: Feedback.Neutral,
7979
citations: cloneDeep(mockCitations)
@@ -133,7 +133,7 @@ describe('Answer Component', () => {
133133

134134
const answerWithMissingFeedback = {
135135
...mockAnswerProps,
136-
answer: 'This is an example answer with citations [doc1]',
136+
answer: 'This is an example answer with citations [1]',
137137
citations: [mockCitations[0]] // Only include one citation
138138
}
139139

src/frontend/src/components/Answer/AnswerParser.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const sampleCitations: Citation[] = [
4141
]
4242

4343
const sampleAnswer: AskResponse = {
44-
answer: 'This is an example answer with citations [doc1] and [doc2].',
44+
answer: 'This is an example answer with citations [1] and [2].',
4545
citations: cloneDeep(sampleCitations)
4646
}
4747

@@ -57,13 +57,13 @@ describe('enumerateCitations', () => {
5757
describe('parseAnswer', () => {
5858
it('reformats the answer text and reindexes citations', () => {
5959
const parsed: ParsedAnswer = parseAnswer(sampleAnswer)
60-
expect(parsed.markdownFormatText).toBe('This is an example answer with citations [doc1] and [doc2].')
61-
expect(parsed.citations.length).toBe(3)
60+
expect(parsed.markdownFormatText).toBe('This is an example answer with citations ^1^ and ^2^ .')
61+
expect(parsed.citations.length).toBe(2)
6262
expect(parsed.citations[0].id).toBe('doc1')
63-
// expect(parsed.citations[0].reindex_id).toBe('1')
64-
// expect(parsed.citations[1].id).toBe('2')
65-
// // expect(parsed.citations[1].reindex_id).toBe('2')
66-
// expect(parsed.citations[0].part_index).toBe(1)
67-
// expect(parsed.citations[1].part_index).toBe(2)
63+
expect(parsed.citations[0].reindex_id).toBe('1')
64+
expect(parsed.citations[1].id).toBe('doc2')
65+
expect(parsed.citations[1].reindex_id).toBe('2')
66+
expect(parsed.citations[0].part_index).toBe(1)
67+
expect(parsed.citations[1].part_index).toBe(2)
6868
})
6969
})

src/frontend/src/components/DraftCards/SectionCard.test.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React from 'react'
22
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
3+
import { act } from 'react'
34
import '@testing-library/jest-dom'
45
import SectionCard from './SectionCard'
56
import { AppStateContext } from '../../state/AppProvider'
67
import { sectionGenerate } from '../../api'
78
import { MemoryRouter } from 'react-router-dom'
89

910
import { ChatHistoryLoadingState } from '../../api/models'
10-
import { act } from 'react-dom/test-utils'
1111

1212
import {defaultMockState} from '../../test/test.utils';
1313

@@ -77,17 +77,27 @@ describe('SectionCard Component', () => {
7777
})
7878

7979
it('When context not available throws an error', async () => {
80+
// Suppress console.error for this test to avoid cluttering test output
81+
const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {})
82+
8083
expect(() =>
8184
render(
8285
<MemoryRouter>
8386
<SectionCard sectionIdx={0} />
8487
</MemoryRouter>
8588
)
8689
).toThrow('useAppState must be used within a AppStateProvider')
90+
91+
consoleSpy.mockRestore()
8792
})
8893

8994
it('When no section available in context throws an error', async () => {
95+
// Suppress console.error for this test to avoid cluttering test output
96+
const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {})
97+
9098
expect(() => renderWithContext(2)).toThrow('Section not found')
99+
100+
consoleSpy.mockRestore()
91101
})
92102

93103
it('renders section title and description', async () => {

0 commit comments

Comments
 (0)