-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic tests to SynthesizedValue and SynthesizedTable
- Loading branch information
1 parent
3c07c77
commit d8b4f3f
Showing
8 changed files
with
223 additions
and
7 deletions.
There are no files selected for viewing
139 changes: 139 additions & 0 deletions
139
services/ui-src/src/components/fields/SynthesizedTable.test.jsx
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,139 @@ | ||
import React from "react"; | ||
import { Provider } from "react-redux"; | ||
import { screen, render } from "@testing-library/react"; | ||
import configureMockStore from "redux-mock-store"; | ||
import { lteMask } from "../../util/constants"; | ||
import SynthesizedTable from "./SynthesizedTable"; | ||
|
||
const mockStore = configureMockStore(); | ||
const store = mockStore({ | ||
formData: [ | ||
{ | ||
contents: { | ||
section: { | ||
year: 2023, | ||
state: "AL", | ||
}, | ||
}, | ||
}, | ||
], | ||
global: { | ||
stateName: "AL", | ||
}, | ||
stateUser: { | ||
abbr: "CMS", | ||
}, | ||
enrollmentCounts: { | ||
chipEnrollments: 0, | ||
}, | ||
lastYearFormData: [], | ||
lastYearTotals: {}, | ||
}); | ||
|
||
const defaultProps = { | ||
tableTitle: "Managed Care Costs", | ||
question: { | ||
questions: [], | ||
fieldset_info: { | ||
rows: [ | ||
[ | ||
{ | ||
contents: "Eligible children", | ||
}, | ||
{ | ||
actions: ["identity"], | ||
targets: ["$..*[?(@ && @.id=='2023-05-a-03-01-a')].answer.entry"], | ||
}, | ||
{ | ||
actions: ["identity"], | ||
targets: ["$..*[?(@ && @.id=='2023-05-a-03-01-b')].answer.entry"], | ||
}, | ||
], | ||
], | ||
headers: [ | ||
{ | ||
contents: "", | ||
}, | ||
{ | ||
contents: "FFY 2023", | ||
}, | ||
{ | ||
contents: "FFY 2024", | ||
}, | ||
], | ||
}, | ||
fieldset_type: "synthesized_table", | ||
type: "fieldset", | ||
}, | ||
}; | ||
|
||
const SynthesizedTableComponentWithProps = (testSpecificProps) => { | ||
return ( | ||
<Provider store={store}> | ||
<SynthesizedTable {...defaultProps} {...testSpecificProps} /> | ||
</Provider> | ||
); | ||
}; | ||
|
||
describe("<SynthesizedTable />", () => { | ||
test("should render header and labels", () => { | ||
render(SynthesizedTableComponentWithProps()); | ||
|
||
expect(screen.getByText("FFY 2023")).toBeInTheDocument(); | ||
expect(screen.getByText("FFY 2024")).toBeInTheDocument(); | ||
expect(screen.getByText("Eligible children")).toBeInTheDocument(); | ||
}); | ||
|
||
test("should not render in print view with lessThanEleven mask prop", () => { | ||
render( | ||
SynthesizedTableComponentWithProps({ | ||
question: { | ||
...defaultProps.question, | ||
fieldset_info: { | ||
rows: [ | ||
[ | ||
{ | ||
contents: "Eligible children", | ||
mask: lteMask, | ||
}, | ||
{ | ||
mask: lteMask, | ||
actions: ["identity"], | ||
targets: [ | ||
"$..*[?(@ && @.id=='2023-05-a-03-01-a')].answer.entry", | ||
], | ||
}, | ||
{ | ||
mask: lteMask, | ||
actions: ["identity"], | ||
targets: [ | ||
"$..*[?(@ && @.id=='2023-05-a-03-01-b')].answer.entry", | ||
], | ||
}, | ||
], | ||
], | ||
headers: [ | ||
{ | ||
mask: lteMask, | ||
contents: "", | ||
}, | ||
{ | ||
mask: lteMask, | ||
contents: "FFY 2023", | ||
}, | ||
{ | ||
mask: lteMask, | ||
contents: "FFY 2024", | ||
}, | ||
], | ||
}, | ||
}, | ||
printView: true, | ||
}) | ||
); | ||
|
||
expect(screen.queryByText("FFY 2023")).not.toBeInTheDocument(); | ||
expect(screen.queryByText("FFY 2024")).not.toBeInTheDocument(); | ||
expect(screen.queryByText("Eligible children")).not.toBeInTheDocument(); | ||
}); | ||
}); |
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
79 changes: 79 additions & 0 deletions
79
services/ui-src/src/components/fields/SynthesizedValue.test.jsx
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,79 @@ | ||
import React from "react"; | ||
import { Provider } from "react-redux"; | ||
import { screen, render } from "@testing-library/react"; | ||
import configureMockStore from "redux-mock-store"; | ||
import SynthesizedValue from "./SynthesizedValue"; | ||
import { lteMask } from "../../util/constants"; | ||
|
||
const mockStore = configureMockStore(); | ||
const store = mockStore({ | ||
formData: [ | ||
{ | ||
contents: { | ||
section: { | ||
year: 2023, | ||
state: "AL", | ||
}, | ||
}, | ||
}, | ||
], | ||
global: { | ||
stateName: "AL", | ||
}, | ||
stateUser: { | ||
abbr: "CMS", | ||
}, | ||
enrollmentCounts: { | ||
chipEnrollments: 0, | ||
}, | ||
lastYearFormData: [], | ||
lastYearTotals: {}, | ||
}); | ||
|
||
const defaultProps = { | ||
question: { | ||
questions: [], | ||
fieldset_info: { | ||
actions: ["percentage"], | ||
targets: [ | ||
"$..*[?(@ && @.id=='2023-03-i-02-01-01-05')].answer.entry", | ||
"$..*[?(@ && @.id=='2023-03-i-02-01-01-04')].answer.entry", | ||
], | ||
}, | ||
fieldset_type: "synthesized_value", | ||
type: "fieldset", | ||
}, | ||
}; | ||
|
||
const SynthesizedValueComponentWithProps = (testSpecificProps) => { | ||
return ( | ||
<Provider store={store}> | ||
<SynthesizedValue {...defaultProps} {...testSpecificProps} /> | ||
</Provider> | ||
); | ||
}; | ||
|
||
describe("<Synthesized Value />", () => { | ||
test("should render header and labels", () => { | ||
render(SynthesizedValueComponentWithProps()); | ||
|
||
expect(screen.getByText("Computed:")).toBeInTheDocument(); | ||
}); | ||
|
||
test("should not render in print view with lessThanEleven mask prop", () => { | ||
render( | ||
SynthesizedValueComponentWithProps({ | ||
question: { | ||
...defaultProps.question, | ||
fieldset_info: { | ||
...defaultProps.fieldset_info, | ||
mask: lteMask, | ||
}, | ||
}, | ||
printView: true, | ||
}) | ||
); | ||
|
||
expect(screen.queryByText("Computed:")).not.toBeInTheDocument(); | ||
}); | ||
}); |
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
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
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
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 |
---|---|---|
@@ -1,4 +1 @@ | ||
// import.meta.env is threaded through here in order to mock it out for jest | ||
export const { MODE, BASE_URL } = import.meta.env; | ||
|
||
export const lteMask = "lessThanEleven"; |
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,2 @@ | ||
// import.meta.env is threaded through here in order to mock it out for jest | ||
export const { MODE, BASE_URL } = import.meta.env; |