-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix redirect new session when dock right (#36)
* fix: change to new session after history deleted Signed-off-by: Lin Wang <wonglam@amazon.com> * test: add miss file and style mock Signed-off-by: Lin Wang <wonglam@amazon.com> * feat: add unit test for clear deleted old chat session data Signed-off-by: Lin Wang <wonglam@amazon.com> * refactor: change handleEditConversationConfirmModalClose to handleEditConversationModalClose Signed-off-by: Lin Wang <wonglam@amazon.com> * Utilize barrel file for cleaner imports Example of using index.ts and importing one line instead of two. Signed-off-by: Kawika Avilla <kavilla414@gmail.com> * refactor: move hooks references to index.ts Signed-off-by: Lin Wang <wonglam@amazon.com> --------- Signed-off-by: Lin Wang <wonglam@amazon.com> Signed-off-by: Kawika Avilla <kavilla414@gmail.com> Co-authored-by: Kawika Avilla <kavilla414@gmail.com>
- Loading branch information
Showing
13 changed files
with
139 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { useChatContext } from './chat_context'; | ||
export { useCore } from './core_context'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { useSaveChat } from './use_save_chat'; | ||
export { useChatState, ChatStateProvider } from './use_chat_state'; | ||
export { useChatActions } from './use_chat_actions'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { act, fireEvent, render } from '@testing-library/react'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { I18nProvider } from '@osd/i18n/react'; | ||
|
||
import * as useChatStateExports from '../../../hooks'; | ||
import * as contextsExports from '../../../contexts'; | ||
|
||
import { ChatHistoryPage } from '../chat_history_page'; | ||
|
||
const setup = () => { | ||
const useCoreMock = { | ||
services: { | ||
sessions: { | ||
sessions$: new BehaviorSubject({ | ||
objects: [ | ||
{ | ||
id: '1', | ||
title: 'foo', | ||
}, | ||
], | ||
total: 1, | ||
}), | ||
status$: new BehaviorSubject('idle'), | ||
load: jest.fn(), | ||
}, | ||
sessionLoad: {}, | ||
}, | ||
}; | ||
const useChatStateMock = { | ||
chatStateDispatch: jest.fn(), | ||
}; | ||
const useChatContextMock = { | ||
sessionId: '1', | ||
setSessionId: jest.fn(), | ||
setTitle: jest.fn(), | ||
}; | ||
jest.spyOn(contextsExports, 'useCore').mockReturnValue(useCoreMock); | ||
jest.spyOn(useChatStateExports, 'useChatState').mockReturnValue(useChatStateMock); | ||
jest.spyOn(contextsExports, 'useChatContext').mockReturnValue(useChatContextMock); | ||
|
||
const renderResult = render( | ||
<I18nProvider> | ||
<ChatHistoryPage shouldRefresh={false} /> | ||
</I18nProvider> | ||
); | ||
|
||
return { | ||
useCoreMock, | ||
useChatStateMock, | ||
useChatContextMock, | ||
renderResult, | ||
}; | ||
}; | ||
|
||
describe('<ChatHistoryPage />', () => { | ||
it('should clear old session data after current session deleted', async () => { | ||
const { renderResult, useChatStateMock, useChatContextMock } = setup(); | ||
|
||
act(() => { | ||
fireEvent.click(renderResult.getByLabelText('Delete conversation')); | ||
}); | ||
|
||
expect(useChatContextMock.setSessionId).not.toHaveBeenCalled(); | ||
expect(useChatContextMock.setTitle).not.toHaveBeenCalled(); | ||
expect(useChatStateMock.chatStateDispatch).not.toHaveBeenCalled(); | ||
|
||
act(() => { | ||
fireEvent.click(renderResult.getByTestId('confirmModalConfirmButton')); | ||
}); | ||
|
||
expect(useChatContextMock.setSessionId).toHaveBeenLastCalledWith(undefined); | ||
expect(useChatContextMock.setTitle).toHaveBeenLastCalledWith(undefined); | ||
expect(useChatStateMock.chatStateDispatch).toHaveBeenLastCalledWith({ type: 'reset' }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
module.exports = 'file-stub'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
module.exports = {}; |