diff --git a/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/__snapshots__/index.test.jsx.snap b/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/__snapshots__/index.test.jsx.snap index b12be4b3..c3bf452c 100644 --- a/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/__snapshots__/index.test.jsx.snap +++ b/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/__snapshots__/index.test.jsx.snap @@ -3,9 +3,11 @@ exports[`AdjustedGradeInput component render snapshot 1`] = ` some-hint-text diff --git a/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/hooks.js b/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/hooks.js index da315857..9e3ee891 100644 --- a/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/hooks.js +++ b/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/hooks.js @@ -8,13 +8,25 @@ const useAdjustedGradeInputData = () => { const hintText = possibleGrade && ` ${getLocalizedSlash()} ${possibleGrade}`; const onChange = ({ target }) => { - setModalState({ adjustedGradeValue: target.value }); + let adjustedGradeValue; + switch (true) { + case target.value < 0: + adjustedGradeValue = 0; + break; + case possibleGrade && target.value > possibleGrade: + adjustedGradeValue = possibleGrade; + break; + default: + adjustedGradeValue = target.value; + } + setModalState({ adjustedGradeValue }); }; return { value, onChange, hintText, + possibleGrade, }; }; diff --git a/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/hooks.test.jsx b/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/hooks.test.jsx index e266dc3d..69279353 100644 --- a/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/hooks.test.jsx +++ b/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/hooks.test.jsx @@ -57,11 +57,26 @@ describe('useAdjustedGradeInputData hook', () => { }); }); describe('onChange', () => { - it('sets modal state with event target value', () => { - const testValue = 'test-value'; + it('sets modal state with event target value when it is less than possibleGrade', () => { + const testValue = possibleGrade - 1; out.onChange({ target: { value: testValue } }); expect(setModalState).toHaveBeenCalledWith({ adjustedGradeValue: testValue }); }); + it('sets modal state with event target value when it is equal to possibleGrade', () => { + const testValue = possibleGrade; + out.onChange({ target: { value: testValue } }); + expect(setModalState).toHaveBeenCalledWith({ adjustedGradeValue: testValue }); + }); + it('sets modal state to possibleGrade when event target value is greater than possibleGrade', () => { + const testValue = possibleGrade + 1; + out.onChange({ target: { value: testValue } }); + expect(setModalState).toHaveBeenCalledWith({ adjustedGradeValue: possibleGrade }); + }); + it('sets modal state to 0 when event target value is less than 0', () => { + const testValue = -1; + out.onChange({ target: { value: testValue } }); + expect(setModalState).toHaveBeenCalledWith({ adjustedGradeValue: 0 }); + }); }); }); }); diff --git a/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/index.jsx b/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/index.jsx index d070b9b5..5c2c4c4c 100644 --- a/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/index.jsx +++ b/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/index.jsx @@ -14,12 +14,15 @@ export const AdjustedGradeInput = () => { value, onChange, hintText, + possibleGrade, } = useAdjustedGradeInputData(); return (