Added tests for formatted value

This commit is contained in:
Hugo Häggmark
2019-01-17 15:14:07 +01:00
parent 4f6e87bbbf
commit 8ccf212f34
2 changed files with 67 additions and 13 deletions

View File

@@ -78,13 +78,19 @@ export class Gauge extends PureComponent<Props> {
}
addRangeToTextMappingText(allValueMappings: ValueMapping[], rangeToTextMapping: RangeMap, value: TimeSeriesValue) {
if (
rangeToTextMapping.from &&
rangeToTextMapping.to &&
value &&
value >= rangeToTextMapping.from &&
value <= rangeToTextMapping.to
) {
if (!rangeToTextMapping.from || !rangeToTextMapping.to || !value) {
return allValueMappings;
}
const valueAsNumber = parseFloat(value as string);
const fromAsNumber = parseFloat(rangeToTextMapping.from as string);
const toAsNumber = parseFloat(rangeToTextMapping.to as string);
if (isNaN(valueAsNumber) || isNaN(fromAsNumber) || isNaN(toAsNumber)) {
return allValueMappings;
}
if (valueAsNumber >= fromAsNumber && valueAsNumber <= toAsNumber) {
return allValueMappings.concat(rangeToTextMapping);
}