feat: make the app reload submission on modal close (#50)

* feat: make the app reload submission on modal close

* chore: remove reloadSubmission request and reuse initial app
This commit is contained in:
leangseu-edx
2022-01-25 14:00:51 -05:00
committed by GitHub
parent 46ebc899ee
commit 81026ae013
6 changed files with 53 additions and 11 deletions

View File

@@ -4,7 +4,7 @@ import { connect } from 'react-redux';
import { FullscreenModal } from '@edx/paragon';
import { selectors, actions } from 'data/redux';
import { selectors, actions, thunkActions } from 'data/redux';
import { RequestKeys } from 'data/constants/requests';
import LoadingMessage from 'components/LoadingMessage';
@@ -25,6 +25,7 @@ export class ReviewModal extends React.Component {
onClose() {
this.props.setShowReview(false);
this.props.reloadSubmissions();
}
get isLoading() {
@@ -60,6 +61,7 @@ ReviewModal.propTypes = {
text: PropTypes.node,
}),
setShowReview: PropTypes.func.isRequired,
reloadSubmissions: PropTypes.func.isRequired,
isLoaded: PropTypes.bool.isRequired,
errorStatus: PropTypes.number,
};
@@ -74,6 +76,7 @@ export const mapStateToProps = (state) => ({
export const mapDispatchToProps = {
setShowReview: actions.app.setShowReview,
reloadSubmissions: thunkActions.app.reloadSubmissions,
};
export default connect(mapStateToProps, mapDispatchToProps)(ReviewModal);

View File

@@ -1,7 +1,7 @@
import React from 'react';
import { shallow } from 'enzyme';
import { selectors, actions } from 'data/redux';
import { selectors, actions, thunkActions } from 'data/redux';
import { RequestKeys } from 'data/constants/requests';
import {
@@ -10,7 +10,6 @@ import {
mapDispatchToProps,
} from '.';
let el;
jest.useFakeTimers('modern');
jest.mock('data/redux', () => ({
@@ -32,6 +31,11 @@ jest.mock('data/redux', () => ({
setShowReview: jest.fn(),
},
},
thunkActions: {
app: {
reloadSubmissions: jest.fn(),
},
},
}));
jest.mock('containers/ReviewActions', () => 'ReviewActions');
@@ -41,6 +45,7 @@ jest.mock('components/LoadingMessage', () => 'LoadingMessage');
const requestKey = RequestKeys.fetchSubmission;
describe('ReviewModal component', () => {
let el;
const props = {
oraName: 'test-ora-name',
isOpen: false,
@@ -48,10 +53,11 @@ describe('ReviewModal component', () => {
showRubric: false,
isLoaded: false,
};
beforeEach(() => {
props.setShowReview = jest.fn();
props.reloadSubmissions = jest.fn();
});
describe('component', () => {
beforeEach(() => {
props.setShowReview = jest.fn();
});
describe('snapshots', () => {
let render;
beforeEach(() => {
@@ -75,6 +81,18 @@ describe('ReviewModal component', () => {
expect(render()).toMatchSnapshot();
});
});
describe('component', () => {
beforeEach(() => {
el = shallow(<ReviewModal {...props} />);
});
test('setShowReview and reloadSubmissions get call on modal close', () => {
el.instance().onClose();
const { setShowReview, reloadSubmissions } = props;
expect(setShowReview).toHaveBeenCalledTimes(1);
expect(reloadSubmissions).toHaveBeenCalledTimes(1);
});
});
});
describe('mapStateToProps', () => {
let mapped;
@@ -99,8 +117,12 @@ describe('ReviewModal component', () => {
});
});
describe('mapDispatchToProps', () => {
it('loads setShowReview from thunkActions.app.setShowReview', () => {
it('loads setShowReview from actions.app.setShowReview', () => {
expect(mapDispatchToProps.setShowReview).toEqual(actions.app.setShowReview);
});
it('loads reloadSubmissions from thunkActions.app.reloadSubmissions', () => {
expect(mapDispatchToProps.reloadSubmissions).toEqual(thunkActions.app.reloadSubmissions);
});
});
});

View File

@@ -9,6 +9,7 @@ export const RequestStates = StrictDict({
export const RequestKeys = StrictDict({
initialize: 'initialize',
reloadSubmissions: 'reloadSubmissions',
fetchSubmission: 'fetchSubmission',
fetchSubmissionStatus: 'fetchSubmissionStatus',
setLock: 'setLock',

View File

@@ -19,4 +19,18 @@ export const initialize = () => (dispatch) => {
}));
};
export default StrictDict({ initialize });
/**
* initialize the app, loading ora and course metadata from the api, and loading the initial
* submission list data.
*/
export const reloadSubmissions = () => (dispatch) => {
dispatch(initializeApp({
locationId,
reload: true,
onSuccess: (response) => {
dispatch(actions.submissions.loadList(response.submissions));
},
}));
};
export default StrictDict({ initialize, reloadSubmissions });

View File

@@ -35,14 +35,15 @@ export const networkRequest = ({
/**
* Tracked initializeApp api method.
* Tracked to the `initialize` request key.
* Tracked to the `initialize` or `reloadSubmissions` request key.
* @param {string} locationId - ora location id
* @param {bool} reload - is reloading submission
* @param {[func]} onSuccess - onSuccess method ((response) => { ... })
* @param {[func]} onFailure - onFailure method ((error) => { ... })
*/
export const initializeApp = ({ locationId, ...rest }) => (dispatch) => {
export const initializeApp = ({ locationId, reload, ...rest }) => (dispatch) => {
dispatch(module.networkRequest({
requestKey: RequestKeys.initialize,
requestKey: reload ? RequestKeys.reloadSubmissions : RequestKeys.initialize,
promise: api.initializeApp(locationId),
...rest,
}));

View File

@@ -36,6 +36,7 @@ const initializeApp = () => get(
[paramKeys.oraLocation]: locationId,
}),
).then(response => response.data);
/**
* get('/api/submission', { submissionUUID })
* @return {