Skip to content

Commit

Permalink
Main -> Val (#139769)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsummers1 authored Sep 20, 2024
2 parents 302182a + ff74b23 commit 36af6a0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 24 deletions.
8 changes: 4 additions & 4 deletions services/ui-src/src/components/fields/Integer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ const getPrevYearValue = (question, lastYearFormData) => {

// Get questions from last years JSON
const questions =
lastYearFormData[3].contents.section.subsections[2].parts[partIndex]
lastYearFormData?.[3]?.contents.section.subsections[2].parts[partIndex]
.questions;

// Filter down to this question
const matchingQuestion = questions.filter(
const matchingQuestion = questions?.filter(
(question) => fieldsetId === question?.fieldset_info?.id
);

// The first will always be correct
if (matchingQuestion[0]) {
prevYearValue = parseInt(matchingQuestion[0].questions[0].answer?.entry);
if (matchingQuestion?.[0]) {
prevYearValue = matchingQuestion[0].questions[0].answer?.entry;
}
}
return prevYearValue;
Expand Down
25 changes: 19 additions & 6 deletions services/ui-src/src/components/layout/FormActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,27 @@ const FormActions = () => {
const printDialogeRef = useRef(null);

// Get section IDs and subsection IDs for printing single section
let searchParams = document.location.pathname
.toString()
.replace("/sections/", "")
.replace(formYear + "/", "");
let searchParams = "";
let sectionId = "";

const sectionId = formYear + "-" + searchParams.substring(0, 2);
let subsectionId = sectionId + "-";
if (currentUser.role === AppRoles.CMS_ADMIN) {
const stateId = window.location.href.split("/")[5];
searchParams = document.location.pathname
.toString()
.replace(`views/sections/${stateId}/`, "")
.replace(formYear + "/", "");

sectionId = formYear + "-" + searchParams.substring(1, 3);
} else {
searchParams = document.location.pathname
.toString()
.replace("/sections/", "")
.replace(formYear + "/", "");

sectionId = formYear + "-" + searchParams.substring(0, 2);
}

let subsectionId = sectionId + "-";
if (sectionId.slice(-2) === "03") {
subsectionId += searchParams.slice(-1);
} else {
Expand Down
70 changes: 56 additions & 14 deletions services/ui-src/src/components/layout/FormActions.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,91 @@ import {
stateUserWithReportInProgress,
} from "../../store/fakeStoreExamples";
import { MemoryRouter } from "react-router";
const firstLocation = "/sections/2021/00";
const adminFirstLocation = "/views/sections/AL/2021/00";

const mockStore = configureMockStore();
const store = mockStore(stateUserWithReportInProgress);
const formActions = (
<Provider store={store}>
<MemoryRouter initialEntries={["/"]}>
<MemoryRouter initialEntries={[firstLocation]}>
<FormActions />
</MemoryRouter>
</Provider>
);
const adminStore = mockStore(adminUserWithReportInProgress);
const adminFormActions = (
<Provider store={adminStore}>
<MemoryRouter initialEntries={["/"]}>
<MemoryRouter initialEntries={[adminFirstLocation]}>
<FormActions />
</MemoryRouter>
</Provider>
);

describe("Fill Form Component", () => {
it("should render correctly", () => {
afterEach(() => {
jest.clearAllMocks();
});

test("should render correctly", () => {
expect(shallow(formActions).exists()).toBe(true);
});
it("should add hrefs given a section and subsection", () => {
test("should add hrefs given a section and subsection", () => {
render(formActions);
window.history.pushState({}, "Title", "/sections/00");
const printShowButton = screen.getByTestId("print-show");
fireEvent.click(printShowButton);
const printFormButton = screen.getByTestId("print-form");
const printPageButton = screen.getByTestId("print-page");
expect(printPageButton).toHaveAttribute(
"href",
"/print?year=2021&state=AL&sectionId=2021-00&subsectionId=2021-00-a"
);
expect(printFormButton).toHaveAttribute(
"href",
"/print?year=2021&state=AL"
);
});

test("should add hrefs given a section and subsection for admin user", () => {
const setLocation = (path = "/") => {
delete window.location;
window.location = new URL("https://www.example.com" + path);
};

setLocation(adminFirstLocation);
render(adminFormActions);
window.history.pushState({}, "Title", "/00/a");
const printShowButton = screen.getByTestId("print-show");
fireEvent.click(printShowButton);
const printFormButton = screen.getByTestId("print-form");
const printPageButton = screen.getByTestId("print-page");
expect(printPageButton).toHaveAttribute("href");
expect(printFormButton).toHaveAttribute("href");
expect(printPageButton).toHaveAttribute(
"href",
"/print?year=2021&state=AL&sectionId=2021-00&subsectionId=2021-00-a"
);
expect(printFormButton).toHaveAttribute(
"href",
"/print?year=2021&state=AL"
);
});
it("should build the component when looking at section 3 subsections", () => {
window.history.pushState({}, "Title", "/sections/03");
test("should build the component when looking at section 3 subsections", () => {
render(adminFormActions);
window.history.pushState({}, "Title", "/sections/03");
window.history.pushState({}, "Title", "/03/a");
const printShowButton = screen.getByTestId("print-show");
fireEvent.click(printShowButton);
const printFormButton = screen.getByTestId("print-form");
const printPageButton = screen.getByTestId("print-page");
expect(printPageButton).toHaveAttribute("href");
expect(printFormButton).toHaveAttribute("href");
expect(printPageButton).toHaveAttribute(
"href",
"/print?year=2021&state=AL&sectionId=2021-03&subsectionId=2021-03-a"
);
expect(printFormButton).toHaveAttribute(
"href",
"/print?year=2021&state=AL"
);
});
it("should display print section or page on click", () => {
test("should display print section or page on click", () => {
render(formActions);
const printShowButton = screen.getByTestId("print-show");
fireEvent.click(printShowButton);
Expand All @@ -60,7 +102,7 @@ describe("Fill Form Component", () => {
expect(printPageButton).toHaveTextContent("This Section");
expect(printFormButton).toHaveTextContent("Entire Form");
});
it("should clear on click", () => {
test("should clear on click", () => {
render(formActions);
const printShowButton = screen.getByTestId("print-show");
fireEvent.click(printShowButton);
Expand All @@ -72,7 +114,7 @@ describe("Fill Form Component", () => {
expect(printPageButton).toBeNull();
expect(printFormButton).toBeNull();
});
it("should not clear on internal click, then clear on outside click", () => {
test("should not clear on internal click, then clear on outside click", () => {
const map = {};

document.addEventListener = jest.fn((event, cb) => {
Expand Down

0 comments on commit 36af6a0

Please sign in to comment.