diff --git a/src/containers/ListView/SubmissionsTable.test.jsx b/src/containers/ListView/SubmissionsTable.test.jsx index 880f72cf..2704cad0 100644 --- a/src/containers/ListView/SubmissionsTable.test.jsx +++ b/src/containers/ListView/SubmissionsTable.test.jsx @@ -211,7 +211,7 @@ describe('SubmissionsTable component', () => { expect(columns[3]).toEqual({ Header: messages.learnerSubmissionDate.defaultMessage, accessor: submissionFields.dateSubmitted, - Cell: el.instance.children[0].props.columns[1].Cell, + Cell: el.instance.children[0].props.columns[3].Cell, disableFilters: true, }); }); @@ -219,7 +219,7 @@ describe('SubmissionsTable component', () => { expect(columns[4]).toEqual({ Header: messages.grade.defaultMessage, accessor: submissionFields.score, - Cell: el.instance.children[0].props.columns[2].Cell, + Cell: el.instance.children[0].props.columns[4].Cell, disableFilters: true, }); }); @@ -227,10 +227,10 @@ describe('SubmissionsTable component', () => { expect(columns[5]).toEqual({ Header: messages.gradingStatus.defaultMessage, accessor: submissionFields.gradingStatus, - Cell: el.instance.children[0].props.columns[3].Cell, + Cell: el.instance.children[0].props.columns[5].Cell, Filter: MultiSelectDropdownFilter, filter: 'includesValue', - filterChoices: el.instance.children[0].props.columns[3].filterChoices, + filterChoices: el.instance.children[0].props.columns[5].filterChoices, }); }); }); @@ -251,7 +251,7 @@ describe('SubmissionsTable component', () => { expect(columns[3]).toEqual({ Header: messages.teamSubmissionDate.defaultMessage, accessor: submissionFields.dateSubmitted, - Cell: el.instance.children[0].props.columns[1].Cell, + Cell: el.instance.children[0].props.columns[3].Cell, disableFilters: true, }); }); @@ -259,7 +259,7 @@ describe('SubmissionsTable component', () => { expect(columns[4]).toEqual({ Header: messages.grade.defaultMessage, accessor: submissionFields.score, - Cell: el.instance.children[0].props.columns[2].Cell, + Cell: el.instance.children[0].props.columns[4].Cell, disableFilters: true, }); }); @@ -267,10 +267,10 @@ describe('SubmissionsTable component', () => { expect(columns[5]).toEqual({ Header: messages.gradingStatus.defaultMessage, accessor: submissionFields.gradingStatus, - Cell: el.instance.children[0].props.columns[3].Cell, + Cell: el.instance.children[0].props.columns[5].Cell, Filter: MultiSelectDropdownFilter, filter: 'includesValue', - filterChoices: el.instance.children[0].props.columns[3].filterChoices, + filterChoices: el.instance.children[0].props.columns[5].filterChoices, }); }); }); @@ -397,24 +397,24 @@ describe('SubmissionsTable component', () => { const fakeDate = 16131215154955; const fakeDateString = 'test-date-string'; const mock = jest.spyOn(Date.prototype, 'toLocaleString').mockReturnValue(fakeDateString); - expect(el.instance.children[0].props.columns[1].Cell({ value: fakeDate })).toEqual(fakeDateString); + expect(el.instance.children[0].props.columns[3].Cell({ value: fakeDate })).toEqual(fakeDateString); mock.mockRestore(); }); }); describe('formatGrade method', () => { it('returns "-" if grade is null', () => { - expect(el.instance.children[0].props.columns[2].Cell({ value: null })).toEqual('-'); + expect(el.instance.children[0].props.columns[4].Cell({ value: null })).toEqual('-'); }); it('returns / if grade exists', () => { expect( - el.instance.children[0].props.columns[2].Cell({ value: { pointsEarned: 1, pointsPossible: 10 } }), + el.instance.children[0].props.columns[4].Cell({ value: { pointsEarned: 1, pointsPossible: 10 } }), ).toEqual('1/10'); }); }); describe('formatStatus method', () => { it('returns a StatusBadge with the given status', () => { const status = 'graded'; - expect(el.instance.children[0].props.columns[3].Cell({ value: 'graded' })).toEqual( + expect(el.instance.children[0].props.columns[5].Cell({ value: 'graded' })).toEqual( , ); }); diff --git a/src/containers/ReviewProblemStepsModal/components/ReviewProblemStepsContent/components/AssessmentsTable/index.test.jsx b/src/containers/ReviewProblemStepsModal/components/ReviewProblemStepsContent/components/AssessmentsTable/index.test.jsx index 7554a371..e068137c 100644 --- a/src/containers/ReviewProblemStepsModal/components/ReviewProblemStepsContent/components/AssessmentsTable/index.test.jsx +++ b/src/containers/ReviewProblemStepsModal/components/ReviewProblemStepsContent/components/AssessmentsTable/index.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow } from '@edx/react-unit-test-utils'; import { formatMessage } from 'testUtils'; import { DataTable, diff --git a/src/containers/ReviewProblemStepsModal/components/ReviewProblemStepsContent/hooks.test.js b/src/containers/ReviewProblemStepsModal/components/ReviewProblemStepsContent/hooks.test.js index 6d67f577..633ddb21 100644 --- a/src/containers/ReviewProblemStepsModal/components/ReviewProblemStepsContent/hooks.test.js +++ b/src/containers/ReviewProblemStepsModal/components/ReviewProblemStepsContent/hooks.test.js @@ -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@example.com', scorerName: 'John Doe', scorerUsername: 'johndoe123', feedback: 'Great work!', problemStep: 'Step 1', - assesmentScores: [ + assessmentScores: [ { criterionName: 'Criterion 1', scoreEarned: 8, @@ -61,26 +62,52 @@ 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')); @@ -88,7 +115,7 @@ describe('ReviewProblemStepsContent hooks', () => { 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,15 +125,15 @@ 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')); @@ -114,7 +141,7 @@ describe('ReviewProblemStepsContent hooks', () => { 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(); }); diff --git a/src/containers/ReviewProblemStepsModal/components/ReviewProblemStepsContent/utils.test.js b/src/containers/ReviewProblemStepsModal/components/ReviewProblemStepsContent/utils.test.js index e83cd2ce..1ef924ef 100644 --- a/src/containers/ReviewProblemStepsModal/components/ReviewProblemStepsContent/utils.test.js +++ b/src/containers/ReviewProblemStepsModal/components/ReviewProblemStepsContent/utils.test.js @@ -5,13 +5,13 @@ describe('assessmentTableFormat', () => { const inputAssessmentData = [ { assessmentId: 1, - assesmentDate: '2023-11-17', + assessmentDate: '2023-11-17', scorerEmail: 'scorer@example.com', 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' }, ], diff --git a/src/data/services/lms/api.test.js b/src/data/services/lms/api.test.js index 141375e5..52b231e9 100644 --- a/src/data/services/lms/api.test.js +++ b/src/data/services/lms/api.test.js @@ -19,7 +19,6 @@ jest.mock('data/constants/app', () => ({ const gradeData = 'test-grade-data'; const submissionUUID = 'test-submission-uuid'; const submissionUUIDs = ['some', 'submission', 'uuid']; -const assessmentType = 'received'; const methodKeys = StrictDict({ get: 'get', @@ -152,12 +151,26 @@ describe('lms service api methods', () => { }); }); - describe('getFeedbackList', () => { + describe('getFeedbackFromList', () => { testAPI({ - promise: api.getFeedbackList(submissionUUID, assessmentType), + promise: api.getFeedbackFromList(submissionUUID), method: methodKeys.get, expected: { - urlKey: urlKeys.getFeedbackSubmissionsUrl, + urlKey: urlKeys.assessmentsFeedbackFromUrl, + urlParams: { + [paramKeys.oraLocation]: locationId(), + [paramKeys.submissionUUID]: submissionUUID, + }, + }, + }); + }); + + describe('getFeedbackToList', () => { + testAPI({ + promise: api.getFeedbackToList(submissionUUID), + method: methodKeys.get, + expected: { + urlKey: urlKeys.assessmentsFeedbackToUrl, urlParams: { [paramKeys.oraLocation]: locationId(), [paramKeys.submissionUUID]: submissionUUID,