Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: request error for empty user list responses #290

Open
wants to merge 1 commit into
base: open-release/quince.master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/containers/ListView/TableAction.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const TableAction = ({ tableInstance, handleClick }) => (
onClick={handleClick(tableInstance.rows)}
variant="primary"
className="view-all-responses-btn"
disabled={tableInstance.rows.length === 0}
>
<FormattedMessage {...messages.viewAllResponses} />
</Button>
Expand Down
9 changes: 9 additions & 0 deletions src/containers/ListView/TableAction.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ describe('TableAction component', () => {
expect(el).toMatchSnapshot();
});

test('Inactive Button "View All Responses"', () => {
const emptyProps = {
tableInstance: { rows: [] },
handleClick: jest.fn(),
};
const el = shallow(<TableAction {...emptyProps} />);
expect(el.snapshot).toMatchSnapshot();
});

test('handleClick', () => {
shallow(<TableAction {...props} />);
expect(props.handleClick).toHaveBeenCalledWith(props.tableInstance.rows);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TableAction component Inactive Button "View All Responses" 1`] = `undefined`;

exports[`TableAction component snapshots 1`] = `
<Button
className="view-all-responses-btn"
disabled={false}
onClick={[MockFunction]}
variant="primary"
>
Expand Down
8 changes: 5 additions & 3 deletions src/data/redux/thunkActions/grading.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ export const loadPrev = () => (dispatch) => {
* @param {string[]} submissionUUIDs - ordered list of submissionUUIDs for selected submissions
*/
export const loadSelectionForReview = (submissionUUIDs) => (dispatch) => {
dispatch(actions.grading.updateSelection(submissionUUIDs));
dispatch(actions.app.setShowReview(true));
dispatch(module.loadSubmission());
if (submissionUUIDs?.length > 0) {
dispatch(actions.grading.updateSelection(submissionUUIDs));
dispatch(actions.app.setShowReview(true));
dispatch(module.loadSubmission());
}
};

export const loadSubmission = () => (dispatch, getState) => {
Expand Down
17 changes: 11 additions & 6 deletions src/data/redux/thunkActions/grading.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,25 @@ describe('grading thunkActions', () => {
});
});
describe('loadSelectionForReview', () => {
const submissionUUIDs = [
'submission-id-0',
'submission-id-1',
'submission-id-2',
'submission-id-3',
];
test('dispatches actions.grading.updateSelection, actions.app.setShowReview(true), and then loadSubmission', () => {
const submissionUUIDs = [
'submission-id-0',
'submission-id-1',
'submission-id-2',
'submission-id-3',
];
thunkActions.loadSelectionForReview(submissionUUIDs)(dispatch, getState);
expect(dispatch.mock.calls).toEqual([
[actions.grading.updateSelection(submissionUUIDs)],
[actions.app.setShowReview(true)],
[thunkActions.loadSubmission()],
]);
});
test('with empty submissionUUIDs does not dispatch any action', () => {
const submissionUUIDs = [];
thunkActions.loadSelectionForReview(submissionUUIDs)(dispatch, getState);
expect(dispatch).not.toHaveBeenCalled();
});
});
});

Expand Down
Loading