Skip to content

Commit

Permalink
format dno name + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Feb 6, 2024
1 parent d73b941 commit 21c594c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, expect, test } from "@jest/globals";
import {
formatDNORegionName,
} from "./useAggregateSitesDataForTimestamp";

describe("check formatDNORegionName ", () => {
test("Check we are getting the correct respsonse", () => {
expect(formatDNORegionName("UKPN (East)")).toBe("East (UKPN)");
expect(formatDNORegionName("SSE")).toBe("SSE");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ const getPvActualGenerationForSite = (
);
};

export const formatDNORegionName = (regionName: string) => {
/* The long name is like this "UKPN (East)" or just "SSE".
We want to change this to "East (UKPN)" or just "SSE" */

// if regionName is empty then return now
if (!regionName) return regionName;

const regionNameParts = regionName.split(" ");
if (regionNameParts.length > 1) {
// Strip out the brackets
regionName = `${regionNameParts[1].replace('(','').replace(')','')}`;

// join names back together
regionName = `${regionName} (${regionNameParts[0]})`;
}

return regionName;
};

export const useAggregateSitesDataForTimestamp = (
combinedSitesData: CombinedSitesData,
selectedISOTime: string
Expand Down Expand Up @@ -108,9 +127,12 @@ export const useAggregateSitesDataForTimestamp = (
const regionLatLong = dnoLatLongMap.get(region.dno_id);
const regionLat = regionLatLong?.lat || 0;
const regionLong = regionLatLong?.long || 0;

const regionNameFormatted = formatDNORegionName(regionName);

let updatedRegionData = sitesTableData.regions.get(regionId) || {
id: regionId,
label: regionName,
label: regionNameFormatted,
capacity: 0,
actualPV: 0,
expectedPV: 0,
Expand Down Expand Up @@ -205,3 +227,4 @@ export const useAggregateSitesDataForTimestamp = (
return sitesTableData;
}, [firstForecastData, selectedISOTime]);
};

0 comments on commit 21c594c

Please sign in to comment.