-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-add tests that were removed during reskin (#1717)
* fix: Re-enable CookieConsent portion of Dialogs.test.js * test: Restore and repair PoliciesModelledPopup test * chore: Lint
- Loading branch information
Showing
2 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import "@testing-library/jest-dom"; | ||
import { render, waitFor } from "@testing-library/react"; | ||
import { screen } from "@testing-library/react"; | ||
|
||
import CookieConsent from "modals/CookieConsent"; | ||
|
||
jest.mock("react-plotly.js", () => jest.fn()); | ||
|
||
jest.mock("react-router-dom", () => { | ||
const originalModule = jest.requireActual("react-router-dom"); | ||
return { | ||
__esModule: true, | ||
...originalModule, | ||
useSearchParams: jest.fn(), | ||
}; | ||
}); | ||
|
||
describe("Test cookie consent pop-up", () => { | ||
test("Pop-up appears without cookie existing", async () => { | ||
// Launch CookieConsent | ||
const { getByText } = render(<CookieConsent />); | ||
|
||
// Wait for pop-up to appear | ||
await new Promise((r) => setTimeout(r, 1250)); | ||
|
||
// Ensure that component returns | ||
await waitFor(() => { | ||
expect(getByText("Accept")).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test("Pop-up does not appear if cookies have been accepted", async () => { | ||
// Mock cookie that matches desired | ||
Object.defineProperty(window.document, "cookie", { | ||
configurable: true, | ||
writable: true, | ||
value: "consent=granted;max-age=31536000;path=/", | ||
}); | ||
|
||
// Launch CookieConsent | ||
render(<CookieConsent />); | ||
|
||
// Wait for pop-up to appear | ||
await new Promise((r) => setTimeout(r, 1250)); | ||
|
||
// Ensure that return is null | ||
await waitFor(() => { | ||
const acceptButton = screen.queryByText("Accept"); | ||
expect(acceptButton).toBeNull(); | ||
}); | ||
|
||
// Remove cookie | ||
delete window.document.cookie; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import "@testing-library/jest-dom"; | ||
import { render, waitFor } from "@testing-library/react"; | ||
import { BrowserRouter, useSearchParams } from "react-router-dom"; | ||
// External package imports | ||
import fetch from "node-fetch"; | ||
|
||
import HouseholdOutput from "pages/household/output/HouseholdOutput"; | ||
import { createDefaultHousehold } from "../../api/variables"; | ||
|
||
jest.mock("react-plotly.js", () => jest.fn()); | ||
|
||
jest.mock("react-router-dom", () => { | ||
const originalModule = jest.requireActual("react-router-dom"); | ||
return { | ||
__esModule: true, | ||
...originalModule, | ||
useSearchParams: jest.fn(), | ||
}; | ||
}); | ||
|
||
let metadataUS = null; | ||
beforeAll(async () => { | ||
const res = await fetch("https://api.policyengine.org/us/metadata"); | ||
const metadataRaw = await res.json(); | ||
metadataUS = metadataRaw.result; | ||
}); | ||
|
||
describe("Test PoliciesModelledPopup", () => { | ||
test("Pop-up appears after beginning calculations", async () => { | ||
const testProps = { | ||
policy: { | ||
reform: { | ||
label: "testVal", | ||
}, | ||
baseline: { | ||
label: "testVal", | ||
}, | ||
}, | ||
}; | ||
|
||
let sampleHousehold = createDefaultHousehold(metadataUS); | ||
// The below is necessary to prevent a litany of 'quiet' errors that | ||
// will materialize in the console | ||
sampleHousehold.people.you.state_name = { | ||
2024: "az", | ||
}; | ||
sampleHousehold.households["your household"].state_name = { | ||
2024: "az", | ||
}; | ||
|
||
useSearchParams.mockImplementation(() => { | ||
const get = (param) => { | ||
if (param === "focus") { | ||
return "householdOutput.netIncome"; | ||
} else if (param === "reform") { | ||
return "testVal"; | ||
} else if (param === "baseline") { | ||
return "testVal"; | ||
} | ||
}; | ||
return [{ get }]; | ||
}); | ||
|
||
const { getByText } = render( | ||
<BrowserRouter> | ||
<HouseholdOutput | ||
loading={true} | ||
policy={testProps.policy} | ||
metadata={metadataUS} | ||
setHasShownHouseholdPopup={() => false} | ||
householdInput={sampleHousehold} | ||
/> | ||
</BrowserRouter>, | ||
); | ||
|
||
await waitFor(() => { | ||
expect( | ||
getByText( | ||
"PolicyEngine results may not constitute exact tax liabilities or benefit entitlements.", | ||
), | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |