feat: split cancel and stop grading actions

This commit is contained in:
Ben Warzeski
2021-10-26 12:26:19 -04:00
parent eccc4e36a3
commit 39047272ca
2 changed files with 46 additions and 2 deletions

View File

@@ -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,
});

View File

@@ -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)],