forked from openedx/frontend-app-ora-grading
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
75 additions
and
34 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
2 changes: 1 addition & 1 deletion
2
...tepsModal/components/ReviewProblemStepsContent/components/AssessmentsTable/index.test.jsx
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 |
---|---|---|
|
@@ -3,7 +3,8 @@ import api from 'data/services/lms/api'; | |
import { useFeedbackList } from './hooks'; | ||
|
||
jest.mock('data/services/lms/api', () => ({ | ||
getFeedbackList: jest.fn(), | ||
getFeedbackFromList: jest.fn(), | ||
getFeedbackToList: jest.fn(), | ||
})); | ||
|
||
describe('ReviewProblemStepsContent hooks', () => { | ||
|
@@ -14,13 +15,13 @@ describe('ReviewProblemStepsContent hooks', () => { | |
const mockAssessments = [ | ||
{ | ||
assessmentId: 1, | ||
assesmentDate: '2024-01-01', | ||
assessmentDate: '2024-01-01', | ||
scorerEmail: '[email protected]', | ||
scorerName: 'John Doe', | ||
scorerUsername: 'johndoe123', | ||
feedback: 'Great work!', | ||
problemStep: 'Step 1', | ||
assesmentScores: [ | ||
assessmentScores: [ | ||
{ | ||
criterionName: 'Criterion 1', | ||
scoreEarned: 8, | ||
|
@@ -61,34 +62,60 @@ describe('ReviewProblemStepsContent hooks', () => { | |
|
||
test('should change feedbackListType', async () => { | ||
const mockResponse = { assessments: mockAssessments }; | ||
api.getFeedbackList.mockResolvedValue(mockResponse); | ||
api.getFeedbackFromList.mockResolvedValue(mockResponse); | ||
|
||
const { result, waitForNextUpdate } = renderHook(() => useFeedbackList('some-uuid')); | ||
|
||
act(() => result.current.setFeedbackListType('received')); | ||
|
||
await act(async () => { | ||
result.current.getFeedbackListApi(); | ||
await waitForNextUpdate(); | ||
}); | ||
|
||
expect(api.getFeedbackFromList).toHaveBeenCalledWith('some-uuid'); | ||
expect(result.current.isLoadingFeedbackList).toBe(false); | ||
expect(result.current.feedbackList).toEqual(expectedFormattedAssessments); | ||
expect(result.current.feedbackListError).toBeNull(); | ||
}); | ||
|
||
test('successful API call getFeedbackFromList', async () => { | ||
const mockResponse = { assessments: mockAssessments }; | ||
api.getFeedbackFromList.mockResolvedValue(mockResponse); | ||
|
||
const { result, waitForNextUpdate } = renderHook(() => useFeedbackList('some-uuid')); | ||
|
||
act(() => result.current.setFeedbackListType('given')); | ||
act(() => { | ||
result.current.getFeedbackListApi(); | ||
}); | ||
|
||
expect(api.getFeedbackFromList).toHaveBeenCalledWith('some-uuid'); | ||
expect(result.current.isLoadingFeedbackList).toBe(true); | ||
expect(result.current.feedbackList).toEqual([]); | ||
expect(result.current.feedbackListError).toBeNull(); | ||
|
||
await act(async () => { | ||
result.current.getFeedbackListApi(); | ||
await waitForNextUpdate(); | ||
}); | ||
|
||
expect(api.getFeedbackList).toHaveBeenCalledWith('some-uuid', 'given'); | ||
expect(api.getFeedbackFromList).toHaveBeenCalledWith('some-uuid'); | ||
expect(result.current.isLoadingFeedbackList).toBe(false); | ||
expect(result.current.feedbackList).toEqual(expectedFormattedAssessments); | ||
expect(result.current.feedbackListError).toBeNull(); | ||
}); | ||
|
||
test('successful API call', async () => { | ||
test('successful API call getFeedbackToList', async () => { | ||
const mockResponse = { assessments: mockAssessments }; | ||
api.getFeedbackList.mockResolvedValue(mockResponse); | ||
api.getFeedbackToList.mockResolvedValue(mockResponse); | ||
|
||
const { result, waitForNextUpdate } = renderHook(() => useFeedbackList('some-uuid')); | ||
|
||
act(() => { | ||
result.current.getFeedbackListApi(); | ||
}); | ||
|
||
expect(api.getFeedbackList).toHaveBeenCalledWith('some-uuid', 'received'); | ||
expect(api.getFeedbackToList).toHaveBeenCalledWith('some-uuid'); | ||
expect(result.current.isLoadingFeedbackList).toBe(true); | ||
expect(result.current.feedbackList).toEqual([]); | ||
expect(result.current.feedbackListError).toBeNull(); | ||
|
@@ -98,23 +125,23 @@ describe('ReviewProblemStepsContent hooks', () => { | |
await waitForNextUpdate(); | ||
}); | ||
|
||
expect(api.getFeedbackList).toHaveBeenCalledWith('some-uuid', 'received'); | ||
expect(api.getFeedbackToList).toHaveBeenCalledWith('some-uuid'); | ||
expect(result.current.isLoadingFeedbackList).toBe(false); | ||
expect(result.current.feedbackList).toEqual(expectedFormattedAssessments); | ||
expect(result.current.feedbackListError).toBeNull(); | ||
}); | ||
|
||
test('fail API call', async () => { | ||
test('fail API call getFeedbackFromList', async () => { | ||
const mockError = new Error('Error fetching data'); | ||
api.getFeedbackList.mockRejectedValue(mockError); | ||
api.getFeedbackFromList.mockRejectedValue(mockError); | ||
|
||
const { result, waitForNextUpdate } = renderHook(() => useFeedbackList('some-uuid')); | ||
|
||
act(() => { | ||
result.current.getFeedbackListApi(); | ||
}); | ||
|
||
expect(api.getFeedbackList).toHaveBeenCalledWith('some-uuid', 'received'); | ||
expect(api.getFeedbackFromList).toHaveBeenCalledWith('some-uuid'); | ||
expect(result.current.isLoadingFeedbackList).toBe(true); | ||
expect(result.current.feedbackListError).toBeNull(); | ||
|
||
|
@@ -123,7 +150,7 @@ describe('ReviewProblemStepsContent hooks', () => { | |
await waitForNextUpdate(); | ||
}); | ||
|
||
expect(api.getFeedbackList).toHaveBeenCalledWith('some-uuid', 'received'); | ||
expect(api.getFeedbackFromList).toHaveBeenCalledWith('some-uuid'); | ||
expect(result.current.isLoadingFeedbackList).toBe(false); | ||
expect(result.current.feedbackListError).toBe('Error fetching data'); | ||
}); | ||
|
@@ -139,7 +166,8 @@ describe('ReviewProblemStepsContent hooks', () => { | |
expect(result.current.isLoadingFeedbackList).toBe(false); | ||
}, { timeout: 500 }); | ||
|
||
expect(api.getFeedbackList).not.toHaveBeenCalled(); | ||
expect(api.getFeedbackFromList).not.toHaveBeenCalled(); | ||
expect(api.getFeedbackToList).not.toHaveBeenCalled(); | ||
expect(result.current.feedbackList).toEqual([]); | ||
expect(result.current.feedbackListError).toBeNull(); | ||
}); | ||
|
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 |
---|---|---|
|
@@ -5,13 +5,13 @@ describe('assessmentTableFormat', () => { | |
const inputAssessmentData = [ | ||
{ | ||
assessmentId: 1, | ||
assesmentDate: '2023-11-17', | ||
assessmentDate: '2023-11-17', | ||
scorerEmail: '[email protected]', | ||
scorerName: 'Scorer 1', | ||
scorerUsername: 'scorer1', | ||
feedback: 'Good work!', | ||
problemStep: 'Problem Step 1', | ||
assesmentScores: [ | ||
assessmentScores: [ | ||
{ criterionName: 'Criterion 1', scoreEarned: 8, scoreType: 'High' }, | ||
{ criterionName: 'Criterion 2', scoreEarned: 6, scoreType: 'Medium' }, | ||
], | ||
|
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