Skip to content

Commit

Permalink
fix: request error for empty user list responses
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroAlipov authored and arbrandes committed Apr 3, 2024
1 parent 59a7d07 commit 9cfab58
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
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.snapshot).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
15 changes: 15 additions & 0 deletions src/containers/ListView/__snapshots__/TableAction.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TableAction component Inactive Button "View All Responses" 1`] = `
<Button
className="view-all-responses-btn"
disabled={true}
variant="primary"
>
<FormattedMessage
defaultMessage="View all responses"
description="Button text to load all responses for review/grading"
id="ora-grading.ListView.viewAllResponses"
/>
</Button>
`;

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 && 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

0 comments on commit 9cfab58

Please sign in to comment.