Skip to content

Commit

Permalink
Minor update to how the pollutant summary determines if no AQI differ…
Browse files Browse the repository at this point in the history
…ence has yet been set
  • Loading branch information
rstrange-scottlogic committed Aug 22, 2024
1 parent fe4fb18 commit 2f6c005
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions air-quality-ui/src/services/summary-comparison-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,46 @@ describe('Summary Comparison Service createComparisonData', () => {
value: 6,
})
})
it('should produce comparisons defaulting to earliest when forecast is exact', () => {
const forecastData = {
London: [
mockForecastResponseDto({
valid_time: '2024-06-01T00:00:00Z',
overall_aqi_level: 4,
no2: { aqi_level: 4, value: 4 },
}),
mockForecastResponseDto({
valid_time: '2024-06-01T03:00:00Z',
overall_aqi_level: 4,
no2: { aqi_level: 4, value: 4 },
}),
],
}
const measurements = {
London: [
mockMeasurementSummaryResponseDto({
measurement_base_time: '2024-06-01T00:00:00Z',
no2: { mean: { aqi_level: 4, value: 4 } },
}),
mockMeasurementSummaryResponseDto({
measurement_base_time: '2024-06-01T03:00:00Z',
no2: { mean: { aqi_level: 4, value: 4 } },
}),
],
}
const comparisons = createComparisonData(forecastData, measurements)
expect(comparisons.length).toEqual(1)

expect(comparisons[0]['no2'].forecastData).toEqual({
validTime: '2024-06-01T00:00:00Z',
aqiLevel: 4,
value: 4,
})
expect(comparisons[0]['no2'].measurementData).toEqual({
aqiLevel: 4,
value: 4,
})
})
})

describe('Summary Comparison Service createSummaryRow', () => {
Expand Down
2 changes: 1 addition & 1 deletion air-quality-ui/src/services/summary-comparison-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const reduceComparisonData = (
const reducedComparisonData = { ...currentComparison }

if (
!reducedComparisonData.aqiDifference ||
reducedComparisonData.aqiDifference == undefined ||
reducedComparisonData.aqiDifference < aqiDifference ||
(reducedComparisonData.aqiDifference == aqiDifference &&
reducedComparisonData.forecastData.aqiLevel <
Expand Down

0 comments on commit 2f6c005

Please sign in to comment.