From: Jean-Baptiste Lievremont Date: Tue, 8 Apr 2014 09:05:10 +0000 (+0200) Subject: SONAR-5091 Fix handling of zero values for work durations X-Git-Tag: 4.3~108 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=594d162c72e325ea25f4ff767a49e00f0ed66b44;p=sonarqube.git SONAR-5091 Fix handling of zero values for work durations --- diff --git a/sonar-server/src/main/coffee/common/inputs.coffee b/sonar-server/src/main/coffee/common/inputs.coffee index 4352040b021..cbe26df23e8 100644 --- a/sonar-server/src/main/coffee/common/inputs.coffee +++ b/sonar-server/src/main/coffee/common/inputs.coffee @@ -5,6 +5,8 @@ transformPattern = (pattern) -> convertWorkDuration = (value) -> + return 0 if value == '0' + daysPattern = transformPattern t('work_duration.x_days') hoursPattern = transformPattern t('work_duration.x_hours') minutesPattern = transformPattern t('work_duration.x_minutes') @@ -24,7 +26,9 @@ convertWorkDuration = (value) -> restoreWorkDuration = (value) -> + return '0' if value == '0' return value unless /^\d+$/.test value + days = Math.floor(value / (8 * 60)) hours = Math.floor((value - days * 8 * 60) / 60) minutes = value % 60 diff --git a/sonar-server/src/main/coffee/tests/common/inputsSpec.coffee b/sonar-server/src/main/coffee/tests/common/inputsSpec.coffee index d20983d9c65..3cbc6591925 100644 --- a/sonar-server/src/main/coffee/tests/common/inputsSpec.coffee +++ b/sonar-server/src/main/coffee/tests/common/inputsSpec.coffee @@ -17,28 +17,33 @@ describe 'WORK_DUR suite', -> @input.originalVal '2d 7h 13min' expect(@input.val()).toBe 1393 - it 'converts only days', -> @input.originalVal '1d' expect(@input.val()).toBe 480 - it 'converts hours with minutes', -> @input.originalVal '2h 30min' expect(@input.val()).toBe 150 + it 'converts zero', -> + @input.originalVal '0' + expect(@input.val()).toBe 0 + it 'restores', -> @input.val 1393 expect(@input.originalVal()).toBe '2d 7h 13min' + it 'restores zero', -> + @input.val '0' + expect(@input.originalVal()).toBe '0' + it 'returns initially incorrect value', -> @input.val 'something' expect(@input.val()).toBe 'something' - describe 'RATING suite', -> beforeEach ->