From 62656cef9da7a1c53d26ede9af54106a844a827b Mon Sep 17 00:00:00 2001 From: Taras Lytvynenko <69678257+Inferato@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:37:35 +0300 Subject: [PATCH 1/4] feat: adjusted grade field validation --- .../OverrideTable/AdjustedGradeInput/hooks.js | 14 +++++++++++++- .../OverrideTable/AdjustedGradeInput/index.jsx | 5 ++++- 2 files changed, 17 insertions(+), 2 deletions(-) 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/index.jsx b/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/index.jsx index d070b9b5..9cfdf42f 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 ( From 8a3987ea9df4d1b7251711ebc45766f8073524b1 Mon Sep 17 00:00:00 2001 From: Taras Lytvynenko <69678257+Inferato@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:45:49 +0300 Subject: [PATCH 2/4] feat: adjusted grade field validation --- .../EditModal/OverrideTable/AdjustedGradeInput/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/index.jsx b/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/index.jsx index 9cfdf42f..5c2c4c4c 100644 --- a/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/index.jsx +++ b/src/components/GradesView/EditModal/OverrideTable/AdjustedGradeInput/index.jsx @@ -22,7 +22,7 @@ export const AdjustedGradeInput = () => { type="number" name="adjustedGradeValue" min="0" - max={possibleGrade ? possibleGrade : ''} + max={possibleGrade || ''} value={value} onChange={onChange} /> From cbc4939e1a4c73825c3aac93acf4b8ed3909cec6 Mon Sep 17 00:00:00 2001 From: Eugene Dyudyunov Date: Wed, 7 Feb 2024 15:20:46 +0200 Subject: [PATCH 3/4] test: update snapshot --- .../AdjustedGradeInput/__snapshots__/index.test.jsx.snap | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 From 5aba8f209c34b4f4db598aebc03b6e9965c75010 Mon Sep 17 00:00:00 2001 From: Eugene Dyudyunov Date: Wed, 7 Feb 2024 15:40:40 +0200 Subject: [PATCH 4/4] test: increase coverage --- .../AdjustedGradeInput/hooks.test.jsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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 }); + }); }); }); });