Skip to content

Commit e281359

Browse files
Put count inside label (#151)
* show count in label * fix tests
1 parent 6450fe5 commit e281359

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

src/facet_display/FacetDisplay.test.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe.each([undefined, "static", "filterable"] as const)(
143143
}
144144
]
145145
})
146-
await user.click(screen.getByRole("checkbox", { name: "Cats" }))
146+
await user.click(screen.getByRole("checkbox", { name: "Cats 10" }))
147147
expect(spies.onFacetChange).toHaveBeenCalledWith("topic", "Cats", true)
148148
})
149149

@@ -158,10 +158,10 @@ describe.each([undefined, "static", "filterable"] as const)(
158158
]
159159
})
160160
screen.getByRole("checkbox", {
161-
name: "Civil and Environmental Engineering"
161+
name: "Civil and Environmental Engineering 100"
162162
})
163163
screen.getByRole("checkbox", {
164-
name: "Mechanical Engineering"
164+
name: "Mechanical Engineering 200"
165165
})
166166
})
167167

@@ -180,16 +180,16 @@ describe.each([undefined, "static", "filterable"] as const)(
180180
})
181181
const checkboxCount = () => screen.getAllByRole("checkbox").length
182182
expect(checkboxCount()).toBe(3)
183-
screen.getByRole("checkbox", { name: "Cats" })
184-
screen.getByRole("checkbox", { name: "Dogs" })
185-
screen.getByRole("checkbox", { name: "Donkeys" })
183+
screen.getByRole("checkbox", { name: "Cats 10" })
184+
screen.getByRole("checkbox", { name: "Dogs 20" })
185+
screen.getByRole("checkbox", { name: "Donkeys 30" })
186186
rerender({
187187
activeFacets: {
188188
topic: ["Cats", "Dragons"]
189189
}
190190
})
191191
expect(checkboxCount()).toBe(4)
192-
screen.getByRole("checkbox", { name: "Dragons" })
192+
screen.getByRole("checkbox", { name: "Dragons 0" })
193193
})
194194

195195
test("Displays filterable facet if type='filterable'", async () => {
@@ -200,9 +200,9 @@ describe.each([undefined, "static", "filterable"] as const)(
200200
expect(screen.getAllByRole("checkbox")).toHaveLength(3)
201201
invariant(textbox, "Expected textbox to exist")
202202
await user.type(textbox, "D")
203-
const box0 = screen.queryByRole("checkbox", { name: "Cats" })
204-
const box1 = screen.queryByRole("checkbox", { name: "Dogs" })
205-
const box2 = screen.queryByRole("checkbox", { name: "Donkeys" })
203+
const box0 = screen.queryByRole("checkbox", { name: "Cats 10" })
204+
const box1 = screen.queryByRole("checkbox", { name: "Dogs 20" })
205+
const box2 = screen.queryByRole("checkbox", { name: "Donkeys 30" })
206206
expect(!!box0).toBe(false)
207207
expect(!!box1).toBe(true)
208208
expect(!!box2).toBe(true)
@@ -242,26 +242,24 @@ describe("FacetDisplay with type='group' facet", () => {
242242
setup()
243243
const checkboxes = screen.getAllByRole("checkbox")
244244
const withCerts = screen.getByRole("checkbox", {
245-
name: "With Certificate"
245+
name: "With Certificate 20"
246246
})
247-
const free = screen.getByRole("checkbox", { name: "Free Stuff" })
247+
const free = screen.getByRole("checkbox", { name: "Free Stuff 30" })
248248
expect(checkboxes).toEqual([withCerts, free])
249-
250-
const labels = document.querySelectorAll(".facet-label")
251-
expect(labels[0].textContent).toBe("With Certificate20")
252-
expect(labels[1].textContent).toBe("Free Stuff30")
253249
})
254250

255251
test("Clicking a checkbox calls onFacetChange", async () => {
256252
const { spies } = setup()
257-
await user.click(screen.getByRole("checkbox", { name: "With Certificate" }))
253+
await user.click(
254+
screen.getByRole("checkbox", { name: "With Certificate 20" })
255+
)
258256
expect(spies.onFacetChange).toHaveBeenCalledWith(
259257
"certification",
260258
"true",
261259
true
262260
)
263261

264-
await user.click(screen.getByRole("checkbox", { name: "Free Stuff" }))
262+
await user.click(screen.getByRole("checkbox", { name: "Free Stuff 30" }))
265263
expect(spies.onFacetChange).toHaveBeenCalledWith("free", "false", true)
266264
})
267265

@@ -290,7 +288,9 @@ describe("FacetDisplay with type='group' facet", () => {
290288
certification: true
291289
}
292290
})
293-
const checkbox = screen.getByRole("checkbox", { name: "With Certificate" })
291+
const checkbox = screen.getByRole("checkbox", {
292+
name: "With Certificate 0"
293+
})
294294
expect(checkbox).toBeTruthy()
295295
})
296296
})

src/facet_display/SearchFacetItem.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ export function SearchFacetItem(props: Props) {
3030
checked={isChecked}
3131
onChange={onUpdate}
3232
/>
33-
<div className="facet-label">
34-
<label htmlFor={facetId} className={"facet-key"}>
35-
{displayKey ?? ""}
36-
</label>
37-
<div className="facet-count">{bucket.doc_count}</div>
38-
</div>
33+
<label htmlFor={facetId} className="facet-label">
34+
<span className="facet-text">{displayKey ?? ""}</span>
35+
<span className="facet-count">{bucket.doc_count}</span>
36+
</label>
3937
</div>
4038
)
4139
}

0 commit comments

Comments
 (0)