Skip to content

Commit

Permalink
Ensure Section 2 tables populate for admins (#139757)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmrabian authored Sep 6, 2024
1 parent 0e8e6af commit 3dbba17
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 32 deletions.
61 changes: 30 additions & 31 deletions services/ui-src/src/util/synthesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ const snakeToCamel = (str) =>
group.toUpperCase().replace("-", "").replace("_", "")
);

// returns the state abbreviation for the associated report
const getStateAbbr = (stateUserAbbr) => {
if (stateUserAbbr) return stateUserAbbr;
const windowPathName = window.location.pathname;
// if admin, grab the state from the URL
const stateFromURL = windowPathName.split("/")[3];

// if admin and in a print view get state param
const urlSearchParams = new URLSearchParams(window.location.search);
const stateFromParams = urlSearchParams.get("state");

return windowPathName.includes("print") ? stateFromParams : stateFromURL;
};

/**
* Retrieve acsSet from state and return for individual state.
*
Expand All @@ -230,26 +244,13 @@ const lookupAcs = (allStatesData, stateUserAbbr, { ffy, acsProperty }) => {
? snakeToCamel(acsProperty)
: acsProperty;

// if allStatesData and stateUser are available
if (allStatesData && stateUserAbbr) {
const windowPathName = window.location.pathname;
// if admin, grab the state from the URL
const stateFromURL = windowPathName.split("/")[3];
// if allStatesData is a populated array
if (allStatesData?.length > 0) {
const stateAbbr = getStateAbbr(stateUserAbbr);

// if admin and in a print view get state param
const urlSearchParams = new URLSearchParams(window.location.search);
const stateFromParams = urlSearchParams.get("state");

// Get stateUser state or fallback to the URL, if an admin
const stateAbbr =
stateUserAbbr ||
(windowPathName.includes("print") ? stateFromParams : stateFromURL);

// Filter for only matching state
const stateData = allStatesData.filter((st) => st.code === stateAbbr)[0];

// Filter for matching state from JSON
const acs = stateData?.acsSet.filter((year) => year.year === +ffy)[0];
// Find data for matching state
const stateData = allStatesData.find((st) => st.code === stateAbbr);
const acs = stateData?.acsSet.find((year) => year.year === +ffy);

// If acs exists, return the value from the object
if (acs) {
Expand Down Expand Up @@ -279,20 +280,18 @@ export const compareACS = (
) => {
const percentagePrecision = 2;
let returnValue = "Not Available";
// if allStatesData and stateUser are available
if (allStatesData && stateUserAbbr) {
// Filter for only matching state
const stateData = allStatesData.filter(
(st) => st.code === stateUserAbbr
)[0];

// Filter for the correct year of state data
const startACS = stateData?.acsSet.filter(
// if allStatesData is a populated array
if (allStatesData?.length > 0) {
const stateAbbr = getStateAbbr(stateUserAbbr);
const stateData = allStatesData.find((st) => st.code === stateAbbr);

// Find the correct year of state data
const startACS = stateData?.acsSet.find(
(year) => year.year === parseInt(ffy1, 10)
)[0];
const endACS = stateData?.acsSet.filter(
);
const endACS = stateData?.acsSet.find(
(year) => year.year === parseInt(ffy2, 10)
)[0];
);

// If start year and end year of ACS exist, return the calculated value (percent change) from the objects
if (startACS && endACS) {
Expand Down
25 changes: 24 additions & 1 deletion services/ui-src/src/util/synthesize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const fallbackChipState = {
},
};

describe("value synthesization utility", () => {
describe("value synthesis utility", () => {
describe("handles identity", () => {
test("with no values", () => {
// Returns undefined, because there's not a value
Expand Down Expand Up @@ -615,6 +615,29 @@ describe("value synthesization utility", () => {
);
expect(out).toEqual({ contents: ["3.70%"] });
});

it("compares two ffys as admin user", () => {
Object.defineProperty(window, "location", {
value: {
pathname: "/views/sections/AL/2023/02",
},
});
const out = synthesize(
{
compareACS: {
ffy1: 2021,
ffy2: 2020,
acsProperty: "numberUninsured",
},
},
state.allStatesData,
state.global.stateName,
undefined, // state user abbreviation
state.enrollmentCounts.chipEnrollments,
state.formData
);
expect(out).toEqual({ contents: ["3.70%"] });
});
});

describe("handles CHIPS Enrollment Data", () => {
Expand Down

0 comments on commit 3dbba17

Please sign in to comment.