From 2f6c005a4eed278bbfd1fb3a0d312e440b9ea554 Mon Sep 17 00:00:00 2001 From: rstrange-scottlogic Date: Thu, 22 Aug 2024 09:11:37 +0100 Subject: [PATCH] Minor update to how the pollutant summary determines if no AQI difference has yet been set --- .../summary-comparison-service.spec.ts | 40 +++++++++++++++++++ .../services/summary-comparison-service.ts | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/air-quality-ui/src/services/summary-comparison-service.spec.ts b/air-quality-ui/src/services/summary-comparison-service.spec.ts index 38d0856e..7043fbca 100644 --- a/air-quality-ui/src/services/summary-comparison-service.spec.ts +++ b/air-quality-ui/src/services/summary-comparison-service.spec.ts @@ -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', () => { diff --git a/air-quality-ui/src/services/summary-comparison-service.ts b/air-quality-ui/src/services/summary-comparison-service.ts index 7bd90c01..35c42956 100644 --- a/air-quality-ui/src/services/summary-comparison-service.ts +++ b/air-quality-ui/src/services/summary-comparison-service.ts @@ -68,7 +68,7 @@ const reduceComparisonData = ( const reducedComparisonData = { ...currentComparison } if ( - !reducedComparisonData.aqiDifference || + reducedComparisonData.aqiDifference == undefined || reducedComparisonData.aqiDifference < aqiDifference || (reducedComparisonData.aqiDifference == aqiDifference && reducedComparisonData.forecastData.aqiLevel <