From 39047272cabf313c2747f210977d21e28378f77c Mon Sep 17 00:00:00 2001 From: Ben Warzeski Date: Tue, 26 Oct 2021 12:26:19 -0400 Subject: [PATCH] feat: split cancel and stop grading actions --- src/data/thunkActions/grading.js | 17 ++++++++++++++- src/data/thunkActions/grading.test.js | 31 ++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/data/thunkActions/grading.js b/src/data/thunkActions/grading.js index 3fdd326..aa21244 100644 --- a/src/data/thunkActions/grading.js +++ b/src/data/thunkActions/grading.js @@ -140,7 +140,21 @@ export const startGrading = () => (dispatch, getState) => { }; /** - * Stops the grading process for the current submisison + * Cancels the grading process for the current submisison. + * Releases the lock and dispatches stopGrading on success. + */ +export const cancelGrading = () => (dispatch, getState) => { + dispatch(requests.setLock({ + value: false, + submissionId: selectors.grading.selected.submissionId(getState()), + onSuccess: () => { + dispatch(module.stopGrading()); + }, + })); +}; + +/** + * Stops the grading process for the current submission (local only) * Clears the local grade data for the current submission and sets grading state * to False */ @@ -154,5 +168,6 @@ export default StrictDict({ loadNext, loadPrev, startGrading, + cancelGrading, stopGrading, }); diff --git a/src/data/thunkActions/grading.test.js b/src/data/thunkActions/grading.test.js index 6cfccc3..1fa8355 100644 --- a/src/data/thunkActions/grading.test.js +++ b/src/data/thunkActions/grading.test.js @@ -313,9 +313,38 @@ describe('grading thunkActions', () => { }); }); + describe('cancelGrading', () => { + let stopGrading; + beforeAll(() => { + stopGrading = thunkActions.stopGrading; + thunkActions.stopGrading = () => 'stop grading'; + }); + beforeEach(() => { + getDispatched(thunkActions.cancelGrading()); + actionArgs = dispatched.setLock; + }); + afterAll(() => { + thunkActions.stopGrading = stopGrading; + }); + test('dispatches setLock with selected submissionId and value: false', () => { + expect(actionArgs).not.toEqual(undefined); + expect(actionArgs.value).toEqual(false); + expect(actionArgs.submissionId).toEqual(selectors.grading.selected.submissionId(testState)); + }); + describe('onSuccess', () => { + beforeEach(() => { + dispatch.mockClear(); + }); + test('dispatches stopGrading thunkAction', () => { + actionArgs.onSuccess(); + expect(dispatch.mock.calls).toContainEqual([thunkActions.stopGrading()]); + }); + }); + }); + describe('stopGrading', () => { it('dispatches grading.clearGrade and app.setGrading(false)', () => { - thunkActions.stopGrading()(dispatch); + thunkActions.stopGrading()(dispatch, getState); expect(dispatch.mock.calls).toEqual([ [actions.grading.clearGrade()], [actions.app.setGrading(false)],