Repository: dhsc-govuk/FingertipsNext
Pull request #485: DHSCFT-642: fix bug with using incorrect areaType being used
Author: login: alibombaye
Created: 2025-04-17T12:27:59Z | Merged: 2025-04-22T15:15:05Z

# Description

Jira ticket: [DHSCFT-642](https://bjss-enterprise.atlassian.net/browse/DHSCFT-642)

Fixes a bug when selecting the areaType would result in the chart not being shown for when the areaSelected is defaulted to england.
![Screenshot 2025-04-17 at 13 24 32](https://github.com/user-attachments/assets/a1b9983c-9f51-4b12-954d-9fd80102fa30)

Updates logic when an indicator and an area has insufficient health data points.
![Screenshot 2025-04-17 at 13 25 18](https://github.com/user-attachments/assets/ab14c735-60b0-4a08-b43b-a49237b8eeca)
![Screenshot 2025-04-17 at 13 27 16](https://github.com/user-attachments/assets/e7b1c77f-1d1b-4c63-ae36-914db16d5d78)
^ just one health data point 

## Validation

Tested manually



Diff:
diff --git a/frontend/fingertips-frontend/components/organisms/ViewsWrapper/ViewsWrapper.test.tsx b/frontend/fingertips-frontend/components/organisms/ViewsWrapper/ViewsWrapper.test.tsx
index b7b9bef1d..24ffbb7f8 100644
--- a/frontend/fingertips-frontend/components/organisms/ViewsWrapper/ViewsWrapper.test.tsx
+++ b/frontend/fingertips-frontend/components/organisms/ViewsWrapper/ViewsWrapper.test.tsx
@@ -1,10 +1,10 @@
 import { render, screen } from '@testing-library/react';
 import { ViewsWrapper } from '.';
-import { SearchParams } from '@/lib/searchStateManager';
 import {
   generateMockAreaHealthData,
+  generateMockHealthDataPoint,
   generateMockIndicatorWithAreaHealthData,
-} from './hasHealthDataCheck.test';
+} from './hasSufficientHealthDataCheck.test';
 
 const TestComponent = () => {
   return (
@@ -16,19 +16,18 @@ const TestComponent = () => {
 
 describe('ViewsWrapper', () => {
   it('should render the child component if there are healthData for the selected areas', () => {
-    const searchState = {
-      [SearchParams.AreasSelected]: ['A001'],
-    };
-
     const mockIndicatorsDataForAreas = [
       generateMockIndicatorWithAreaHealthData(1, [
-        generateMockAreaHealthData('A001'),
+        generateMockAreaHealthData('A001', [
+          generateMockHealthDataPoint(2022),
+          generateMockHealthDataPoint(2021),
+        ]),
       ]),
     ];
 
     render(
       <ViewsWrapper
-        searchState={searchState}
+        areaCodes={['A001']}
         indicatorsDataForAreas={mockIndicatorsDataForAreas}
       >
         <TestComponent />
@@ -42,10 +41,6 @@ describe('ViewsWrapper', () => {
   });
 
   it('should render "No data" if there are no healthData for all the selected areas', () => {
-    const searchState = {
-      [SearchParams.AreasSelected]: ['A002'],
-    };
-
     const mockIndicatorsDataForAreas = [
       generateMockIndicatorWithAreaHealthData(1, [
         generateMockAreaHealthData('A001'),
@@ -54,7 +49,7 @@ describe('ViewsWrapper', () => {
 
     render(
       <ViewsWrapper
-        searchState={searchState}
+        areaCodes={['A002']}
         indicatorsDataForAreas={mockIndicatorsDataForAreas}
       >
         <TestComponent />
diff --git a/frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasHealthDataCheck.test.ts b/frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasHealthDataCheck.test.ts
deleted file mode 100644
index 8d30e606b..000000000
--- a/frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasHealthDataCheck.test.ts
+++ /dev/null
@@ -1,152 +0,0 @@
-import {
-  HealthDataForArea,
-  IndicatorWithHealthDataForArea,
-} from '@/generated-sources/ft-api-client';
-import { hasHealthDataCheck } from './hasHealthDataCheck';
-
-export const generateMockAreaHealthData = (
-  areaCode: string
-): HealthDataForArea => {
-  return {
-    areaCode,
-    areaName: `Name ${areaCode}`,
-    healthData: [],
-  };
-};
-
-export const generateMockIndicatorWithAreaHealthData = (
-  indicatorId: number,
-  areaHealthData: HealthDataForArea[]
-): IndicatorWithHealthDataForArea => {
-  return {
-    indicatorId,
-    areaHealthData,
-  };
-};
-
-describe('hasHealthDataCheck', () => {
-  describe('When there is only one indicator', () => {
-    it('should return true if the indicator has health data for the single areaSelected', () => {
-      const areasSelected = ['A001'];
-
-      const indicatorsToCheck = [
-        generateMockIndicatorWithAreaHealthData(1, [
-          generateMockAreaHealthData('A001'),
-        ]),
-      ];
-
-      const result = hasHealthDataCheck(indicatorsToCheck, areasSelected);
-
-      expect(result).toBe(true);
-    });
-
-    it('should return false if the indicator has no health data for the single areaSelected', () => {
-      const areasSelected = ['A001'];
-
-      const indicatorsToCheck = [
-        generateMockIndicatorWithAreaHealthData(1, []),
-      ];
-
-      const result = hasHealthDataCheck(indicatorsToCheck, areasSelected);
-
-      expect(result).toBe(false);
-    });
-
-    it('should return true if the indicator has health data for all the areaSelected', () => {
-      const areasSelected = ['A001', 'A002'];
-
-      const indicatorsToCheck = [
-        generateMockIndicatorWithAreaHealthData(1, [
-          generateMockAreaHealthData('A001'),
-          generateMockAreaHealthData('A002'),
-          generateMockAreaHealthData('A003'),
-        ]),
-      ];
-
-      const result = hasHealthDataCheck(indicatorsToCheck, areasSelected);
-
-      expect(result).toBe(true);
-    });
-
-    it('should return true if the indicator has health data for at least one of the areaSelected', () => {
-      const areasSelected = ['A001', 'A002'];
-
-      const indicatorsToCheck = [
-        generateMockIndicatorWithAreaHealthData(1, [
-          generateMockAreaHealthData('A001'),
-        ]),
-      ];
-
-      const result = hasHealthDataCheck(indicatorsToCheck, areasSelected);
-
-      expect(result).toBe(true);
-    });
-
-    it('should return false if the indicator has no health data for all the areaSelected', () => {
-      const areasSelected = ['A001', 'A002'];
-
-      const indicatorsToCheck = [
-        generateMockIndicatorWithAreaHealthData(1, [
-          generateMockAreaHealthData('A003'),
-        ]),
-      ];
-
-      const result = hasHealthDataCheck(indicatorsToCheck, areasSelected);
-
-      expect(result).toBe(false);
-    });
-  });
-
-  describe('When there are multiple indicators', () => {
-    it('should return true if all the indicator has health data for at least one of the areaSelected', () => {
-      const areasSelected = ['A001', 'A002'];
-
-      const indicatorsToCheck = [
-        generateMockIndicatorWithAreaHealthData(1, [
-          generateMockAreaHealthData('A001'),
-        ]),
-        generateMockIndicatorWithAreaHealthData(2, [
-          generateMockAreaHealthData('A001'),
-        ]),
-      ];
-
-      const result = hasHealthDataCheck(indicatorsToCheck, areasSelected);
-
-      expect(result).toBe(true);
-    });
-
-    it('should return true if one of the indicator has health data for at least one of the areaSelected', () => {
-      const areasSelected = ['A001', 'A002'];
-
-      const indicatorsToCheck = [
-        generateMockIndicatorWithAreaHealthData(1, [
-          generateMockAreaHealthData('A001'),
-        ]),
-        generateMockIndicatorWithAreaHealthData(2, [
-          generateMockAreaHealthData('A003'),
-        ]),
-      ];
-
-      const result = hasHealthDataCheck(indicatorsToCheck, areasSelected);
-
-      expect(result).toBe(true);
-    });
-
-    it('should return false if all the indicator has no health data for all of the areaSelected', () => {
-      const areasSelected = ['A001', 'A002'];
-
-      const indicatorsToCheck = [
-        generateMockIndicatorWithAreaHealthData(1, [
-          generateMockAreaHealthData('A003'),
-        ]),
-        generateMockIndicatorWithAreaHealthData(2, [
-          generateMockAreaHealthData('A003'),
-        ]),
-      ];
-
-      const result = hasHealthDataCheck(indicatorsToCheck, areasSelected);
-
-      expect(result).toBe(false);
-    });
-  });
-});
diff --git a/frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasHealthDataCheck.ts b/frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasHealthDataCheck.ts
deleted file mode 100644
index 420fb408c..000000000
--- a/frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasHealthDataCheck.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import { IndicatorWithHealthDataForArea } from '@/generated-sources/ft-api-client';
-
-const hasAreaHealthData = (
-  indicatorDataForArea: IndicatorWithHealthDataForArea,
-  areasSelected: string[]
-): boolean => {
-  if (indicatorDataForArea.areaHealthData) {
-    return indicatorDataForArea.areaHealthData.reduce<boolean>(
-      (hasHealthData, healthData) => {
-        const hasAreaSelectedHealthData = areasSelected?.find(
-          (areaSelected) => areaSelected === healthData.areaCode
-        );
-
-        if (hasAreaSelectedHealthData) {
-          return true;
-        }
-        return hasHealthData;
-      },
-      false
-    );
-  }
-  return false;
-};
-
-export const hasHealthDataCheck = (
-  indicatorsDataForAreas: IndicatorWithHealthDataForArea[] = [],
-  areasSelected: string[] = []
-): boolean => {
-  const hasHealthDataForAllSelectedAreasAndIndicators = indicatorsDataForAreas
-    ?.map((indicatorData) => {
-      return hasAreaHealthData(indicatorData, areasSelected);
-    })
-    .some(
-      (hasNoHealthDataForAllSelectedArea) => hasNoHealthDataForAllSelectedArea
-    );
-
-  return hasHealthDataForAllSelectedAreasAndIndicators;
-};
diff --git a/frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasSufficientHealthDataCheck.test.ts b/frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasSufficientHealthDataCheck.test.ts
new file mode 100644
index 000000000..e8d065ca3
--- /dev/null
+++ b/frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasSufficientHealthDataCheck.test.ts
@@ -0,0 +1,273 @@
+import {
+  HealthDataForArea,
+  HealthDataPoint,
+  IndicatorWithHealthDataForArea,
+} from '@/generated-sources/ft-api-client';
+import { hasSufficientHealthDataCheck } from './hasSufficientHealthDataCheck';
+import { healthDataPoint } from '@/lib/mocks';
+
+export const generateMockHealthDataPoint = (year: number): HealthDataPoint => {
+  return {
+    ...healthDataPoint,
+    year,
+  };
+};
+
+export const generateMockAreaHealthData = (
+  areaCode: string,
+  healthData: HealthDataPoint[] = []
+): HealthDataForArea => {
+  return {
+    areaCode,
+    areaName: `Name ${areaCode}`,
+    healthData: healthData,
+  };
+};
+
+export const generateMockIndicatorWithAreaHealthData = (
+  indicatorId: number,
+  areaHealthData: HealthDataForArea[]
+): IndicatorWithHealthDataForArea => {
+  return {
+    indicatorId,
+    areaHealthData,
+  };
+};
+
+const sufficientMockHealthDataPoints = [
+  generateMockHealthDataPoint(2022),
+  generateMockHealthDataPoint(2021),
+];
+
+const insufficientMockHealthDataPoints = [generateMockHealthDataPoint(2022)];
+
+describe('hasSufficientHealthDataCheck', () => {
+  describe('When there is only one indicator', () => {
+    it('should return true if the indicator has sufficient health data for the single areaSelected', () => {
+      const areasSelected = ['A001'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', sufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(true);
+    });
+
+    it('should return false if the indicator has insufficient health data for the single areaSelected', () => {
+      const areasSelected = ['A001'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', insufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(false);
+    });
+
+    it('should return true if indicator has insufficient health data for the areas selected but more than 2 areas are selected. Only the latest data health point is provided for more than 2 areas', () => {
+      const areasSelected = ['A001', 'A002', 'A003'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', insufficientMockHealthDataPoints),
+          generateMockAreaHealthData('A002', insufficientMockHealthDataPoints),
+          generateMockAreaHealthData('A003', insufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(true);
+    });
+
+    it('should return false if the indicator has no health data for the single areaSelected', () => {
+      const areasSelected = ['A001'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, []),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(false);
+    });
+
+    it('should return true if the indicator has sufficient health data for all the areaSelected', () => {
+      const areasSelected = ['A001', 'A002'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', sufficientMockHealthDataPoints),
+          generateMockAreaHealthData('A002', sufficientMockHealthDataPoints),
+          generateMockAreaHealthData('A003', sufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(true);
+    });
+
+    it('should return true if the indicator has sufficient health data for at least one of the areaSelected', () => {
+      const areasSelected = ['A001', 'A002'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', sufficientMockHealthDataPoints),
+          generateMockAreaHealthData('A002', insufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(true);
+    });
+
+    it('should return false if the indicator has no health data for all the areaSelected', () => {
+      const areasSelected = ['A001', 'A002'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001'),
+          generateMockAreaHealthData('A002'),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(false);
+    });
+
+    it('should return false if the indicator has insufficient health data for all the areaSelected', () => {
+      const areasSelected = ['A001', 'A002'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', insufficientMockHealthDataPoints),
+          generateMockAreaHealthData('A002', insufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(false);
+    });
+  });
+
+  describe('When there are multiple indicators', () => {
+    it('should return false if all the indicator has no health data for all of the areaSelected', () => {
+      const areasSelected = ['A001', 'A002'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001'),
+          generateMockAreaHealthData('A002'),
+        ]),
+        generateMockIndicatorWithAreaHealthData(2, [
+          generateMockAreaHealthData('A001'),
+          generateMockAreaHealthData('A002'),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(false);
+    });
+
+    it('should return true if all the indicator has sufficient health data for at least one of the areaSelected', () => {
+      const areasSelected = ['A001', 'A002'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', sufficientMockHealthDataPoints),
+        ]),
+        generateMockIndicatorWithAreaHealthData(2, [
+          generateMockAreaHealthData('A001', sufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(true);
+    });
+
+    it('should return true if one of the indicator has health data for at least one of the areaSelected', () => {
+      const areasSelected = ['A001', 'A002'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', sufficientMockHealthDataPoints),
+        ]),
+        generateMockIndicatorWithAreaHealthData(2, [
+          generateMockAreaHealthData('A003', sufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(true);
+    });
+
+    it('should return true if one of the indicators and areasSelected has sufficient health data', () => {
+      const areasSelected = ['A001', 'A002'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', insufficientMockHealthDataPoints),
+          generateMockAreaHealthData('A002', sufficientMockHealthDataPoints),
+        ]),
+        generateMockIndicatorWithAreaHealthData(2, [
+          generateMockAreaHealthData('A001', insufficientMockHealthDataPoints),
+          generateMockAreaHealthData('A002', insufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(true);
+    });
+  });
+});
diff --git a/frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasSufficientHealthDataCheck.ts b/frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasSufficientHealthDataCheck.ts
new file mode 100644
index 000000000..7332bc5c2
--- /dev/null
+++ b/frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasSufficientHealthDataCheck.ts
@@ -0,0 +1,52 @@
+import { IndicatorWithHealthDataForArea } from '@/generated-sources/ft-api-client';
+
+const checkAreaHasSufficientHealthData = (
+  indicatorDataForArea: IndicatorWithHealthDataForArea,
+  areasSelected: string[],
+  indicatorsRequested: number
+): boolean => {
+  if (indicatorDataForArea.areaHealthData) {
+    return indicatorDataForArea.areaHealthData.reduce<boolean>(
+      (hasSufficientAreaHealthData, areaHealthData) => {
+        const healthDataForSelectedArea = areasSelected?.find(
+          (areaSelected) => areaSelected === areaHealthData.areaCode
+        );
+
+        if (healthDataForSelectedArea) {
+          // We only return a single and the most recent health data point when more than one indicator or 2 areas have been selected.
+          // Therefore we can only check there is sufficient data when there is one indicator and 2 or less areas selected.
+          const requiresOnlyLatestHealthData =
+            indicatorsRequested > 1 || areasSelected.length > 2;
+
+          const hasSufficientHealthData = requiresOnlyLatestHealthData
+            ? areaHealthData.healthData.length > 0
+            : areaHealthData.healthData.length > 1;
+
+          if (hasSufficientHealthData) return true;
+        }
+        return hasSufficientAreaHealthData;
+      },
+      false
+    );
+  }
+  return false;
+};
+
+export const hasSufficientHealthDataCheck = (
+  indicatorsDataForAreas: IndicatorWithHealthDataForArea[] = [],
+  areasSelected: string[] = []
+): boolean => {
+  const hasHealthDataForAllSelectedAreasAndIndicators = indicatorsDataForAreas
+    ?.map((indicatorData) => {
+      return checkAreaHasSufficientHealthData(
+        indicatorData,
+        areasSelected,
+        indicatorsDataForAreas.length
+      );
+    })
+    .some(
+      (hasNoHealthDataForAllSelectedArea) => hasNoHealthDataForAllSelectedArea
+    );
+
+  return hasHealthDataForAllSelectedAreasAndIndicators;
+};
diff --git a/frontend/fingertips-frontend/components/organisms/ViewsWrapper/index.tsx b/frontend/fingertips-frontend/components/organisms/ViewsWrapper/index.tsx
index 8631adecd..91bfb21ec 100644
--- a/frontend/fingertips-frontend/components/organisms/ViewsWrapper/index.tsx
+++ b/frontend/fingertips-frontend/components/organisms/ViewsWrapper/index.tsx
@@ -1,30 +1,22 @@
 'use client';
 
 import { IndicatorWithHealthDataForArea } from '@/generated-sources/ft-api-client';
-import { SearchParams, SearchStateParams } from '@/lib/searchStateManager';
 import { Paragraph } from 'govuk-react';
-import { hasHealthDataCheck } from './hasHealthDataCheck';
-import { determineAreaCodes } from '@/lib/chartHelpers/chartHelpers';
+import { hasSufficientHealthDataCheck } from './hasSufficientHealthDataCheck';
 
 interface ViewsWrapperProps {
   children: React.ReactNode;
-  searchState?: SearchStateParams;
+  areaCodes: string[];
   indicatorsDataForAreas?: IndicatorWithHealthDataForArea[];
 }
 
 export function ViewsWrapper({
   children,
-  searchState,
+  areaCodes,
   indicatorsDataForAreas,
 }: Readonly<ViewsWrapperProps>) {
-  const areasSelected = searchState?.[SearchParams.AreasSelected];
-
-  const areaCodes = determineAreaCodes(areasSelected);
-
-  const hasHealthDataForAllSelectedAreasAndIndicators = hasHealthDataCheck(
-    indicatorsDataForAreas ?? [],
-    areaCodes ?? []
-  );
+  const hasHealthDataForAllSelectedAreasAndIndicators =
+    hasSufficientHealthDataCheck(indicatorsDataForAreas ?? [], areaCodes ?? []);
 
   return (
     <>
diff --git a/frontend/fingertips-frontend/components/views/OneIndicatorOneAreaView/OneIndicatorOneAreaView.test.tsx b/frontend/fingertips-frontend/components/views/OneIndicatorOneAreaView/OneIndicatorOneAreaView.test.tsx
index 758c5dcb9..33effc9fa 100644
--- a/frontend/fingertips-frontend/components/views/OneIndicatorOneAreaView/OneIndicatorOneAreaView.test.tsx
+++ b/frontend/fingertips-frontend/components/views/OneIndicatorOneAreaView/OneIndicatorOneAreaView.test.tsx
@@ -109,6 +109,31 @@ describe('OneIndicatorOneAreaView', () => {
     }
   );
 
+  it('should have made a call to getHealthIndicatorData using the defaulted to england area data when no areaTypeSelected and areaSelected was provided', async () => {
+    const searchState: SearchStateParams = {
+      [SearchParams.IndicatorsSelected]: ['1'],
+    };
+    mockIndicatorsApi.getHealthDataForAnIndicator.mockResolvedValueOnce({});
+
+    await OneIndicatorOneAreaView({ searchState: searchState });
+
+    expect(
+      mockIndicatorsApi.getHealthDataForAnIndicator
+    ).toHaveBeenNthCalledWith(
+      1,
+      {
+        areaCodes: [areaCodeForEngland],
+        indicatorId: 1,
+        inequalities: [
+          GetHealthDataForAnIndicatorInequalitiesEnum.Sex,
+          GetHealthDataForAnIndicatorInequalitiesEnum.Deprivation,
+        ],
+        areaType: englandAreaType.key,
+      },
+      API_CACHE_CONFIG
+    );
+  });
+
   it('should pass the first indicatorDocument from selectedIndicatorData as indicatorMetadata prop', async () => {
     const firstIndicatorDocument = generateIndicatorDocument('1');
 
diff --git a/frontend/fingertips-frontend/components/views/OneIndicatorOneAreaView/index.tsx b/frontend/fingertips-frontend/components/views/OneIndicatorOneAreaView/index.tsx
index 0059e135a..ec7c64b16 100644
--- a/frontend/fingertips-frontend/components/views/OneIndicatorOneAreaView/index.tsx
+++ b/frontend/fingertips-frontend/components/views/OneIndicatorOneAreaView/index.tsx
@@ -13,6 +13,7 @@ import { connection } from 'next/server';
 import { ViewProps } from '../ViewsContext';
 import { ViewsWrapper } from '@/components/organisms/ViewsWrapper';
 import { determineAreaCodes } from '@/lib/chartHelpers/chartHelpers';
+import { englandAreaType } from '@/lib/areaFilterHelpers/areaType';
 
 export default async function OneIndicatorOneAreaView({
   selectedIndicatorsData,
@@ -23,7 +24,7 @@ export default async function OneIndicatorOneAreaView({
     [SearchParams.AreasSelected]: areasSelected,
     [SearchParams.IndicatorsSelected]: indicatorSelected,
     [SearchParams.GroupSelected]: selectedGroupCode,
-    [SearchParams.AreaTypeSelected]: AreaTypeSelected,
+    [SearchParams.AreaTypeSelected]: areaTypeSelected,
   } = stateManager.getSearchState();
 
   const areaCodes = determineAreaCodes(areasSelected);
@@ -43,6 +44,11 @@ export default async function OneIndicatorOneAreaView({
   await connection();
   const indicatorApi = ApiClientFactory.getIndicatorsApiClient();
 
+  const areaTypeToUse =
+    areaCodes[0] === areaCodeForEngland
+      ? englandAreaType.key
+      : areaTypeSelected;
+
   let indicatorData: IndicatorWithHealthDataForArea | undefined;
   try {
     indicatorData = await indicatorApi.getHealthDataForAnIndicator(
@@ -53,7 +59,7 @@ export default async function OneIndicatorOneAreaView({
           GetHealthDataForAnIndicatorInequalitiesEnum.Sex,
           GetHealthDataForAnIndicatorInequalitiesEnum.Deprivation,
         ],
-        areaType: AreaTypeSelected,
+        areaType: areaTypeToUse,
       },
       API_CACHE_CONFIG
     );
@@ -64,7 +70,7 @@ export default async function OneIndicatorOneAreaView({
 
   return (
     <ViewsWrapper
-      searchState={searchState}
+      areaCodes={areaCodes}
       indicatorsDataForAreas={[indicatorData]}
     >
       <OneIndicatorOneAreaViewPlots
diff --git a/frontend/fingertips-frontend/components/views/OneIndicatorTwoOrMoreAreasView/index.tsx b/frontend/fingertips-frontend/components/views/OneIndicatorTwoOrMoreAreasView/index.tsx
index 9638db26b..10790e8bc 100644
--- a/frontend/fingertips-frontend/components/views/OneIndicatorTwoOrMoreAreasView/index.tsx
+++ b/frontend/fingertips-frontend/components/views/OneIndicatorTwoOrMoreAreasView/index.tsx
@@ -74,7 +74,7 @@ export default async function OneIndicatorTwoOrMoreAreasView({
 
   return (
     <ViewsWrapper
-      searchState={searchState}
+      areaCodes={areaCodes}
       indicatorsDataForAreas={[indicatorDataAvailableAreas]}
     >
       <OneIndicatorTwoOrMoreAreasViewPlots
diff --git a/frontend/fingertips-frontend/components/views/TwoOrMoreIndicatorsAreasView/index.tsx b/frontend/fingertips-frontend/components/views/TwoOrMoreIndicatorsAreasView/index.tsx
index 9b1fb044b..3dd17d162 100644
--- a/frontend/fingertips-frontend/components/views/TwoOrMoreIndicatorsAreasView/index.tsx
+++ b/frontend/fingertips-frontend/components/views/TwoOrMoreIndicatorsAreasView/index.tsx
@@ -101,7 +101,7 @@ export default async function TwoOrMoreIndicatorsAreasView({
 
   return (
     <ViewsWrapper
-      searchState={searchState}
+      areaCodes={areaCodes}
       indicatorsDataForAreas={combinedIndicatorData}
     >
       <TwoOrMoreIndicatorsAreasViewPlot
diff --git a/frontend/fingertips-frontend/components/views/TwoOrMoreIndicatorsEnglandView/index.tsx b/frontend/fingertips-frontend/components/views/TwoOrMoreIndicatorsEnglandView/index.tsx
index de96a7a16..81bdb688e 100644
--- a/frontend/fingertips-frontend/components/views/TwoOrMoreIndicatorsEnglandView/index.tsx
+++ b/frontend/fingertips-frontend/components/views/TwoOrMoreIndicatorsEnglandView/index.tsx
@@ -55,7 +55,7 @@ export default async function TwoOrMoreIndicatorsEnglandView({
 
   return (
     <ViewsWrapper
-      searchState={searchState}
+      areaCodes={areaCodes}
       indicatorsDataForAreas={combinedIndicatorData}
     >
       <TwoOrMoreIndicatorsEnglandViewPlots


Reviews:
user: login: steves-bjss
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-22T11:53:22Z
user: login: alibombaye
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-22T12:25:29Z
user: login: alibombaye
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-22T12:26:31Z
user: login: gareth-allan
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-22T13:28:35Z
user: login: gareth-allan
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-22T13:44:31Z
user: login: gareth-allan
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-22T13:48:10Z
user: login: gareth-allan
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-22T14:01:56Z
user: login: gareth-allan
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-22T14:03:07Z
user: login: gareth-allan
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-22T15:14:41Z

Review comments:
diff_hunk: @@ -1,34 +1,43 @@
 import { IndicatorWithHealthDataForArea } from '@/generated-sources/ft-api-client';
 
-const hasAreaHealthData = (
+const hasSufficientAreaHealthData = (
   indicatorDataForArea: IndicatorWithHealthDataForArea,
-  areasSelected: string[]
+  areasSelected: string[],
+  indicatorsRequested: number
 ): boolean => {
   if (indicatorDataForArea.areaHealthData) {
     return indicatorDataForArea.areaHealthData.reduce<boolean>(
-      (hasHealthData, healthData) => {
+      (hasSufficientAreaHealthData, areaHealthData) => {
         const hasAreaSelectedHealthData = areasSelected?.find(
-          (areaSelected) => areaSelected === healthData.areaCode
+          (areaSelected) => areaSelected === areaHealthData.areaCode
         );
 
         if (hasAreaSelectedHealthData) {
-          return true;
+          const hasSufficientAreaHealthData =
+            indicatorsRequested === 1 && areasSelected.length <= 2
+              ? areaHealthData.healthData.length > 1
+              : true;
+          if (hasSufficientAreaHealthData) return true;
path: frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasSufficientHealthDataCheck.ts
user: login: steves-bjss
body: Do we need to check the status of hasSufficentAreaHealthData? - we could just return that value or skip the line as it will be returned on line 22.
created_at: 2025-04-22T11:50:40Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,34 +1,43 @@
 import { IndicatorWithHealthDataForArea } from '@/generated-sources/ft-api-client';
 
-const hasAreaHealthData = (
+const hasSufficientAreaHealthData = (
path: frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasSufficientHealthDataCheck.ts
user: login: steves-bjss
body: The same variable name is used on line 3 and line 16 - could we choose an alternative to make things clearer.
created_at: 2025-04-22T11:52:46Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,34 +1,43 @@
 import { IndicatorWithHealthDataForArea } from '@/generated-sources/ft-api-client';
 
-const hasAreaHealthData = (
+const hasSufficientAreaHealthData = (
   indicatorDataForArea: IndicatorWithHealthDataForArea,
-  areasSelected: string[]
+  areasSelected: string[],
+  indicatorsRequested: number
 ): boolean => {
   if (indicatorDataForArea.areaHealthData) {
     return indicatorDataForArea.areaHealthData.reduce<boolean>(
-      (hasHealthData, healthData) => {
+      (hasSufficientAreaHealthData, areaHealthData) => {
         const hasAreaSelectedHealthData = areasSelected?.find(
-          (areaSelected) => areaSelected === healthData.areaCode
+          (areaSelected) => areaSelected === areaHealthData.areaCode
         );
 
         if (hasAreaSelectedHealthData) {
-          return true;
+          const hasSufficientAreaHealthData =
+            indicatorsRequested === 1 && areasSelected.length <= 2
+              ? areaHealthData.healthData.length > 1
+              : true;
+          if (hasSufficientAreaHealthData) return true;
path: frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasSufficientHealthDataCheck.ts
user: login: alibombaye
body: We want to only overwrite the state of `hasSufficientAreaHealthData` when we have sufficient health data for the area. If we remove this check we overwrite the state and this test then fails;
`should return true if the indicator has sufficient health data for at least one of the areaSelected`
The test here has 2 areas with the last one having insufficient health data. We then incorrectly set the entire state to false when it should be true since the first area had sufficient health data.
created_at: 2025-04-22T12:25:29Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,34 +1,43 @@
 import { IndicatorWithHealthDataForArea } from '@/generated-sources/ft-api-client';
 
-const hasAreaHealthData = (
+const hasSufficientAreaHealthData = (
path: frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasSufficientHealthDataCheck.ts
user: login: alibombaye
body: Yeah updating naming has helped. Good spot 👍 
created_at: 2025-04-22T12:26:31Z
author_association: CONTRIBUTOR
diff_hunk: @@ -43,6 +44,11 @@ export default async function OneIndicatorOneAreaView({
   await connection();
   const indicatorApi = ApiClientFactory.getIndicatorsApiClient();
 
+  const areaTypeToUse =
+    areaCodes.length === 1 && areaCodes[0] === areaCodeForEngland
+      ? englandAreaType.key
+      : areaTypeSelected;
path: frontend/fingertips-frontend/components/views/OneIndicatorOneAreaView/index.tsx
user: login: gareth-allan
body: I think, given the block above that will throw an error if `areaCodes.length !==1`, we can safely assume we only have a single area code in this view.
```suggestion
  const areaTypeToUse =
    areaCodes[0] === areaCodeForEngland
      ? englandAreaType.key
      : areaTypeSelected;
```
created_at: 2025-04-22T13:28:35Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,47 @@
+import { IndicatorWithHealthDataForArea } from '@/generated-sources/ft-api-client';
+
+const checkAreaHasSufficientHealthData = (
+  indicatorDataForArea: IndicatorWithHealthDataForArea,
+  areasSelected: string[],
+  indicatorsRequested: number
+): boolean => {
+  if (indicatorDataForArea.areaHealthData) {
+    return indicatorDataForArea.areaHealthData.reduce<boolean>(
+      (hasSufficientAreaHealthData, areaHealthData) => {
+        const healthDataForSelectedArea = areasSelected?.find(
+          (areaSelected) => areaSelected === areaHealthData.areaCode
+        );
+
+        if (healthDataForSelectedArea) {
+          const hasSufficientHealthData =
+            indicatorsRequested === 1 && areasSelected.length <= 2
+              ? areaHealthData.healthData.length > 1
path: frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasSufficientHealthDataCheck.ts
user: login: gareth-allan
body: This is because we need to display a line chart for 1 indicator/1 area and 1 indicator/2 areas, and we need > 1 data point for a line chart, right? Might be worth a comment/extracting to a nicely named function to make it clear what's going on, as it took me a while to work through it.
created_at: 2025-04-22T13:44:31Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,259 @@
+import {
+  HealthDataForArea,
+  HealthDataPoint,
+  HealthDataPointTrendEnum,
+  IndicatorWithHealthDataForArea,
+} from '@/generated-sources/ft-api-client';
+import { hasSufficientHealthDataCheck } from './hasSufficientHealthDataCheck';
+
+export const generateMockHealthDataPoint = (year: number): HealthDataPoint => {
+  return {
+    year,
+    ageBand: { value: '0-4', isAggregate: false },
+    sex: { value: 'female', isAggregate: false },
+    trend: HealthDataPointTrendEnum.IncreasingAndGettingBetter,
+    deprivation: {
+      sequence: 0,
+      value: 'dep1',
+      type: 'depType',
+      isAggregate: false,
+    },
+  };
+};
path: frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasSufficientHealthDataCheck.test.ts
user: login: gareth-allan
body: Can you use `healthDataPoint` from `frontend/fingertips-frontend/lib/mocks.ts` here and just replace the year? It just means one less place to update if we change the structure of the health data point in the API response.
created_at: 2025-04-22T13:48:10Z
author_association: CONTRIBUTOR
diff_hunk: @@ -13,10 +13,15 @@ const checkAreaHasSufficientHealthData = (
         );
 
         if (healthDataForSelectedArea) {
-          const hasSufficientHealthData =
-            indicatorsRequested === 1 && areasSelected.length <= 2
-              ? areaHealthData.healthData.length > 1
-              : true;
+          // We only return a single and the most recent health data point when more that one indicator or 2 areas have have been selected.
+          // Therefore we can only check there is sufficient data when there is one indicator and 2 or less areas selected.
+          const hasOnlyLatestHealthData =
path: frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasSufficientHealthDataCheck.ts
user: login: gareth-allan
body: Perhaps `requiresOnlyLatestHealthData` is slightly clearer?
```suggestion
          const requiresOnlyLatestHealthData =
```
created_at: 2025-04-22T14:01:55Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,251 @@
+import {
+  HealthDataForArea,
+  HealthDataPoint,
+  IndicatorWithHealthDataForArea,
+} from '@/generated-sources/ft-api-client';
+import { hasSufficientHealthDataCheck } from './hasSufficientHealthDataCheck';
+import { healthDataPoint } from '@/lib/mocks';
+
+export const generateMockHealthDataPoint = (year: number): HealthDataPoint => {
+  return {
+    ...healthDataPoint,
+    year,
+  };
+};
+
+export const generateMockAreaHealthData = (
+  areaCode: string,
+  healthData: HealthDataPoint[] = []
+): HealthDataForArea => {
+  return {
+    areaCode,
+    areaName: `Name ${areaCode}`,
+    healthData: healthData,
+  };
+};
+
+export const generateMockIndicatorWithAreaHealthData = (
+  indicatorId: number,
+  areaHealthData: HealthDataForArea[]
+): IndicatorWithHealthDataForArea => {
+  return {
+    indicatorId,
+    areaHealthData,
+  };
+};
+
+const sufficientMockHealthDataPoints = [
+  generateMockHealthDataPoint(2022),
+  generateMockHealthDataPoint(2021),
+];
+
+const insufficientMockHealthDataPoints = [generateMockHealthDataPoint(2022)];
+
+describe('hasSufficientHealthDataCheck', () => {
+  describe('When there is only one indicator', () => {
+    it('should return true if the indicator has sufficient health data for the single areaSelected', () => {
+      const areasSelected = ['A001'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', sufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(true);
+    });
+
+    it('should return false if the indicator has insufficient health data for the single areaSelected', () => {
+      const areasSelected = ['A001'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', insufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(false);
+    });
+
+    it('should return true if indicator has insufficient health data for the areas selected but more than 2 areas are selected. Only the latest data health point is provided for more than 2 areas', () => {
+      const areasSelected = ['A001', 'A002', 'A003'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', insufficientMockHealthDataPoints),
+          generateMockAreaHealthData('A002', insufficientMockHealthDataPoints),
+          generateMockAreaHealthData('A003', insufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(true);
+    });
+
+    it('should return false if the indicator has no health data for the single areaSelected', () => {
+      const areasSelected = ['A001'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, []),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(false);
+    });
+
+    it('should return true if the indicator has sufficient health data for all the areaSelected', () => {
+      const areasSelected = ['A001', 'A002'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', sufficientMockHealthDataPoints),
+          generateMockAreaHealthData('A002', sufficientMockHealthDataPoints),
+          generateMockAreaHealthData('A003', sufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(true);
+    });
+
+    it('should return true if the indicator has sufficient health data for at least one of the areaSelected', () => {
+      const areasSelected = ['A001', 'A002'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', sufficientMockHealthDataPoints),
+          generateMockAreaHealthData('A002', insufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(true);
+    });
+
+    it('should return false if the indicator has no health data for all the areaSelected', () => {
+      const areasSelected = ['A001', 'A002'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001'),
+          generateMockAreaHealthData('A002'),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(false);
+    });
+
+    it('should return false if the indicator has insufficient health data for all the areaSelected', () => {
+      const areasSelected = ['A001', 'A002'];
+
+      const indicatorsToCheck = [
+        generateMockIndicatorWithAreaHealthData(1, [
+          generateMockAreaHealthData('A001', insufficientMockHealthDataPoints),
+          generateMockAreaHealthData('A002', insufficientMockHealthDataPoints),
+        ]),
+      ];
+
+      const result = hasSufficientHealthDataCheck(
+        indicatorsToCheck,
+        areasSelected
+      );
+
+      expect(result).toBe(false);
+    });
+  });
+
+  describe('When there are multiple indicators', () => {
path: frontend/fingertips-frontend/components/organisms/ViewsWrapper/hasSufficientHealthDataCheck.test.ts
user: login: gareth-allan
body: I think you're now missing the `should return false if all the indicator has no health data for all of the areaSelected` case that used to exist in this describe block, aren't you?
created_at: 2025-04-22T14:03:06Z
author_association: CONTRIBUTOR

PR comments:
user: login: sonarqubecloud[bot]
created_at: 2025-04-22T14:49:23Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=dhsc-govuk_FingertipsNext&pullRequest=485) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=dhsc-govuk_FingertipsNext&pullRequest=485&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=dhsc-govuk_FingertipsNext&pullRequest=485&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=dhsc-govuk_FingertipsNext&pullRequest=485&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=dhsc-govuk_FingertipsNext&pullRequest=485&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=dhsc-govuk_FingertipsNext&pullRequest=485&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=dhsc-govuk_FingertipsNext&pullRequest=485)


author_association: NONE