Skip to content

Commit 6f8664b

Browse files
fix: how did you hear test labels (#5972)
1 parent b44be08 commit 6f8664b

File tree

2 files changed

+198
-64
lines changed

2 files changed

+198
-64
lines changed

sites/partners/__tests__/components/applications/PaperApplicationForm/sections/FormDemographics.test.tsx

Lines changed: 101 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
import { FormDemographics } from "../../../../../src/components/applications/PaperApplicationForm/sections/FormDemographics"
2-
import { mockNextRouter, render, screen, FormProviderWrapper } from "../../../../testUtils"
31
import React from "react"
42
import userEvent from "@testing-library/user-event"
53
import { RaceEthnicityConfiguration } from "@bloom-housing/shared-helpers/src/types/backend-swagger"
64
import { defaultRaceEthnicityConfiguration } from "@bloom-housing/shared-helpers/__tests__/testHelpers"
5+
import { t } from "@bloom-housing/ui-components"
6+
import { FormDemographics } from "../../../../../src/components/applications/PaperApplicationForm/sections/FormDemographics"
7+
import { mockNextRouter, render, screen, FormProviderWrapper, within } from "../../../../testUtils"
78

89
const customConfig: RaceEthnicityConfiguration = {
910
options: [
1011
{
1112
id: "blackAfricanAmerican",
12-
hasSubOptions: false,
1313
subOptions: [],
1414
allowOtherText: false,
1515
},
1616
{
1717
id: "white",
18-
hasSubOptions: false,
1918
subOptions: [],
2019
allowOtherText: false,
2120
},
2221

2322
{
2423
id: "otherMultiracial",
25-
hasSubOptions: false,
2624
subOptions: [],
2725
allowOtherText: true,
2826
},
@@ -73,18 +71,55 @@ describe("<FormDemographics>", () => {
7371

7472
expect(screen.getByLabelText(/ethnicity/i)).toBeInTheDocument()
7573

76-
expect(screen.getByText(/how did you hear about us/i))
77-
expect(screen.getByLabelText(/bus ad/i)).toBeInTheDocument()
78-
expect(screen.getByLabelText(/developer website/i)).toBeInTheDocument()
79-
expect(screen.getByLabelText(/email alert/i)).toBeInTheDocument()
80-
expect(screen.getByLabelText(/flyer/i)).toBeInTheDocument()
81-
expect(screen.getByLabelText(/friend/i)).toBeInTheDocument()
82-
expect(screen.getByLabelText(/housing counselor/i)).toBeInTheDocument()
83-
expect(screen.getByLabelText(/^other$/i)).toBeInTheDocument()
84-
expect(screen.getByLabelText(/radio ad/i)).toBeInTheDocument()
85-
expect(screen.getByLabelText(/jurisdiction website/i)).toBeInTheDocument()
86-
expect(screen.queryByLabelText(/government website/i)).not.toBeInTheDocument()
87-
expect(screen.queryByLabelText(/property website/i)).not.toBeInTheDocument()
74+
const howDidYouHearGroup = screen.getByRole("group", {
75+
name: "How did you hear about us?",
76+
})
77+
expect(within(howDidYouHearGroup).getAllByRole("checkbox")).toHaveLength(9)
78+
expect(
79+
within(howDidYouHearGroup).getByRole("checkbox", {
80+
name: t("application.review.demographics.howDidYouHearOptions.flyer"),
81+
})
82+
).toBeInTheDocument()
83+
expect(
84+
within(howDidYouHearGroup).getByRole("checkbox", {
85+
name: t("application.review.demographics.howDidYouHearOptions.emailAlert"),
86+
})
87+
).toBeInTheDocument()
88+
expect(
89+
within(howDidYouHearGroup).getByRole("checkbox", {
90+
name: t("application.review.demographics.howDidYouHearOptions.friend"),
91+
})
92+
).toBeInTheDocument()
93+
expect(
94+
within(howDidYouHearGroup).getByRole("checkbox", {
95+
name: t("application.review.demographics.howDidYouHearOptions.housingCounselor"),
96+
})
97+
).toBeInTheDocument()
98+
expect(
99+
within(howDidYouHearGroup).getByRole("checkbox", {
100+
name: t("application.review.demographics.howDidYouHearOptions.developerWebsite"),
101+
})
102+
).toBeInTheDocument()
103+
expect(
104+
within(howDidYouHearGroup).getByRole("checkbox", {
105+
name: t("application.review.demographics.howDidYouHearOptions.jurisdictionWebsite"),
106+
})
107+
).toBeInTheDocument()
108+
expect(
109+
within(howDidYouHearGroup).getByRole("checkbox", {
110+
name: t("application.review.demographics.howDidYouHearOptions.busAd"),
111+
})
112+
).toBeInTheDocument()
113+
expect(
114+
within(howDidYouHearGroup).getByRole("checkbox", {
115+
name: t("application.review.demographics.howDidYouHearOptions.radioAd"),
116+
})
117+
).toBeInTheDocument()
118+
expect(
119+
within(howDidYouHearGroup).getByRole("checkbox", {
120+
name: t("application.review.demographics.howDidYouHearOptions.other"),
121+
})
122+
).toBeInTheDocument()
88123
})
89124

90125
it("renders the form with limited how did you hear options when flag is enabled", () => {
@@ -107,18 +142,55 @@ describe("<FormDemographics>", () => {
107142

108143
expect(screen.getByLabelText(/ethnicity/i)).toBeInTheDocument()
109144

110-
expect(screen.getByText(/how did you hear about us/i))
111-
expect(screen.queryByLabelText(/bus ad/i)).not.toBeInTheDocument()
112-
expect(screen.getByLabelText(/developer website/i)).toBeInTheDocument()
113-
expect(screen.getByLabelText(/email alert/i)).toBeInTheDocument()
114-
expect(screen.getByLabelText(/flyer/i)).toBeInTheDocument()
115-
expect(screen.getByLabelText(/friend/i)).toBeInTheDocument()
116-
expect(screen.getByLabelText(/housing counselor/i)).toBeInTheDocument()
117-
expect(screen.getByLabelText(/^other$/i)).toBeInTheDocument()
118-
expect(screen.queryByLabelText(/radio ad/i)).not.toBeInTheDocument()
119-
expect(screen.getByLabelText(/jurisdiction website/i)).toBeInTheDocument()
120-
expect(screen.queryByLabelText(/government website/i)).not.toBeInTheDocument()
121-
expect(screen.queryByLabelText(/property website/i)).not.toBeInTheDocument()
145+
const howDidYouHearGroup = screen.getByRole("group", {
146+
name: "How did you hear about us?",
147+
})
148+
expect(within(howDidYouHearGroup).getAllByRole("checkbox")).toHaveLength(7)
149+
expect(
150+
within(howDidYouHearGroup).getByRole("checkbox", {
151+
name: t("application.review.demographics.howDidYouHearOptions.flyer"),
152+
})
153+
).toBeInTheDocument()
154+
expect(
155+
within(howDidYouHearGroup).getByRole("checkbox", {
156+
name: t("application.review.demographics.howDidYouHearOptions.emailAlert"),
157+
})
158+
).toBeInTheDocument()
159+
expect(
160+
within(howDidYouHearGroup).getByRole("checkbox", {
161+
name: t("application.review.demographics.howDidYouHearOptions.friend"),
162+
})
163+
).toBeInTheDocument()
164+
expect(
165+
within(howDidYouHearGroup).getByRole("checkbox", {
166+
name: t("application.review.demographics.howDidYouHearOptions.housingCounselor"),
167+
})
168+
).toBeInTheDocument()
169+
expect(
170+
within(howDidYouHearGroup).getByRole("checkbox", {
171+
name: t("application.review.demographics.howDidYouHearOptions.developerWebsite"),
172+
})
173+
).toBeInTheDocument()
174+
expect(
175+
within(howDidYouHearGroup).getByRole("checkbox", {
176+
name: t("application.review.demographics.howDidYouHearOptions.jurisdictionWebsite"),
177+
})
178+
).toBeInTheDocument()
179+
expect(
180+
within(howDidYouHearGroup).queryByRole("checkbox", {
181+
name: t("application.review.demographics.howDidYouHearOptions.busAd"),
182+
})
183+
).not.toBeInTheDocument()
184+
expect(
185+
within(howDidYouHearGroup).queryByRole("checkbox", {
186+
name: t("application.review.demographics.howDidYouHearOptions.radioAd"),
187+
})
188+
).not.toBeInTheDocument()
189+
expect(
190+
within(howDidYouHearGroup).getByRole("checkbox", {
191+
name: t("application.review.demographics.howDidYouHearOptions.other"),
192+
})
193+
).toBeInTheDocument()
122194
})
123195

124196
it("should expand suboptions when main key is checked", async () => {
@@ -233,7 +305,6 @@ describe("<FormDemographics>", () => {
233305
options: [
234306
{
235307
id: "asian",
236-
hasSubOptions: true,
237308
subOptions: [
238309
{ id: "chinese", allowOtherText: false },
239310
{ id: "vietnamese", allowOtherText: false },
@@ -242,7 +313,6 @@ describe("<FormDemographics>", () => {
242313
},
243314
{
244315
id: "otherMultiracial",
245-
hasSubOptions: false,
246316
subOptions: [],
247317
allowOtherText: true,
248318
},

sites/public/__tests__/pages/applications/review/demographics.test.tsx

Lines changed: 97 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Listing,
99
RaceEthnicityConfiguration,
1010
} from "@bloom-housing/shared-helpers/src/types/backend-swagger"
11+
import { t } from "@bloom-housing/ui-components"
1112
import { defaultRaceEthnicityConfiguration } from "@bloom-housing/shared-helpers/__tests__/testHelpers"
1213
import { mockNextRouter, render } from "../../../testUtils"
1314
import ApplicationConductor from "../../../../src/lib/applications/ApplicationConductor"
@@ -78,11 +79,55 @@ describe("Demographics", () => {
7879
expect(screen.getByRole("checkbox", { name: "Other / Multiracial" })).toBeInTheDocument()
7980
expect(screen.getByRole("checkbox", { name: "Decline to respond" })).toBeInTheDocument()
8081
expect(screen.getByLabelText("Which best describes your ethnicity?")).toBeInTheDocument()
82+
const howDidYouHearGroup = screen.getByRole("group", {
83+
name: "How did you hear about this listing?",
84+
})
85+
expect(within(howDidYouHearGroup).getAllByRole("checkbox")).toHaveLength(9)
86+
expect(
87+
within(howDidYouHearGroup).getByRole("checkbox", {
88+
name: t("application.review.demographics.howDidYouHearOptions.flyer"),
89+
})
90+
).toBeInTheDocument()
91+
expect(
92+
within(howDidYouHearGroup).getByRole("checkbox", {
93+
name: t("application.review.demographics.howDidYouHearOptions.emailAlert"),
94+
})
95+
).toBeInTheDocument()
8196
expect(
82-
screen.getAllByRole("checkbox", {
83-
name: /Jurisdiction website|Developer website|Flyer|Email alert|Friend|Housing counselor|Radio ad|Bus ad|Other/,
97+
within(howDidYouHearGroup).getByRole("checkbox", {
98+
name: t("application.review.demographics.howDidYouHearOptions.friend"),
8499
})
85-
).toHaveLength(11)
100+
).toBeInTheDocument()
101+
expect(
102+
within(howDidYouHearGroup).getByRole("checkbox", {
103+
name: t("application.review.demographics.howDidYouHearOptions.housingCounselor"),
104+
})
105+
).toBeInTheDocument()
106+
expect(
107+
within(howDidYouHearGroup).getByRole("checkbox", {
108+
name: t("application.review.demographics.howDidYouHearOptions.developerWebsite"),
109+
})
110+
).toBeInTheDocument()
111+
expect(
112+
within(howDidYouHearGroup).getByRole("checkbox", {
113+
name: t("application.review.demographics.howDidYouHearOptions.jurisdictionWebsite"),
114+
})
115+
).toBeInTheDocument()
116+
expect(
117+
within(howDidYouHearGroup).getByRole("checkbox", {
118+
name: t("application.review.demographics.howDidYouHearOptions.busAd"),
119+
})
120+
).toBeInTheDocument()
121+
expect(
122+
within(howDidYouHearGroup).getByRole("checkbox", {
123+
name: t("application.review.demographics.howDidYouHearOptions.radioAd"),
124+
})
125+
).toBeInTheDocument()
126+
expect(
127+
within(howDidYouHearGroup).getByRole("checkbox", {
128+
name: t("application.review.demographics.howDidYouHearOptions.other"),
129+
})
130+
).toBeInTheDocument()
86131
})
87132

88133
it("should render sub demographics fields when parent is checked", () => {
@@ -190,21 +235,6 @@ describe("Demographics", () => {
190235
})
191236
})
192237

193-
it("should show full list of how did you hear fields", () => {
194-
render(<ApplicationDemographics />)
195-
expect(screen.getByText("How did you hear about this listing?")).toBeInTheDocument()
196-
expect(screen.getByRole("checkbox", { name: "Jurisdiction website" })).toBeInTheDocument()
197-
expect(screen.getByRole("checkbox", { name: "Developer website" })).toBeInTheDocument()
198-
expect(screen.getByRole("checkbox", { name: "Flyer" })).toBeInTheDocument()
199-
expect(screen.getByRole("checkbox", { name: "Email alert" })).toBeInTheDocument()
200-
expect(screen.getByRole("checkbox", { name: "Friend" })).toBeInTheDocument()
201-
expect(screen.getByRole("checkbox", { name: "Friend" })).toBeInTheDocument()
202-
expect(screen.getByRole("checkbox", { name: "Housing counselor" })).toBeInTheDocument()
203-
expect(screen.getByRole("checkbox", { name: "Radio ad" })).toBeInTheDocument()
204-
expect(screen.getByRole("checkbox", { name: "Bus ad" })).toBeInTheDocument()
205-
expect(screen.getByRole("checkbox", { name: "Other" })).toBeInTheDocument()
206-
})
207-
208238
it("should show limited list of how did you hear fields when enableLimitedHowDidYouHear is on", () => {
209239
const conductor = new ApplicationConductor({}, {})
210240
conductor.config.featureFlags = [
@@ -229,17 +259,55 @@ describe("Demographics", () => {
229259
<ApplicationDemographics />
230260
</AppSubmissionContext.Provider>
231261
)
232-
expect(screen.getByText("How did you hear about this listing?")).toBeInTheDocument()
233-
expect(screen.getByRole("checkbox", { name: "Jurisdiction website" })).toBeInTheDocument()
234-
expect(screen.getByRole("checkbox", { name: "Developer website" })).toBeInTheDocument()
235-
expect(screen.getByRole("checkbox", { name: "Flyer" })).toBeInTheDocument()
236-
expect(screen.getByRole("checkbox", { name: "Email alert" })).toBeInTheDocument()
237-
expect(screen.getByRole("checkbox", { name: "Friend" })).toBeInTheDocument()
238-
expect(screen.getByRole("checkbox", { name: "Friend" })).toBeInTheDocument()
239-
expect(screen.getByRole("checkbox", { name: "Housing counselor" })).toBeInTheDocument()
240-
expect(screen.queryByRole("checkbox", { name: "Radio ad" })).not.toBeInTheDocument()
241-
expect(screen.queryByRole("checkbox", { name: "Bus ad" })).not.toBeInTheDocument()
242-
expect(screen.getByRole("checkbox", { name: "Other" })).toBeInTheDocument()
262+
const howDidYouHearGroup = screen.getByRole("group", {
263+
name: "How did you hear about this listing?",
264+
})
265+
expect(within(howDidYouHearGroup).getAllByRole("checkbox")).toHaveLength(7)
266+
expect(
267+
within(howDidYouHearGroup).getByRole("checkbox", {
268+
name: t("application.review.demographics.howDidYouHearOptions.flyer"),
269+
})
270+
).toBeInTheDocument()
271+
expect(
272+
within(howDidYouHearGroup).getByRole("checkbox", {
273+
name: t("application.review.demographics.howDidYouHearOptions.emailAlert"),
274+
})
275+
).toBeInTheDocument()
276+
expect(
277+
within(howDidYouHearGroup).getByRole("checkbox", {
278+
name: t("application.review.demographics.howDidYouHearOptions.friend"),
279+
})
280+
).toBeInTheDocument()
281+
expect(
282+
within(howDidYouHearGroup).getByRole("checkbox", {
283+
name: t("application.review.demographics.howDidYouHearOptions.housingCounselor"),
284+
})
285+
).toBeInTheDocument()
286+
expect(
287+
within(howDidYouHearGroup).getByRole("checkbox", {
288+
name: t("application.review.demographics.howDidYouHearOptions.developerWebsite"),
289+
})
290+
).toBeInTheDocument()
291+
expect(
292+
within(howDidYouHearGroup).getByRole("checkbox", {
293+
name: t("application.review.demographics.howDidYouHearOptions.jurisdictionWebsite"),
294+
})
295+
).toBeInTheDocument()
296+
expect(
297+
within(howDidYouHearGroup).queryByRole("checkbox", {
298+
name: t("application.review.demographics.howDidYouHearOptions.busAd"),
299+
})
300+
).not.toBeInTheDocument()
301+
expect(
302+
within(howDidYouHearGroup).queryByRole("checkbox", {
303+
name: t("application.review.demographics.howDidYouHearOptions.radioAd"),
304+
})
305+
).not.toBeInTheDocument()
306+
expect(
307+
within(howDidYouHearGroup).getByRole("checkbox", {
308+
name: t("application.review.demographics.howDidYouHearOptions.other"),
309+
})
310+
).toBeInTheDocument()
243311
})
244312

245313
it("should hide ethnicity field when disabledEthnicityQuestion flag is on", () => {
@@ -280,19 +348,16 @@ describe("Demographics", () => {
280348
options: [
281349
{
282350
id: "blackAfricanAmerican",
283-
hasSubOptions: false,
284351
subOptions: [],
285352
allowOtherText: false,
286353
},
287354
{
288355
id: "white",
289-
hasSubOptions: false,
290356
subOptions: [],
291357
allowOtherText: false,
292358
},
293359
{
294360
id: "otherMultiracial",
295-
hasSubOptions: false,
296361
subOptions: [],
297362
allowOtherText: true,
298363
},
@@ -340,7 +405,6 @@ describe("Demographics", () => {
340405
options: [
341406
{
342407
id: "asian",
343-
hasSubOptions: true,
344408
subOptions: [
345409
{ id: "chinese", allowOtherText: false },
346410
{ id: "vietnamese", allowOtherText: false },

0 commit comments

Comments
 (0)