-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #346 from karthikjeeyar/drawer-action-config
fix(ChatbotConversationHistoryNav): Make order of drawer action buttons configurable
- Loading branch information
Showing
5 changed files
with
150 additions
and
2 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
126 changes: 126 additions & 0 deletions
126
packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.tsx
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,126 @@ | ||
import React from 'react'; | ||
import '@testing-library/jest-dom'; | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'; | ||
|
||
import { ChatbotDisplayMode } from '../Chatbot/Chatbot'; | ||
import ChatbotConversationHistoryNav, { Conversation } from './ChatbotConversationHistoryNav'; | ||
|
||
describe('ChatbotConversationHistoryNav', () => { | ||
const onDrawerToggle = jest.fn(); | ||
|
||
const initialConversations: Conversation[] = [ | ||
{ | ||
id: '1', | ||
text: 'Lightspeed documentation' | ||
} | ||
]; | ||
|
||
it('should open the conversation history navigation drawer', () => { | ||
render( | ||
<ChatbotConversationHistoryNav | ||
onDrawerToggle={onDrawerToggle} | ||
isDrawerOpen={true} | ||
displayMode={ChatbotDisplayMode.fullscreen} | ||
setIsDrawerOpen={jest.fn()} | ||
conversations={initialConversations} | ||
/> | ||
); | ||
expect(screen.queryByText('Lightspeed documentation')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should display the conversations for grouped conversations', () => { | ||
const groupedConversations: { [key: string]: Conversation[] } = { | ||
Today: [...initialConversations, { id: '2', text: 'Chatbot extension' }] | ||
}; | ||
|
||
render( | ||
<ChatbotConversationHistoryNav | ||
onDrawerToggle={onDrawerToggle} | ||
isDrawerOpen={true} | ||
displayMode={ChatbotDisplayMode.fullscreen} | ||
setIsDrawerOpen={jest.fn()} | ||
conversations={groupedConversations} | ||
/> | ||
); | ||
expect(screen.queryByText('Chatbot extension')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should apply the reversed class when reverseButtonOrder is true', () => { | ||
render( | ||
<ChatbotConversationHistoryNav | ||
onDrawerToggle={onDrawerToggle} | ||
isDrawerOpen={true} | ||
displayMode={ChatbotDisplayMode.fullscreen} | ||
setIsDrawerOpen={jest.fn()} | ||
reverseButtonOrder | ||
conversations={initialConversations} | ||
/> | ||
); | ||
|
||
expect(screen.getByTestId('chatbot-nav-drawer-actions')).toHaveClass('pf-v6-c-drawer__actions--reversed'); | ||
}); | ||
|
||
it('should not apply the reversed class when reverseButtonOrder is false', () => { | ||
render( | ||
<ChatbotConversationHistoryNav | ||
onDrawerToggle={onDrawerToggle} | ||
isDrawerOpen={true} | ||
displayMode={ChatbotDisplayMode.fullscreen} | ||
setIsDrawerOpen={jest.fn()} | ||
reverseButtonOrder={false} | ||
conversations={initialConversations} | ||
/> | ||
); | ||
expect(screen.getByTestId('chatbot-nav-drawer-actions')).not.toHaveClass('pf-v6-c-drawer__actions--reversed'); | ||
}); | ||
|
||
it('should invoke handleTextInputChange callback when user searches for conversations', () => { | ||
const handleSearch = jest.fn(); | ||
const groupedConversations: { [key: string]: Conversation[] } = { | ||
Today: [...initialConversations, { id: '2', text: 'Chatbot extension' }] | ||
}; | ||
|
||
render( | ||
<ChatbotConversationHistoryNav | ||
onDrawerToggle={onDrawerToggle} | ||
isDrawerOpen={true} | ||
displayMode={ChatbotDisplayMode.fullscreen} | ||
setIsDrawerOpen={jest.fn()} | ||
reverseButtonOrder={false} | ||
conversations={groupedConversations} | ||
handleTextInputChange={handleSearch} | ||
/> | ||
); | ||
|
||
const searchInput = screen.getByPlaceholderText(/Search/i); | ||
|
||
fireEvent.change(searchInput, { target: { value: 'Chatbot' } }); | ||
|
||
expect(handleSearch).toHaveBeenCalledWith('Chatbot'); | ||
}); | ||
|
||
it('should close the drawer when escape key is pressed', async () => { | ||
render( | ||
<ChatbotConversationHistoryNav | ||
onDrawerToggle={onDrawerToggle} | ||
isDrawerOpen={true} | ||
displayMode={ChatbotDisplayMode.fullscreen} | ||
setIsDrawerOpen={jest.fn()} | ||
reverseButtonOrder={false} | ||
handleTextInputChange={jest.fn()} | ||
conversations={initialConversations} | ||
/> | ||
); | ||
|
||
fireEvent.keyDown(screen.getByPlaceholderText(/Search/i), { | ||
key: 'Escape', | ||
code: 'Escape', | ||
keyCode: 27, | ||
charCode: 27 | ||
}); | ||
|
||
waitFor(() => { | ||
expect(screen.queryByText('Lightspeed documentation')).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
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