generated from openedx/frontend-template-application
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Added coverage to useMessageHistory() hook
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
|
||
import { useSelector } from 'react-redux'; | ||
import { useMessageHistory } from './message-history'; | ||
import { getLearningAssistantMessageHistory } from '../data/thunks'; | ||
|
||
const mockDispatch = jest.fn(); | ||
jest.mock('react-redux', () => ({ | ||
...jest.requireActual('react-redux'), | ||
useSelector: jest.fn(), | ||
useDispatch: () => mockDispatch, | ||
})); | ||
|
||
jest.mock('../data/thunks'); | ||
|
||
describe('Learning Assistant Message History Hooks', () => { | ||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('useMessageHistory()', () => { | ||
let hook; | ||
const fakeCourseId = 'course-v1:edx+test+23'; | ||
|
||
const renderTestHook = (courseId, isEnabled) => { | ||
const mockedStoreState = { learningAssistant: { isEnabled } }; | ||
useSelector.mockImplementation(selector => selector(mockedStoreState)); | ||
hook = renderHook(() => useMessageHistory(courseId)); | ||
return hook; | ||
}; | ||
|
||
it('should dispatch getLearningAssistantMessageHistory() with the chat history', () => { | ||
renderTestHook(fakeCourseId, true); | ||
|
||
expect(mockDispatch).toHaveBeenCalledTimes(1); | ||
expect(getLearningAssistantMessageHistory).toHaveBeenCalledWith(fakeCourseId); | ||
}); | ||
|
||
it('should NOT dispatch getLearningAssistantMessageHistory() when disabled', () => { | ||
renderTestHook(fakeCourseId, false); | ||
|
||
expect(mockDispatch).not.toHaveBeenCalled(); | ||
expect(getLearningAssistantMessageHistory).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should NOT dispatch getLearningAssistantMessageHistory() with no courseId', () => { | ||
renderTestHook(null, true); | ||
|
||
expect(mockDispatch).not.toHaveBeenCalled(); | ||
expect(getLearningAssistantMessageHistory).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |