Skip to content

Commit

Permalink
fix: max adjusted grades warning and error
Browse files Browse the repository at this point in the history
fix: message error if the input is greater than adjusted grade

fix: change fragment for span

update: testing suites and snapshots updated

testing modified to push

edited file to pass test
  • Loading branch information
lkatsikaris committed Aug 20, 2024
1 parent 997d205 commit 35028b5
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 8 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
"@edx/frontend-platform": "^7.1.0",
"@edx/openedx-atlas": "^0.6.0",
"@edx/react-unit-test-utils": "^2.0.0",
"@openedx/frontend-plugin-framework": "^1.1.2",
"@openedx/frontend-slot-footer": "^1.0.2",
"@openedx/paragon": "^22.1.1",
"@edx/reactifex": "^2.1.1",
"@fortawesome/fontawesome-svg-core": "^1.2.25",
"@fortawesome/free-brands-svg-icons": "^5.11.2",
"@fortawesome/free-solid-svg-icons": "^5.11.2",
"@fortawesome/react-fontawesome": "^0.1.5",
"@openedx/frontend-plugin-framework": "^1.1.2",
"@openedx/frontend-slot-footer": "^1.0.2",
"@openedx/paragon": "^22.1.1",
"@redux-beacon/segment": "^1.0.0",
"@reduxjs/toolkit": "^1.5.1",
"classnames": "^2.2.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ exports[`AdjustedGradeInput component render snapshot 1`] = `
<Form.Control
name="adjustedGradeValue"
onChange={[MockFunction hook.onChange]}
type="text"
size="sm"
type="number"
value="test-value"
/>
some-hint-text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const useAdjustedGradeInputData = () => {
value,
onChange,
hintText,
possibleGrade,
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';

import { Form } from '@openedx/paragon';
import { useIntl } from '@edx/frontend-platform/i18n';
import messages from '../messages';

import useAdjustedGradeInputData from './hooks';

Expand All @@ -13,17 +15,22 @@ export const AdjustedGradeInput = () => {
const {
value,
onChange,
possibleGrade,
hintText,
} = useAdjustedGradeInputData();

const { formatMessage } = useIntl();

return (
<span>
<Form.Control
type="text"
type="number"
name="adjustedGradeValue"
value={value}
onChange={onChange}
size="sm"
/>
{hintText}
{value > possibleGrade ? <div style={{ color: 'red' }}>{ formatMessage(messages.adjustedGradeError) } { possibleGrade }</div> : hintText}
</span>
);
};
Expand Down
5 changes: 5 additions & 0 deletions src/components/GradesView/EditModal/OverrideTable/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const messages = defineMessages({
defaultMessage: 'Reason',
description: 'Edit Modal Override Table Reason column header',
},
adjustedGradeError: {
id: 'gradebook.GradesView.EditModal.Overrides.adjustedGradeError',
defaultMessage: 'The value exceeds the maximum grade:',
description: 'Edit Modal Override Adjusted Grade Error',
},
});

export default messages;
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ exports[`EditModal component render with error snapshot 1`] = `
Cancel
</ModalDialog.CloseButton>
<Button
disabled={false}
onClick={[MockFunction hooks.handleAdjustedGradeClick]}
variant="primary"
>
Expand Down Expand Up @@ -80,6 +81,7 @@ exports[`EditModal component render without error snapshot 1`] = `
Cancel
</ModalDialog.CloseButton>
<Button
disabled={false}
onClick={[MockFunction hooks.handleAdjustedGradeClick]}
variant="primary"
>
Expand Down
8 changes: 7 additions & 1 deletion src/components/GradesView/EditModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import OverrideTable from './OverrideTable';
import ModalHeaders from './ModalHeaders';
import useEditModalData from './hooks';
import messages from './messages';
import useAdjustedGradeInputData from './OverrideTable/AdjustedGradeInput/hooks';

/**
* <EditModal />
Expand All @@ -31,6 +32,11 @@ export const EditModal = () => {
isOpen,
} = useEditModalData();

const {
value,
possibleGrade,
} = useAdjustedGradeInputData();

return (
<ModalDialog
title={formatMessage(messages.title)}
Expand All @@ -57,7 +63,7 @@ export const EditModal = () => {
<ModalDialog.CloseButton variant="tertiary">
{formatMessage(messages.closeText)}
</ModalDialog.CloseButton>
<Button variant="primary" onClick={handleAdjustedGradeClick}>
<Button variant="primary" onClick={handleAdjustedGradeClick} disabled={value > possibleGrade}>
{formatMessage(messages.saveGrade)}
</Button>
</ActionRow>
Expand Down
23 changes: 22 additions & 1 deletion src/components/GradesView/EditModal/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import OverrideTable from './OverrideTable';
import useEditModalData from './hooks';
import EditModal from '.';
import messages from './messages';
import useAdjustedGradeInputData from './OverrideTable/AdjustedGradeInput/hooks';

jest.mock('./hooks', () => jest.fn());
jest.mock('./ModalHeaders', () => 'ModalHeaders');
jest.mock('./OverrideTable', () => 'OverrideTable');
jest.mock('./OverrideTable/AdjustedGradeInput/hooks', () => jest.fn());

const hookProps = {
onClose: jest.fn().mockName('hooks.onClose'),
Expand All @@ -27,6 +29,12 @@ const hookProps = {
};
useEditModalData.mockReturnValue(hookProps);

const adjustedGradeProps = {
value: 50,
possibleGrade: 100,
};
useAdjustedGradeInputData.mockReturnValue(adjustedGradeProps);

let el;
describe('EditModal component', () => {
beforeEach(() => {
Expand All @@ -39,6 +47,7 @@ describe('EditModal component', () => {
});
it('initializes component hooks', () => {
expect(useEditModalData).toHaveBeenCalled();
expect(useAdjustedGradeInputData).toHaveBeenCalled();
});
});
describe('render', () => {
Expand Down Expand Up @@ -88,16 +97,18 @@ describe('EditModal component', () => {
expect(button.children[0].el).toEqual(formatMessage(messages.closeText));
expect(button.type).toEqual('ModalDialog.CloseButton');
});
test('adjusted grade button', () => {
test('adjusted grade button enabled', () => {
const button = footer[1].findByType(ActionRow)[0].children[1];
expect(button.children[0].el).toEqual(formatMessage(messages.saveGrade));
expect(button.type).toEqual('Button');
expect(button.props.onClick).toEqual(hookProps.handleAdjustedGradeClick);
expect(button.props.disabled).toEqual(false);
});
};
describe('without error', () => {
beforeEach(() => {
useEditModalData.mockReturnValueOnce({ ...hookProps, error: undefined });
useAdjustedGradeInputData.mockReturnValueOnce({ value: 50, possibleGrade: 100 });
el = shallow(<EditModal />);
});
test('snapshot', () => {
Expand All @@ -124,5 +135,15 @@ describe('EditModal component', () => {
});
testFooter();
});
describe('when the adjusted grade button is disabled', () => {
beforeEach(() => {
useAdjustedGradeInputData.mockReturnValueOnce({ value: 101, possibleGrade: 100 });
el = shallow(<EditModal />);
});
test('adjusted grade button is disabled', () => {
const button = el.instance.findByType(ActionRow)[0].children[1];
expect(button.props.disabled).toEqual(true);
});
});
});
});
Empty file added webpack.dev-tutor.config.js
Empty file.

0 comments on commit 35028b5

Please sign in to comment.