Skip to content

Commit

Permalink
Prevent 0 as duration and fix the test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
cemalettin-work committed Dec 22, 2020
1 parent 5c580a9 commit c3fe17c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion client/src/pages/reports/EngagementDateFormPartial.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ const EngagementDatePartialFormWithDuration = ({
onWheelCapture={event => event.currentTarget.blur()} // Prevent scroll action on number input
onChange={event => {
const safeVal =
utils.preventNegativeAndLongDigits(event.target.value, 4) || null
utils.preventNonPositiveAndLongDigits(event.target.value, 4) ||
null
setFieldTouched("duration", true, false)
setFieldValue("duration", safeVal, false)
validateFieldDebounced("duration")
Expand Down
6 changes: 3 additions & 3 deletions client/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ export default {
)
},

preventNegativeAndLongDigits: function(valueStr, maxLen) {
preventNonPositiveAndLongDigits: function(valueStr, maxLen) {
let safeVal
const dangerVal = Number(valueStr)
if (!isNaN(dangerVal) && dangerVal < 0) {
safeVal = "0"
if (!isNaN(dangerVal) && dangerVal <= 0) {
safeVal = null
} else {
const nonDigitsRemoved = valueStr.replace(/\D/g, "")
safeVal =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const INVALID_ENGAGEMENT_DURATION_1 = "123456"
const INVALID_ENGAGEMENT_DURATION_2 = "-1"
// positive sliced at 4th digit, negative should turn into 0
const VALID_ENGAGEMENT_DURATION_1 = "1234"
const VALID_ENGAGEMENT_DURATION_2 = "0"
const VALID_ENGAGEMENT_DURATION_2 = ""

const PERSON = "EF 2.1"
const PERSON_VALUE_1 = "HENDERSON, Henry"
Expand Down

0 comments on commit c3fe17c

Please sign in to comment.