From 940482dd9a4fb9f421d056c589a4a3b2db77e2a2 Mon Sep 17 00:00:00 2001 From: Ihor Romaniuk Date: Mon, 12 Aug 2024 17:04:28 +0200 Subject: [PATCH 1/3] fix: add validation to problem number fields (#425) --- .../EditProblemView/SettingsWidget/hooks.js | 6 +++--- .../settingsComponents/ScoringCard.jsx | 4 ++++ .../settingsComponents/ShowAnswerCard.jsx | 1 + .../SettingsWidget/settingsComponents/TimerCard.jsx | 1 + .../settingsComponents/Tolerance/index.jsx | 8 +++++++- .../settingsComponents/Tolerance/index.test.jsx | 9 +++++++-- .../__snapshots__/ScoringCard.test.jsx.snap | 12 ++++++++++++ .../__snapshots__/TimerCard.test.jsx.snap | 1 + 8 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/hooks.js b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/hooks.js index a76fef422..dcac6cf8e 100644 --- a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/hooks.js +++ b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/hooks.js @@ -160,7 +160,7 @@ export const scoringCardHooks = (scoring, updateSettings, defaultValue) => { const handleWeightChange = (event) => { let weight = parseFloat(event.target.value); - if (_.isNaN(weight)) { + if (_.isNaN(weight) || weight < 0) { weight = 0; } updateSettings({ scoring: { ...scoring, weight } }); @@ -194,7 +194,7 @@ export const useAnswerSettings = (showAnswer, updateSettings) => { const handleAttemptsChange = (event) => { let attempts = parseInt(event.target.value); - if (_.isNaN(attempts)) { + if (_.isNaN(attempts) || attempts < 0) { attempts = 0; } updateSettings({ showAnswer: { ...showAnswer, afterAttempts: attempts } }); @@ -210,7 +210,7 @@ export const useAnswerSettings = (showAnswer, updateSettings) => { export const timerCardHooks = (updateSettings) => ({ handleChange: (event) => { let time = parseInt(event.target.value); - if (_.isNaN(time)) { + if (_.isNaN(time) || time < 0) { time = 0; } updateSettings({ timeBetween: time }); diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/ScoringCard.jsx b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/ScoringCard.jsx index 60dc03447..b65a473f5 100644 --- a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/ScoringCard.jsx +++ b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/ScoringCard.jsx @@ -49,6 +49,8 @@ export const ScoringCard = ({ (event) => { if (!isAnswerRangeSet({ answers })) { - const newTolerance = { value: event.target.value, type: tolerance.type }; + let value = parseFloat(event.target.value); + if (value < 0) { + value = 0; + } + const newTolerance = { value, type: tolerance.type }; updateSettings({ tolerance: newTolerance }); } }; @@ -92,6 +96,8 @@ export const ToleranceCard = ({ { const { queryByTestId } = render(); expect(queryByTestId('input')).toBeFalsy(); }); - it('Renders with intial value of tolerance', async () => { + it('Renders with initial value of tolerance', async () => { const { queryByTestId } = render(); expect(queryByTestId('input')).toBeTruthy(); expect(screen.getByDisplayValue('0')).toBeTruthy(); @@ -146,7 +146,12 @@ describe('ToleranceCard', () => { it('Calls change function on change.', () => { const { queryByTestId } = render(); fireEvent.change(queryByTestId('input'), { target: { value: 52 } }); - expect(props.updateSettings).toHaveBeenCalledWith({ tolerance: { type: ToleranceTypes.number.type, value: '52' } }); + expect(props.updateSettings).toHaveBeenCalledWith({ tolerance: { type: ToleranceTypes.number.type, value: 52 } }); + }); + it('Resets negative value on change.', () => { + const { queryByTestId } = render(); + fireEvent.change(queryByTestId('input'), { target: { value: -52 } }); + expect(props.updateSettings).toHaveBeenCalledWith({ tolerance: { type: ToleranceTypes.number.type, value: 0 } }); }); }); }); diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/__snapshots__/ScoringCard.test.jsx.snap b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/__snapshots__/ScoringCard.test.jsx.snap index e6e044d92..9f07b02d0 100644 --- a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/__snapshots__/ScoringCard.test.jsx.snap +++ b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/__snapshots__/ScoringCard.test.jsx.snap @@ -20,7 +20,9 @@ exports[`ScoringCard snapshot snapshot: scoring setting card 1`] = ` @@ -36,8 +38,10 @@ exports[`ScoringCard snapshot snapshot: scoring setting card 1`] = ` @@ -111,8 +117,10 @@ exports[`ScoringCard snapshot snapshot: scoring setting card max attempts 1`] = @@ -186,8 +196,10 @@ exports[`ScoringCard snapshot snapshot: scoring setting card zero zero weight 1` Date: Fri, 16 Aug 2024 17:19:13 +0300 Subject: [PATCH 2/3] fix: license widget checkbox and link (#486) * fix: share alike after save, license link for creative common * test: update snapshot --------- Co-authored-by: Kyrylo Hudym-Levkovych --- .../LicenseWidget/LicenseDetails.jsx | 2 +- .../LicenseWidget/LicenseDisplay.jsx | 16 +++++---- .../LicenseDisplay.test.jsx.snap | 33 ------------------- 3 files changed, 10 insertions(+), 41 deletions(-) diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/LicenseDetails.jsx b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/LicenseDetails.jsx index cba3e3b3a..9cd415a57 100644 --- a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/LicenseDetails.jsx +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/LicenseDetails.jsx @@ -123,7 +123,7 @@ export const LicenseDetails = ({ updateField({ licenseDetails: { diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/LicenseDisplay.jsx b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/LicenseDisplay.jsx index 435d9fd42..67a873cf0 100644 --- a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/LicenseDisplay.jsx +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/LicenseDisplay.jsx @@ -28,13 +28,15 @@ export const LicenseDisplay = ({
{licenseDescription}
- - - + {license === LicenseTypes.creativeCommons && ( + + + + )} ); } diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/__snapshots__/LicenseDisplay.test.jsx.snap b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/__snapshots__/LicenseDisplay.test.jsx.snap index 488422c90..655802d54 100644 --- a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/__snapshots__/LicenseDisplay.test.jsx.snap +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/__snapshots__/LicenseDisplay.test.jsx.snap @@ -26,17 +26,6 @@ exports[`LicenseDisplay snapshots snapshots: renders as expected with default pr FormattedMessage component with license description - - - `; @@ -66,17 +55,6 @@ exports[`LicenseDisplay snapshots snapshots: renders as expected with level set FormattedMessage component with license description - - - `; @@ -148,16 +126,5 @@ exports[`LicenseDisplay snapshots snapshots: renders as expected with level set FormattedMessage component with license description - - - `; From b55e5c9f8fd40f05950f5260af839b6f031b3a29 Mon Sep 17 00:00:00 2001 From: Ihor Romaniuk Date: Fri, 16 Aug 2024 18:19:11 +0200 Subject: [PATCH 3/3] fix: answer range validation in Numerical input (#482) --- src/editors/containers/ProblemEditor/data/OLXParser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.js b/src/editors/containers/ProblemEditor/data/OLXParser.js index 0a3d0ff6a..59e07ff69 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.js @@ -418,7 +418,7 @@ export class OLXParser { [type]: defaultValue, }; } - const isAnswerRange = /[([]\d*,\d*[)\]]/gm.test(numericalresponse['@_answer']); + const isAnswerRange = /[([]\s*\d*,\s*\d*\s*[)\]]/gm.test(numericalresponse['@_answer']); answers.push({ id: indexToLetterMap[answers.length], title: numericalresponse['@_answer'],