feat: split cancel and stop grading actions
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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)],
|
||||
|
||||
Reference in New Issue
Block a user