-
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.
test: add unit test for chat history page (#55)
* test: add unit test for chst history page Signed-off-by: Lin Wang <wonglam@amazon.com> * test: add unit tests for chat history list Signed-off-by: Lin Wang <wonglam@amazon.com> * test: add unit tests for chat history search list Signed-off-by: Lin Wang <wonglam@amazon.com> * test: remove unnecessary act Signed-off-by: Lin Wang <wonglam@amazon.com> --------- Signed-off-by: Lin Wang <wonglam@amazon.com>
- Loading branch information
Showing
7 changed files
with
315 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { fireEvent, render } from '@testing-library/react'; | ||
|
||
import { ChatHistoryList } from '../chat_history_list'; | ||
|
||
describe('<ChatHistoryList />', () => { | ||
it('should render two history titles, update times and one horizontal rule', async () => { | ||
const { getByText, getAllByLabelText } = render( | ||
<ChatHistoryList | ||
chatHistories={[ | ||
{ id: '1', title: 'foo', updatedTimeMs: 0 }, | ||
{ id: '2', title: 'bar', updatedTimeMs: 360000 }, | ||
]} | ||
/> | ||
); | ||
|
||
expect(getByText('foo')).toBeInTheDocument(); | ||
expect(getByText('bar')).toBeInTheDocument(); | ||
expect(getByText('January 1, 1970 at 12:0 AM')).toBeInTheDocument(); | ||
expect(getByText('January 1, 1970 at 12:6 AM')).toBeInTheDocument(); | ||
expect(getAllByLabelText('history horizontal rule')).toHaveLength(1); | ||
}); | ||
|
||
it('should call onChatHistoryTitleClick with id and title', () => { | ||
const onChatHistoryTitleClickMock = jest.fn(); | ||
const { getByText } = render( | ||
<ChatHistoryList | ||
chatHistories={[{ id: '1', title: 'foo', updatedTimeMs: 0 }]} | ||
onChatHistoryTitleClick={onChatHistoryTitleClickMock} | ||
/> | ||
); | ||
|
||
expect(onChatHistoryTitleClickMock).not.toHaveBeenCalled(); | ||
fireEvent.click(getByText('foo')); | ||
expect(onChatHistoryTitleClickMock).toHaveBeenCalledWith('1', 'foo'); | ||
}); | ||
|
||
it('should call onChatHistoryEditClick with id and title', () => { | ||
const onChatHistoryEditClickMock = jest.fn(); | ||
const { getByLabelText } = render( | ||
<ChatHistoryList | ||
chatHistories={[{ id: '1', title: 'foo', updatedTimeMs: 0 }]} | ||
onChatHistoryEditClick={onChatHistoryEditClickMock} | ||
/> | ||
); | ||
|
||
expect(onChatHistoryEditClickMock).not.toHaveBeenCalled(); | ||
fireEvent.click(getByLabelText('Edit conversation name')); | ||
expect(onChatHistoryEditClickMock).toHaveBeenCalledWith({ id: '1', title: 'foo' }); | ||
}); | ||
|
||
it('should call onChatHistoryDeleteClick with id and title', () => { | ||
const onChatHistoryDeleteClickMock = jest.fn(); | ||
const { getByLabelText } = render( | ||
<ChatHistoryList | ||
chatHistories={[{ id: '1', title: 'foo', updatedTimeMs: 0 }]} | ||
onChatHistoryDeleteClick={onChatHistoryDeleteClickMock} | ||
/> | ||
); | ||
|
||
expect(onChatHistoryDeleteClickMock).not.toHaveBeenCalled(); | ||
fireEvent.click(getByLabelText('Delete conversation')); | ||
expect(onChatHistoryDeleteClickMock).toHaveBeenCalledWith({ id: '1' }); | ||
}); | ||
}); |
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
Oops, something went wrong.