Skip to content

Commit 1f9b5cc

Browse files
Merge pull request microsoft#329 from microsoft/psl-bug-16193
fix: psl bug 16193
2 parents b790dc5 + ab0480e commit 1f9b5cc

File tree

10 files changed

+280
-138
lines changed

10 files changed

+280
-138
lines changed

src/frontend/src/components/ChatHistory/ChatHistoryList.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import { AppStateContext } from '../../state/AppProvider';
44
import ChatHistoryList from './ChatHistoryList';
55
import { Conversation } from '../../api/models';
66
import { ChatHistoryLoadingState } from '../../api/models';
7+
import {defaultMockState} from '../../test/test.utils';
8+
79

810
const mockDispatch = jest.fn();
911

1012
const mockState = {
13+
...defaultMockState,
1114
isChatHistoryOpen: false,
1215
chatHistoryLoadingState: ChatHistoryLoadingState.Loading,
1316
isCosmosDBAvailable: {
@@ -27,7 +30,7 @@ const mockState = {
2730
isRequestInitiated: false,
2831
failedSections : [],
2932
isFailedReqInitiated : false,
30-
isLoading : false,
33+
isLoading : false
3134
};
3235

3336
const renderChatHistoryList = (stateOverride = {}) => {

src/frontend/src/components/ChatHistory/ChatHistoryPanel.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { AppStateContext } from '../../state/AppProvider';
44
import { ChatHistoryPanel } from './ChatHistoryPanel';
55
import { ChatHistoryLoadingState, ChatMessage, Conversation, CosmosDBStatus, Feedback, historyDeleteAll,historyList } from '../../api';
66
import * as api from '../../api';
7+
import {defaultMockState} from '../../test/test.utils';
8+
79

810
// Mock the API function
911
jest.mock('../../api/api', () => ({
@@ -37,6 +39,7 @@ const mockConversation: Conversation = {
3739

3840
// Mock initial state for the context
3941
const mockState = {
42+
...defaultMockState,
4043
chatHistoryLoadingState: ChatHistoryLoadingState.Success,
4144
isCosmosDBAvailable: { cosmosDB: true, status: CosmosDBStatus.NotConfigured },
4245
chatHistory: [mockConversation], // Added mock chat history here
@@ -54,7 +57,7 @@ const mockState = {
5457
isRequestInitiated: false,
5558
failedSections : [],
5659
isFailedReqInitiated : false,
57-
isLoading : false,
60+
isLoading : false
5861
};
5962

6063
const mockDispatch = jest.fn();

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { MemoryRouter } from 'react-router-dom'
99
import { ChatHistoryLoadingState } from '../../api/models'
1010
import { act } from 'react-dom/test-utils'
1111

12+
import {defaultMockState} from '../../test/test.utils';
13+
1214
// Mock the API
1315
jest.mock('../../api/api', () => ({
1416
sectionGenerate: jest.fn(() =>
@@ -26,6 +28,7 @@ jest.mock('../../assets/Generate.svg', () => 'mocked-generate-icon')
2628

2729
const mockDispatch = jest.fn()
2830
const mockState = {
31+
...defaultMockState,
2932
draftedDocument: {
3033
title: 'Draft Document',
3134
sections: [
@@ -56,7 +59,7 @@ const mockState = {
5659
isRequestInitiated: false,
5760
failedSections : [],
5861
isFailedReqInitiated : false,
59-
isLoading : false,
62+
isLoading : false
6063
}
6164

6265
const renderWithContext = (idx = 0) =>
@@ -210,4 +213,7 @@ describe('SectionCard Component', () => {
210213
}
211214
})
212215
})
216+
217+
218+
213219
})

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const useStyles = makeStyles({
111111
}
112112
})
113113

114-
const SectionCard = ({ sectionIdx }: SectionCardProps) => {
114+
const SectionCard = ({ sectionIdx }: SectionCardProps) => {
115115
const location = useLocation()
116116
const classes = useStyles()
117117
const [isLoading, setIsLoading] = useState(false)
@@ -141,7 +141,6 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
141141

142142
useEffect(() => {
143143
if (appStateContext.state?.failedSections.length >0 && appStateContext.state?.failedSections[0].title === sectionTitle && isLoading && !appStateContext.state.isFailedReqInitiated) {
144-
console.log("appStateContext.state?.failedSections", appStateContext.state?.failedSections);
145144
const tempItem = {
146145
title: sectionTitle,
147146
description: sectionDescription,
@@ -157,13 +156,13 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
157156

158157
async function fetchSectionContent(sectionTitle: string, sectionDescription: string , isReqFrom = '') {
159158
setIsLoading(true)
159+
160160
const sectionGenerateRequest: SectionGenerateRequest = { sectionTitle, sectionDescription }
161161

162162
const response = await sectionGenerate(sectionGenerateRequest)
163163
const responseBody = await response.json()
164164

165165
if(responseBody?.error?.includes("429")) {
166-
console.log("retriggerd !!!")
167166
const failedSectionItems = {
168167
title: sectionTitle,
169168
description: sectionDescription,
@@ -192,9 +191,11 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
192191

193192
setCharCount(content.length)
194193
setIsLoading(false)
195-
196194
appStateContext?.dispatch({ type: 'REMOVED_FAILED_SECTION', payload: {section : updatedSection} })
197195

196+
appStateContext?.dispatch({ type: 'UPDATE_IS_LOADED_SECTIONS', payload: {section : updatedSection} })
197+
198+
198199
if(isReqFrom == 'failed')
199200
appStateContext?.dispatch({ type: 'UPDATE_SECTION_API_REQ_STATUS', payload: false })
200201
}
@@ -207,6 +208,11 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
207208
useEffect(() => {
208209
if (sectionContent === '' && !isLoading && !isManuallyCleared) {
209210
fetchSectionContent(sectionTitle, sectionDescription)
211+
}else {
212+
if(sectionContent!='' && !isLoading){
213+
const updatedSection: Section = {...section}
214+
appStateContext?.dispatch({ type: 'UPDATE_IS_LOADED_SECTIONS', payload: {section : updatedSection} })
215+
}
210216
}
211217
}, [sectionContent, isLoading, isManuallyCleared])
212218

@@ -256,6 +262,7 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
256262
console.error('Section description is empty')
257263
return
258264
}
265+
appStateContext?.dispatch({ type: 'UPDATE_IS_LOADED_SECTIONS', payload: {section : null, 'title' : sectionTitle ,'act' :'removeItem' } })
259266

260267
setIsPopoverOpen(false)
261268
fetchSectionContent(sectionTitle, updatedSectionDescription)

src/frontend/src/components/Sidebar/Sidebar.test.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Sidebar from './Sidebar';
55
import { ChatHistoryLoadingState } from '../../api/models';
66
import { BrowserRouter as Router, useLocation ,useNavigate} from 'react-router-dom';
77
import { getUserInfo } from '../../api';
8+
import {defaultMockState} from '../../test/test.utils';
89

910
const mockDispatch = jest.fn();
1011
beforeEach(() => {
@@ -35,6 +36,7 @@ jest.mock('react-router-dom', () => ({
3536
useLocation: jest.fn(),
3637
}));
3738
const mockState = {
39+
...defaultMockState,
3840
isChatHistoryOpen: false,
3941
chatHistoryLoadingState: ChatHistoryLoadingState.Loading,
4042
isCosmosDBAvailable: {
@@ -56,23 +58,7 @@ const mockState = {
5658
isFailedReqInitiated : false,
5759
isLoading : false,
5860
};
59-
const mockState2 = {
60-
isChatHistoryOpen: false,
61-
chatHistoryLoadingState: ChatHistoryLoadingState.Loading,
62-
chatHistory: null,
63-
filteredChatHistory: [],
64-
currentChat: null,
65-
browseChat: null,
66-
generateChat: null,
67-
isCosmosDBAvailable: {
68-
cosmosDB: false,
69-
status: 'NotConfigured'
70-
},
71-
frontendSettings: { auth_enabled: false },
72-
feedbackState: {},
73-
draftedDocument: null,
74-
draftedDocumentTitle: ''
75-
};
61+
7662
const renderSidebar = (stateOverride = {}, pathname = '/') => {
7763

7864
(useLocation as jest.Mock).mockReturnValue({ pathname });

0 commit comments

Comments
 (0)