-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: keep in history list after history deleted #26
Closed
wanglam
wants to merge
4
commits into
opensearch-project:feature/langchain
from
wanglam:fix-redirect-new-session-in-dock-right-langchain
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
334fc8d
fix: change to new session after history deleted
wanglam e9dd420
test: add miss file and style mock
wanglam 767e812
feat: add unit test for clear deleted old chat session data
wanglam c568343
refactor: change handleEditConversationConfirmModalClose to handleEdi…
wanglam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { act, fireEvent, render, waitFor } from '@testing-library/react'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { I18nProvider } from '@osd/i18n/react'; | ||
|
||
import * as useChatStateExports from '../../../hooks/use_chat_state'; | ||
import * as chatContextExports from '../../../contexts/chat_context'; | ||
import * as coreContextExports from '../../../contexts/core_context'; | ||
|
||
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(coreContextExports, 'useCore').mockReturnValue(useCoreMock); | ||
jest.spyOn(useChatStateExports, 'useChatState').mockReturnValue(useChatStateMock); | ||
jest.spyOn(chatContextExports, '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
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 = {}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: we should barrel this stuff in like
and then export those files in there so that we can just import with a single line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that means we create a
public/tabs/history/index.ts
file and exports all references in it like thesethen we can import them in single line like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah and i think if you need to import you can be like
depending on where you are importing it. I would export * like how you are doing and then be specific.
Our build system is like a custom implementation of babel and webpack so importing everything with
*
could potentially not support tree-shaking. So just in general probably better to import what you need to ensure a smaller bundle size.