-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No issue: Add a unit test for get measure display info #4014
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ import { | |
} from '@tupaia/ui-components/lib/map'; | ||
import { VALUE_TYPES } from '../components/View/constants'; | ||
import { MAP_COLORS } from '../styles'; | ||
import { formatDataValue } from './formatters'; | ||
import { MARKER_TYPES, SCALE_TYPES } from '../constants'; | ||
|
||
export const MEASURE_TYPE_ICON = 'icon'; | ||
|
@@ -104,27 +103,6 @@ const getNullValueMapping = type => { | |
return baseMapping; | ||
}; | ||
|
||
function getFormattedValue(value, type, valueInfo, scaleType, valueType, submissionDate) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love when code gets deleted, nice one! |
||
switch (type) { | ||
case MEASURE_TYPE_SPECTRUM: | ||
case MEASURE_TYPE_SHADED_SPECTRUM: | ||
if (scaleType === SCALE_TYPES.TIME) { | ||
return `last submission on ${submissionDate}`; | ||
} | ||
return formatDataValue(value, valueType); | ||
case MEASURE_TYPE_RADIUS: | ||
case MEASURE_TYPE_ICON: | ||
case MEASURE_TYPE_COLOR: | ||
case MEASURE_TYPE_SHADING: | ||
if (scaleType === SCALE_TYPES.TIME) { | ||
return `last submission on ${submissionDate}`; | ||
} | ||
return valueInfo.name || value; | ||
default: | ||
return value; | ||
} | ||
} | ||
|
||
const getSpectrumScaleValues = (measureData, measureOption) => { | ||
const { key, scaleType, startDate, endDate } = measureOption; | ||
|
||
|
@@ -223,78 +201,6 @@ export function processMeasureInfo(response) { | |
}; | ||
} | ||
|
||
function getValueInfo(value, valueMapping, hiddenValues = {}) { | ||
if (!value && typeof value !== 'number' && valueMapping.null) { | ||
// use 'no data' value | ||
const nullValue = hiddenValues.null || hiddenValues[valueMapping.null.value]; | ||
|
||
return { | ||
...valueMapping.null, | ||
isHidden: nullValue, | ||
}; | ||
} | ||
|
||
const matchedValue = valueMapping[value]; | ||
|
||
if (!matchedValue) { | ||
// use 'other' value | ||
return { | ||
...valueMapping.other, | ||
isHidden: hiddenValues.other, | ||
value, | ||
}; | ||
} | ||
|
||
return { | ||
...matchedValue, | ||
isHidden: hiddenValues[matchedValue.value], | ||
}; | ||
} | ||
|
||
export function getFormattedInfo(orgUnitData, measureOption) { | ||
const { key, valueMapping, type, displayedValueKey, scaleType, valueType } = measureOption; | ||
|
||
const value = orgUnitData[key]; | ||
const valueInfo = getValueInfo(value, valueMapping); | ||
|
||
if ( | ||
displayedValueKey && | ||
(orgUnitData[displayedValueKey] || orgUnitData[displayedValueKey] === 0) | ||
) { | ||
return { | ||
formattedValue: formatDataValue( | ||
orgUnitData[displayedValueKey], | ||
valueType, | ||
orgUnitData.metadata, | ||
), | ||
valueInfo, | ||
}; | ||
} | ||
|
||
// note: dont use !value here, as 0 is a valid value. | ||
if (value === null || value === undefined) { | ||
return { formattedValue: valueInfo.name || 'No data', valueInfo }; | ||
} | ||
|
||
return { | ||
formattedValue: getFormattedValue( | ||
value, | ||
type, | ||
valueInfo, | ||
scaleType, | ||
valueType, | ||
orgUnitData.submissionDate, | ||
), | ||
valueInfo, | ||
}; | ||
} | ||
|
||
export function getSingleFormattedValue(orgUnitData, measureOptions) { | ||
// For situations where we can only show one value, just show the value | ||
// of the first measure. | ||
return getFormattedInfo(orgUnitData, measureOptions[0]).formattedValue; | ||
} | ||
|
||
// Take a measureData array where the [key]: value is a number | ||
// and filters NaN values (e.g. undefined). | ||
export function flattenNumericalMeasureData(measureData, key) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test title is a little hard to understand. I suggest we call it something shorter like 'should support coloured radius' and if you want the longer description pop in in a comment inside the test case