fix rating display for 0 point assignments
fix issue where for a 0 points assignment with a custom grading scheme, if a rating starts with a number and contains an e, only the number will be displayed in the gradebook and speedgrader when selected. fixes EVAL-3672 flag=none Test Plan: - create a 0 point assignment with a grading scheme that has a custom rating with a number in front and contains the letter 'e' ex: '19 will do e' - go to the gradebook and apply the rating - confirm that the display does not only display the number but the whole rating - go to speedgrader and confirm that the whole rating is displayed - for other assignments without grading schemes, try inputting values in scientific format and confirm that they still work. ex: 2e3 Change-Id: I53411a6c3bf55b4979154127ae6ba29a785bdde5 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/334811 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Christopher Soto <christopher.soto@instructure.com> Reviewed-by: Sleyder Zuleta <sleyder.zuleta@instructure.com> QA-Review: Jackson Huang <jackson.huang@instructure.com> Product-Review: Ravi Koll <ravi.koll@instructure.com>
This commit is contained in:
parent
c46e8a51d9
commit
78b30ece3a
|
@ -17,7 +17,6 @@
|
|||
*/
|
||||
|
||||
import numberHelper from '@canvas/i18n/numberHelper'
|
||||
import I18n from '@canvas/i18n'
|
||||
import I18nStubber from 'helpers/I18nStubber'
|
||||
|
||||
let input, output, delimiter, separator
|
||||
|
@ -53,7 +52,7 @@ test('uses default parse function', () => {
|
|||
|
||||
test('returns NaN for invalid numbers', () => {
|
||||
numberHelper._parseNumber.restore()
|
||||
ok(isNaN(numberHelper.parse('foo')))
|
||||
ok(Number.isNaN(numberHelper.parse('foo')))
|
||||
})
|
||||
|
||||
test('returns value of parse function', () => {
|
||||
|
@ -78,12 +77,12 @@ test('uses default delimiter and separator if not a valid number', () => {
|
|||
})
|
||||
|
||||
test('returns NaN for null and undefined values', () => {
|
||||
ok(isNaN(numberHelper.parse(null)))
|
||||
ok(isNaN(numberHelper.parse(undefined)))
|
||||
ok(Number.isNaN(numberHelper.parse(null)))
|
||||
ok(Number.isNaN(numberHelper.parse(undefined)))
|
||||
})
|
||||
|
||||
test('returns input if already a number', () => {
|
||||
const input = 4.7
|
||||
input = 4.7
|
||||
equal(numberHelper.parse(input), input)
|
||||
})
|
||||
|
||||
|
@ -92,6 +91,21 @@ test('supports e notation', () => {
|
|||
equal(numberHelper.parse('3e2'), 300)
|
||||
})
|
||||
|
||||
test('supports a negative exponent', () => {
|
||||
numberHelper._parseNumber.restore()
|
||||
equal(numberHelper.parse('3e-1'), 0.3)
|
||||
})
|
||||
|
||||
test('supports a negative scientific notation value', () => {
|
||||
numberHelper._parseNumber.restore()
|
||||
equal(numberHelper.parse('-3e1'), -30)
|
||||
})
|
||||
|
||||
test('does not support an invalid scientific notation format', () => {
|
||||
numberHelper._parseNumber.restore()
|
||||
ok(Number.isNaN(numberHelper.parse('19 will e')))
|
||||
})
|
||||
|
||||
test('parses toString value of objects', () => {
|
||||
numberHelper._parseNumber.restore()
|
||||
const obj = {toString: () => `2${separator}3`}
|
||||
|
|
|
@ -40,7 +40,7 @@ const helper = {
|
|||
}
|
||||
|
||||
// final fallback to old parseFloat - this allows us to still support scientific 'e' notation
|
||||
if (input.toString().match(/e/) && Number.isNaN(Number(num))) {
|
||||
if (Number.isNaN(Number(num)) && helper.isScientific(input.toString())) {
|
||||
num = parseFloat(input)
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,11 @@ const helper = {
|
|||
validate(input: number | string) {
|
||||
return !Number.isNaN(Number(helper.parse(input)))
|
||||
},
|
||||
|
||||
isScientific(inputString: string) {
|
||||
const scientificPattern = /^[+-]?\d+(\.\d*)?([eE][+-]?\d+)$/
|
||||
return inputString.match(scientificPattern)
|
||||
},
|
||||
}
|
||||
|
||||
export default helper
|
||||
|
|
Loading…
Reference in New Issue