From 2f915682123199dc11090f52a9805a7799c8d6d7 Mon Sep 17 00:00:00 2001 From: Chris Chudzicki Date: Wed, 27 Mar 2024 09:26:26 -0400 Subject: [PATCH 1/4] remove enzyme from FacetDisplay test --- package.json | 2 + src/facet_display/FacetDisplay.test.tsx | 207 ++++++++------ src/facet_display/FacetDisplay.tsx | 1 + src/facet_display/FilterableFacet.tsx | 1 + yarn.lock | 361 +++++++++++++++++++++++- 5 files changed, 487 insertions(+), 85 deletions(-) diff --git a/package.json b/package.json index ed713af..0619d82 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,8 @@ "homepage": "https://github.com/mitodl/course-search-utils#readme", "dependencies": { "@mitodl/open-api-axios": "^2024.3.22", + "@testing-library/react": "12", + "@testing-library/user-event": "^14.5.2", "axios": "^1.6.7", "fuse.js": "^7.0.0", "query-string": "^6.13.1", diff --git a/src/facet_display/FacetDisplay.test.tsx b/src/facet_display/FacetDisplay.test.tsx index 9c1e075..c9de094 100644 --- a/src/facet_display/FacetDisplay.test.tsx +++ b/src/facet_display/FacetDisplay.test.tsx @@ -1,118 +1,159 @@ import React from "react" -import { shallow } from "enzyme" +// import { shallow } from "enzyme"; +import { render, screen, within } from "@testing-library/react" +import user from "@testing-library/user-event" -import { - default as FacetDisplay, - AvailableFacets, - getDepartmentName, - getLevelName -} from "./FacetDisplay" -import { FacetManifest, Facets } from "./types" +import FacetDisplay, { getDepartmentName } from "./FacetDisplay" +import type { FacetDisplayProps } from "./FacetDisplay" +import { Bucket, FacetManifest, Facets } from "./types" describe("FacetDisplay component", () => { - const facetMap: FacetManifest = [ + const defaultFacetMap: FacetManifest = [ { name: "topic", title: "Topics", useFilterableFacet: false, - expandedOnLoad: false - }, - { - name: "resource_type", - title: "Types", - useFilterableFacet: false, - expandedOnLoad: false + expandedOnLoad: true }, { name: "department", title: "Departments", useFilterableFacet: false, - expandedOnLoad: true, - labelFunction: getDepartmentName - }, - { - name: "level", - title: "Level", - useFilterableFacet: false, - expandedOnLoad: true, - labelFunction: getLevelName + expandedOnLoad: true } ] - function setup() { + const defaultAggregations = { + topic: [ + { key: "Cats", doc_count: 10 }, + { key: "Dogs", doc_count: 20 }, + { key: "Monkeys", doc_count: 30 } + ], + department: [ + { key: "1", doc_count: 100 }, + { key: "2", doc_count: 200 } + ] + } + + const setup = ({ + props, + aggregations = defaultAggregations + }: { + props?: Partial + aggregations?: Record + } = {}) => { const activeFacets = {} - const facetOptions = jest.fn() + const facetOptions = (group: string) => aggregations[group] ?? [] const clearAllFilters = jest.fn() const onFacetChange = jest.fn() - const render = (props = {}) => - shallow( - - ) - return { render, clearAllFilters } + const view = render( + + ) + const spies = { + onFacetChange, + clearAllFilters + } + return { view, spies } } - test("renders a FacetDisplay with expected FilterableFacets", async () => { - const { render } = setup() - const wrapper = render() - const facets = wrapper.find(AvailableFacets).dive().children() - expect(facets).toHaveLength(4) - facets.map((facet, key) => { - expect(facet.prop("name")).toBe(facetMap[key].name) - expect(facet.prop("title")).toBe(facetMap[key].title) - expect(facet.prop("expandedOnLoad")).toBe(facetMap[key].expandedOnLoad) - }) + test("Renders facets with expected titles", async () => { + setup() + screen.getByRole("button", { name: defaultFacetMap[0].title }) + screen.getByRole("button", { name: defaultFacetMap[1].title }) }) - test("shows filters which are active", () => { - const activeFacets: Facets = { - topic: ["Academic Writing", "Accounting", "Aerodynamics"], - resource_type: [], - department: ["1", "2"] + test.each([{ expandedOnLoad: false }, { expandedOnLoad: true }])( + "Initially expanded based on expandedOnLoad ($expandedOnLoad)", + ({ expandedOnLoad }) => { + const facetMap = [{ ...defaultFacetMap[0], expandedOnLoad }] + setup({ + props: { facetMap } + }) + screen.getByRole("button", { + name: facetMap[0].title, + expanded: expandedOnLoad + }) + const checkboxes = screen.queryAllByRole("checkbox") + expect(checkboxes).toHaveLength(expandedOnLoad ? 3 : 0) } + ) - const { render, clearAllFilters } = setup() - const wrapper = render({ - activeFacets + test("Clicking facet title toggles expanded state", async () => { + setup({ + props: { facetMap: [defaultFacetMap[0]] } }) - expect( - wrapper - .find(".active-search-filters") - .find("SearchFilter") - .map(el => el.prop("value")) - ).toEqual(["Academic Writing", "Accounting", "Aerodynamics", "1", "2"]) - wrapper.find(".clear-all-filters-button").simulate("click") - expect(clearAllFilters).toHaveBeenCalled() + const button = screen.getByRole("button", { + name: defaultFacetMap[0].title + }) + const checkboxCount = () => screen.queryAllByRole("checkbox").length + await user.click(button) + expect(button.getAttribute("aria-expanded")).toBe("false") + expect(checkboxCount()).toBe(0) + await user.click(button) + expect(button.getAttribute("aria-expanded")).toBe("true") + expect(checkboxCount()).toBe(3) }) - test("it accepts a label function to convert codes to names", () => { + test("Shows filters which are active", async () => { const activeFacets: Facets = { - topic: [], - resource_type: [], - department: ["1"], - level: ["graduate"] + topic: ["Cats", "Dogs"], + department: ["1"] + } + const { spies } = setup({ props: { activeFacets } }) + const activeDisplay = document.querySelector(".active-search-filters") + if (!(activeDisplay instanceof HTMLElement)) { + throw new Error("Expected activeDisplay to exist") } + within(activeDisplay).getByText("Cats") + within(activeDisplay).getByText("Dogs") + within(activeDisplay).getByText("1") - const { render, clearAllFilters } = setup() - const wrapper = render({ - activeFacets + await user.click(screen.getByRole("button", { name: "Clear All" })) + expect(spies.clearAllFilters).toHaveBeenCalled() + await user.click(screen.getAllByRole("button", { name: "clear filter" })[0]) + expect(spies.onFacetChange).toHaveBeenCalledWith("topic", "Cats", false) + }) + + test("Clicking a facet checkbox calls onFacetChange", async () => { + const { spies } = setup({ + props: { + facetMap: [ + { + ...defaultFacetMap[0], + expandedOnLoad: true + } + ] + } + }) + await user.click(screen.getByRole("checkbox", { name: "Cats" })) + expect(spies.onFacetChange).toHaveBeenCalledWith("topic", "Cats", true) + }) + + test("it accepts a label function to convert codes to names", () => { + setup({ + props: { + facetMap: [ + { + ...defaultFacetMap[1], + labelFunction: getDepartmentName, + expandedOnLoad: true + } + ] + } + }) + screen.getByRole("checkbox", { + name: "Civil and Environmental Engineering" + }) + screen.getByRole("checkbox", { + name: "Mechanical Engineering" }) - expect( - wrapper - .find(".active-search-filters") - .find("SearchFilter") - .map(el => - el.render().find(".active-search-filter-label").first().html() - ) - ).toEqual(["Civil and Environmental Engineering", "Graduate"]) - wrapper.find(".clear-all-filters-button").simulate("click") - expect(clearAllFilters).toHaveBeenCalled() }) }) diff --git a/src/facet_display/FacetDisplay.tsx b/src/facet_display/FacetDisplay.tsx index 37d62a1..e0a332e 100644 --- a/src/facet_display/FacetDisplay.tsx +++ b/src/facet_display/FacetDisplay.tsx @@ -149,3 +149,4 @@ const FacetDisplay = React.memo( export default FacetDisplay export { AvailableFacets } +export type { FacetDisplayProps } diff --git a/src/facet_display/FilterableFacet.tsx b/src/facet_display/FilterableFacet.tsx index 8125c9e..9546de4 100644 --- a/src/facet_display/FilterableFacet.tsx +++ b/src/facet_display/FilterableFacet.tsx @@ -21,6 +21,7 @@ interface Props { } function FilterableFacet(props: Props) { + console.log("hello from filterable facet") const { name, title, results, selected, onUpdate, expandedOnLoad } = props const [showFacetList, setShowFacetList] = useState(expandedOnLoad) diff --git a/yarn.lock b/yarn.lock index 9842f3c..f4878c4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -22,6 +22,14 @@ dependencies: "@babel/highlight" "^7.10.4" +"@babel/code-frame@^7.10.4": + version "7.24.2" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.24.2.tgz#718b4b19841809a58b29b68cde80bc5e1aa6d9ae" + integrity sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ== + dependencies: + "@babel/highlight" "^7.24.2" + picocolors "^1.0.0" + "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.18.6": version "7.18.6" resolved "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.18.6.tgz" @@ -144,6 +152,11 @@ resolved "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.18.6.tgz" integrity sha512-MmetCkz9ej86nJQV+sFCxoGGrUbU3q02kgLciwkrt9QqEB7cP39oKEY0PakknEO0Gu20SskMRi+AYZ3b1TpN9g== +"@babel/helper-validator-identifier@^7.22.20": + version "7.22.20" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz#c4ae002c61d2879e724581d96665583dbc1dc0e0" + integrity sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A== + "@babel/helper-validator-option@^7.18.6": version "7.18.6" resolved "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.18.6.tgz" @@ -167,6 +180,16 @@ chalk "^2.0.0" js-tokens "^4.0.0" +"@babel/highlight@^7.24.2": + version "7.24.2" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.24.2.tgz#3f539503efc83d3c59080a10e6634306e0370d26" + integrity sha512-Yac1ao4flkTxTteCDZLEvdxg2fZfz1v8M4QpaGypq/WPDqg3ijHYbDfs+LG5hvzSoqaSZ9/Z9lKSP3CjZjv+pA== + dependencies: + "@babel/helper-validator-identifier" "^7.22.20" + chalk "^2.4.2" + js-tokens "^4.0.0" + picocolors "^1.0.0" + "@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.18.10", "@babel/parser@^7.19.0", "@babel/parser@^7.7.0": version "7.19.0" resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.19.0.tgz" @@ -938,6 +961,20 @@ resolved "https://registry.yarnpkg.com/@swc/wasm/-/wasm-1.2.130.tgz#88ac26433335d1f957162a9a92f1450b73c176a0" integrity sha512-rNcJsBxS70+pv8YUWwf5fRlWX6JoY/HJc25HD/F8m6Kv7XhJdqPPMhyX6TKkUBPAG7TWlZYoxa+rHAjPy4Cj3Q== +"@testing-library/dom@^8.0.0": + version "8.20.1" + resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.20.1.tgz#2e52a32e46fc88369eef7eef634ac2a192decd9f" + integrity sha512-/DiOQ5xBxgdYRC8LNk7U+RWat0S3qRLeIw3ZIkMQ9kkVlRmwD/Eg8k8CqIpD6GW7u20JIUOfMKbxtiLutpjQ4g== + dependencies: + "@babel/code-frame" "^7.10.4" + "@babel/runtime" "^7.12.5" + "@types/aria-query" "^5.0.1" + aria-query "5.1.3" + chalk "^4.1.0" + dom-accessibility-api "^0.5.9" + lz-string "^1.5.0" + pretty-format "^27.0.2" + "@testing-library/react-hooks@^8.0.1": version "8.0.1" resolved "https://registry.yarnpkg.com/@testing-library/react-hooks/-/react-hooks-8.0.1.tgz#0924bbd5b55e0c0c0502d1754657ada66947ca12" @@ -946,6 +983,20 @@ "@babel/runtime" "^7.12.5" react-error-boundary "^3.1.0" +"@testing-library/react@12": + version "12.1.5" + resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-12.1.5.tgz#bb248f72f02a5ac9d949dea07279095fa577963b" + integrity sha512-OfTXCJUFgjd/digLUuPxa0+/3ZxsQmE7ub9kcbW/wi96Bh3o/p5vrETcBGfP17NWPGqeYYl5LTRpwyGoMC4ysg== + dependencies: + "@babel/runtime" "^7.12.5" + "@testing-library/dom" "^8.0.0" + "@types/react-dom" "<18.0.0" + +"@testing-library/user-event@^14.5.2": + version "14.5.2" + resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-14.5.2.tgz#db7257d727c891905947bd1c1a99da20e03c2ebd" + integrity sha512-YAh82Wh4TIrxYLmfGcixwD18oIjyC1pFQC2Y01F2lzV2HTMiYrI0nze0FD0ocB//CKS/7jIUgae+adPqxK5yCQ== + "@tootallnate/once@2": version "2.0.0" resolved "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz" @@ -971,6 +1022,11 @@ resolved "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.3.tgz" integrity sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ== +"@types/aria-query@^5.0.1": + version "5.0.4" + resolved "https://registry.yarnpkg.com/@types/aria-query/-/aria-query-5.0.4.tgz#1a31c3d378850d2778dabb6374d036dcba4ba708" + integrity sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw== + "@types/babel__core@^7.1.14": version "7.1.19" resolved "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.19.tgz" @@ -1141,6 +1197,13 @@ dependencies: ts-toolbelt "^6.3.3" +"@types/react-dom@<18.0.0": + version "17.0.25" + resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.25.tgz#e0e5b3571e1069625b3a3da2b279379aa33a0cb5" + integrity sha512-urx7A7UxkZQmThYA4So0NelOVjx3V4rNFVJwp0WZlbIK5eM4rNJDiN3R/E9ix0MBh6kAEojk/9YL+Te6D9zHNA== + dependencies: + "@types/react" "^17" + "@types/react-dom@^16.9.8": version "16.9.8" resolved "https://registry.npmjs.org/@types/react-dom/-/react-dom-16.9.8.tgz" @@ -1156,6 +1219,20 @@ "@types/prop-types" "*" csstype "^3.0.2" +"@types/react@^17": + version "17.0.80" + resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.80.tgz#a5dfc351d6a41257eb592d73d3a85d3b7dbcbb41" + integrity sha512-LrgHIu2lEtIo8M7d1FcI3BdwXWoRQwMoXOZ7+dPTW0lYREjmlHl3P0U1VD0i/9tppOuv8/sam7sOjx34TxSFbA== + dependencies: + "@types/prop-types" "*" + "@types/scheduler" "^0.16" + csstype "^3.0.2" + +"@types/scheduler@^0.16": + version "0.16.8" + resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.8.tgz#ce5ace04cfeabe7ef87c0091e50752e36707deff" + integrity sha512-WZLiwShhwLRmeV6zH+GkbOFT6Z6VklCItrDioxUnv+u4Ll+8vKeFySoFyK/0ctcRpOmwAicELfmys1sDc/Rw+A== + "@types/semver@^7.5.0": version "7.5.7" resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.7.tgz#326f5fdda70d13580777bcaa1bc6fa772a5aef0e" @@ -1477,6 +1554,13 @@ argparse@^2.0.1: resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== +aria-query@5.1.3: + version "5.1.3" + resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-5.1.3.tgz#19db27cd101152773631396f7a95a3b58c22c35e" + integrity sha512-R5iJ5lkuHybztUfuOAznmboyjWq8O6sqNqtK7CLOqdydi54VNbORp49mb14KbWgG1QD3JFO9hJdZ+y4KutfdOQ== + dependencies: + deep-equal "^2.0.5" + array-buffer-byte-length@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/array-buffer-byte-length/-/array-buffer-byte-length-1.0.0.tgz#fabe8bc193fea865f317fe7807085ee0dee5aead" @@ -1568,6 +1652,13 @@ available-typed-arrays@^1.0.5: resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7" integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw== +available-typed-arrays@^1.0.7: + version "1.0.7" + resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz#a5cc375d6a03c2efc87a553f3e0b1522def14846" + integrity sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ== + dependencies: + possible-typed-array-names "^1.0.0" + axios@^1.6.5: version "1.6.8" resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66" @@ -1730,6 +1821,17 @@ call-bind@^1.0.0, call-bind@^1.0.2: function-bind "^1.1.1" get-intrinsic "^1.0.2" +call-bind@^1.0.5, call-bind@^1.0.6, call-bind@^1.0.7: + version "1.0.7" + resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.7.tgz#06016599c40c56498c18769d2730be242b6fa3b9" + integrity sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w== + dependencies: + es-define-property "^1.0.0" + es-errors "^1.3.0" + function-bind "^1.1.2" + get-intrinsic "^1.2.4" + set-function-length "^1.2.1" + callsites@^3.0.0: version "3.1.0" resolved "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz" @@ -1771,7 +1873,7 @@ chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@^2.0.0: +chalk@^2.0.0, chalk@^2.4.2: version "2.4.2" resolved "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -1780,7 +1882,7 @@ chalk@^2.0.0: escape-string-regexp "^1.0.5" supports-color "^5.3.0" -chalk@^4.0.0, chalk@^4.1.2: +chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.2: version "4.1.2" resolved "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz" integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== @@ -1995,6 +2097,30 @@ dedent@^0.7.0: resolved "https://registry.npmjs.org/dedent/-/dedent-0.7.0.tgz" integrity sha512-Q6fKUPqnAHAyhiUgFU7BUzLiv0kd8saH9al7tnu5Q/okj6dnupxyTgFIBjVzJATdfIAm9NAsvXNzjaKa+bxVyA== +deep-equal@^2.0.5: + version "2.2.3" + resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-2.2.3.tgz#af89dafb23a396c7da3e862abc0be27cf51d56e1" + integrity sha512-ZIwpnevOurS8bpT4192sqAowWM76JDKSHYzMLty3BZGSswgq6pBaH3DhCSW5xVAZICZyKdOBPjwww5wfgT/6PA== + dependencies: + array-buffer-byte-length "^1.0.0" + call-bind "^1.0.5" + es-get-iterator "^1.1.3" + get-intrinsic "^1.2.2" + is-arguments "^1.1.1" + is-array-buffer "^3.0.2" + is-date-object "^1.0.5" + is-regex "^1.1.4" + is-shared-array-buffer "^1.0.2" + isarray "^2.0.5" + object-is "^1.1.5" + object-keys "^1.1.1" + object.assign "^4.1.4" + regexp.prototype.flags "^1.5.1" + side-channel "^1.0.4" + which-boxed-primitive "^1.0.2" + which-collection "^1.0.1" + which-typed-array "^1.1.13" + deep-is@^0.1.3, deep-is@~0.1.3: version "0.1.4" resolved "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz" @@ -2005,6 +2131,15 @@ deepmerge@^4.2.2: resolved "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz" integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg== +define-data-property@^1.0.1, define-data-property@^1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/define-data-property/-/define-data-property-1.1.4.tgz#894dc141bb7d3060ae4366f6a0107e68fbe48c5e" + integrity sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A== + dependencies: + es-define-property "^1.0.0" + es-errors "^1.3.0" + gopd "^1.0.1" + define-properties@^1.1.2, define-properties@^1.1.3: version "1.1.3" resolved "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz" @@ -2020,6 +2155,15 @@ define-properties@^1.1.4, define-properties@^1.2.0: has-property-descriptors "^1.0.0" object-keys "^1.1.1" +define-properties@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.2.1.tgz#10781cc616eb951a80a034bafcaa7377f6af2b6c" + integrity sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg== + dependencies: + define-data-property "^1.0.1" + has-property-descriptors "^1.0.0" + object-keys "^1.1.1" + delayed-stream@~1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz" @@ -2071,6 +2215,11 @@ doctrine@^3.0.0: dependencies: esutils "^2.0.2" +dom-accessibility-api@^0.5.9: + version "0.5.16" + resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz#5a7429e6066eb3664d911e33fb0e45de8eb08453" + integrity sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg== + dom-serializer@0, dom-serializer@~0.1.1: version "0.1.1" resolved "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.1.tgz" @@ -2263,6 +2412,33 @@ es-abstract@^1.19.0, es-abstract@^1.20.4: unbox-primitive "^1.0.2" which-typed-array "^1.1.9" +es-define-property@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/es-define-property/-/es-define-property-1.0.0.tgz#c7faefbdff8b2696cf5f46921edfb77cc4ba3845" + integrity sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ== + dependencies: + get-intrinsic "^1.2.4" + +es-errors@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/es-errors/-/es-errors-1.3.0.tgz#05f75a25dab98e4fb1dcd5e1472c0546d5057c8f" + integrity sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw== + +es-get-iterator@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/es-get-iterator/-/es-get-iterator-1.1.3.tgz#3ef87523c5d464d41084b2c3c9c214f1199763d6" + integrity sha512-sPZmqHBe6JIiTfN5q2pEi//TwxmAFHwj/XEuYjTuse78i8KxaqMTTzxPoFKuzRpDpTJ+0NAbpfenkmH2rePtuw== + dependencies: + call-bind "^1.0.2" + get-intrinsic "^1.1.3" + has-symbols "^1.0.3" + is-arguments "^1.1.1" + is-map "^2.0.2" + is-set "^2.0.2" + is-string "^1.0.7" + isarray "^2.0.5" + stop-iteration-iterator "^1.0.0" + es-set-tostringtag@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/es-set-tostringtag/-/es-set-tostringtag-2.0.1.tgz#338d502f6f674301d710b80c8592de8a15f09cd8" @@ -2745,6 +2921,11 @@ function-bind@^1.1.1: resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz" integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== +function-bind@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c" + integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA== + function.prototype.name@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/function.prototype.name/-/function.prototype.name-1.1.2.tgz" @@ -2799,6 +2980,17 @@ get-intrinsic@^1.0.2, get-intrinsic@^1.1.1, get-intrinsic@^1.1.3, get-intrinsic@ has-proto "^1.0.1" has-symbols "^1.0.3" +get-intrinsic@^1.2.2, get-intrinsic@^1.2.4: + version "1.2.4" + resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.2.4.tgz#e385f5a4b5227d449c3eabbad05494ef0abbeadd" + integrity sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ== + dependencies: + es-errors "^1.3.0" + function-bind "^1.1.2" + has-proto "^1.0.1" + has-symbols "^1.0.3" + hasown "^2.0.0" + get-package-type@^0.1.0: version "0.1.0" resolved "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz" @@ -2925,6 +3117,13 @@ has-property-descriptors@^1.0.0: dependencies: get-intrinsic "^1.1.1" +has-property-descriptors@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz#963ed7d071dc7bf5f084c5bfbe0d1b6222586854" + integrity sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg== + dependencies: + es-define-property "^1.0.0" + has-proto@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/has-proto/-/has-proto-1.0.1.tgz#1885c1305538958aff469fef37937c22795408e0" @@ -2947,6 +3146,13 @@ has-tostringtag@^1.0.0: dependencies: has-symbols "^1.0.2" +has-tostringtag@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/has-tostringtag/-/has-tostringtag-1.0.2.tgz#2cdc42d40bef2e5b4eeab7c01a73c54ce7ab5abc" + integrity sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw== + dependencies: + has-symbols "^1.0.3" + has@^1.0.3: version "1.0.3" resolved "https://registry.npmjs.org/has/-/has-1.0.3.tgz" @@ -2954,6 +3160,13 @@ has@^1.0.3: dependencies: function-bind "^1.1.1" +hasown@^2.0.0: + version "2.0.2" + resolved "https://registry.yarnpkg.com/hasown/-/hasown-2.0.2.tgz#003eaf91be7adc372e84ec59dc37252cedb80003" + integrity sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ== + dependencies: + function-bind "^1.1.2" + "history-v4@npm:history@^4.9": version "4.10.1" resolved "https://registry.npmjs.org/history/-/history-4.10.1.tgz" @@ -3091,6 +3304,23 @@ internal-slot@^1.0.3, internal-slot@^1.0.5: has "^1.0.3" side-channel "^1.0.4" +internal-slot@^1.0.4: + version "1.0.7" + resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.7.tgz#c06dcca3ed874249881007b0a5523b172a190802" + integrity sha512-NGnrKwXzSms2qUUih/ILZ5JBqNTSa1+ZmP6flaIp6KmSElgE9qdndzS3cqjrDovwFdmwsGsLdeFgB6suw+1e9g== + dependencies: + es-errors "^1.3.0" + hasown "^2.0.0" + side-channel "^1.0.4" + +is-arguments@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/is-arguments/-/is-arguments-1.1.1.tgz#15b3f88fda01f2a97fec84ca761a560f123efa9b" + integrity sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA== + dependencies: + call-bind "^1.0.2" + has-tostringtag "^1.0.0" + is-array-buffer@^3.0.1, is-array-buffer@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/is-array-buffer/-/is-array-buffer-3.0.2.tgz#f2653ced8412081638ecb0ebbd0c41c6e0aecbbe" @@ -3147,6 +3377,13 @@ is-date-object@^1.0.1: resolved "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz" integrity sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g== +is-date-object@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.0.5.tgz#0841d5536e724c25597bf6ea62e1bd38298df31f" + integrity sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ== + dependencies: + has-tostringtag "^1.0.0" + is-extglob@^2.1.1: version "2.1.1" resolved "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz" @@ -3174,6 +3411,11 @@ is-glob@^4.0.0, is-glob@^4.0.1, is-glob@^4.0.3: dependencies: is-extglob "^2.1.1" +is-map@^2.0.2, is-map@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/is-map/-/is-map-2.0.3.tgz#ede96b7fe1e270b3c4465e3a465658764926d62e" + integrity sha512-1Qed0/Hr2m+YqxnM09CjA2d/i6YZNfF6R2oRAOj36eUdS6qIV/huPJNSEpKbupewFs+ZsJlxsjjPbc0/afW6Lw== + is-negative-zero@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.2.tgz#7bf6f03a28003b8b3965de3ac26f664d765f3150" @@ -3214,6 +3456,11 @@ is-regex@^1.1.4: call-bind "^1.0.2" has-tostringtag "^1.0.0" +is-set@^2.0.2, is-set@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/is-set/-/is-set-2.0.3.tgz#8ab209ea424608141372ded6e0cb200ef1d9d01d" + integrity sha512-iPAjerrse27/ygGLxw+EBR9agv9Y6uLeYVJMu+QNCoouJ1/1ri0mGrcWpfCqFZuzzx3WjtwxG098X+n4OuRkPg== + is-shared-array-buffer@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/is-shared-array-buffer/-/is-shared-array-buffer-1.0.2.tgz#8f259c573b60b6a32d4058a1a07430c0a7344c79" @@ -3268,6 +3515,11 @@ is-typed-array@^1.1.10, is-typed-array@^1.1.9: gopd "^1.0.1" has-tostringtag "^1.0.0" +is-weakmap@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/is-weakmap/-/is-weakmap-2.0.2.tgz#bf72615d649dfe5f699079c54b83e47d1ae19cfd" + integrity sha512-K5pXYOm9wqY1RgjpL3YTkF39tni1XajUIkawTLUo9EZEVUFga5gSQJF8nNS7ZwJQ02y+1YCNYcMh+HIf1ZqE+w== + is-weakref@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/is-weakref/-/is-weakref-1.0.2.tgz#9529f383a9338205e89765e0392efc2f100f06f2" @@ -3275,6 +3527,19 @@ is-weakref@^1.0.2: dependencies: call-bind "^1.0.2" +is-weakset@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/is-weakset/-/is-weakset-2.0.3.tgz#e801519df8c0c43e12ff2834eead84ec9e624007" + integrity sha512-LvIm3/KWzS9oRFHugab7d+M/GcBXuXX5xZkzPmN+NxihdQlZUQ4dWuSV1xR/sq6upL1TJEDrfBgRepHFdBtSNQ== + dependencies: + call-bind "^1.0.7" + get-intrinsic "^1.2.4" + +isarray@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.5.tgz#8af1e4c1221244cc62459faf38940d4e644a5723" + integrity sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw== + isexe@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz" @@ -3906,6 +4171,11 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" +lz-string@^1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.5.0.tgz#c1ab50f77887b712621201ba9fd4e3a6ed099941" + integrity sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ== + make-dir@^3.0.0: version "3.1.0" resolved "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz" @@ -4077,6 +4347,14 @@ object-is@^1.0.2, object-is@^1.1.2: define-properties "^1.1.3" es-abstract "^1.17.5" +object-is@^1.1.5: + version "1.1.6" + resolved "https://registry.yarnpkg.com/object-is/-/object-is-1.1.6.tgz#1a6a53aed2dd8f7e6775ff870bea58545956ab07" + integrity sha512-F8cZ+KfGlSGi09lJT7/Nd6KJZ9ygtvYC0/UYYLI9nmQKLMnydpB9yvbv9K1uSkEu7FU9vYPmVwLg328tX+ot3Q== + dependencies: + call-bind "^1.0.7" + define-properties "^1.2.1" + object-keys@^1.0.11, object-keys@^1.0.12, object-keys@^1.1.1: version "1.1.1" resolved "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz" @@ -4339,6 +4617,11 @@ pkg-dir@^4.2.0: dependencies: find-up "^4.0.0" +possible-typed-array-names@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz#89bb63c6fada2c3e90adc4a647beeeb39cc7bf8f" + integrity sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q== + prelude-ls@^1.2.1: version "1.2.1" resolved "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz" @@ -4386,6 +4669,15 @@ pretty-format@^23.0.1: ansi-regex "^3.0.0" ansi-styles "^3.2.0" +pretty-format@^27.0.2: + version "27.5.1" + resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.5.1.tgz#2181879fdea51a7a5851fb39d920faa63f01d88e" + integrity sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ== + dependencies: + ansi-regex "^5.0.1" + ansi-styles "^5.0.0" + react-is "^17.0.1" + pretty-format@^29.0.0, pretty-format@^29.0.3: version "29.0.3" resolved "https://registry.npmjs.org/pretty-format/-/pretty-format-29.0.3.tgz" @@ -4523,6 +4815,11 @@ react-is@^16.13.1, react-is@^16.8.1, react-is@^16.8.6: resolved "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz" integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== +react-is@^17.0.1: + version "17.0.2" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" + integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== + react-is@^18.0.0: version "18.2.0" resolved "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz" @@ -4587,6 +4884,16 @@ regexp.prototype.flags@^1.4.3: define-properties "^1.2.0" functions-have-names "^1.2.3" +regexp.prototype.flags@^1.5.1: + version "1.5.2" + resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz#138f644a3350f981a858c44f6bb1a61ff59be334" + integrity sha512-NcDiDkTLuPR+++OCKB0nWafEmhg/Da8aUPLPMQbK+bxKKCm1/S5he+AqYa4PlMCVBalb4/yxIRub6qkEx5yJbw== + dependencies: + call-bind "^1.0.6" + define-properties "^1.2.1" + es-errors "^1.3.0" + set-function-name "^2.0.1" + require-directory@^2.1.1: version "2.1.1" resolved "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz" @@ -4762,6 +5069,28 @@ set-blocking@^2.0.0: resolved "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz" integrity sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw== +set-function-length@^1.2.1: + version "1.2.2" + resolved "https://registry.yarnpkg.com/set-function-length/-/set-function-length-1.2.2.tgz#aac72314198eaed975cf77b2c3b6b880695e5449" + integrity sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg== + dependencies: + define-data-property "^1.1.4" + es-errors "^1.3.0" + function-bind "^1.1.2" + get-intrinsic "^1.2.4" + gopd "^1.0.1" + has-property-descriptors "^1.0.2" + +set-function-name@^2.0.1: + version "2.0.2" + resolved "https://registry.yarnpkg.com/set-function-name/-/set-function-name-2.0.2.tgz#16a705c5a0dc2f5e638ca96d8a8cd4e1c2b90985" + integrity sha512-7PGFlmtwsEADb0WYyvCMa1t+yke6daIG4Wirafur5kcf+MhUnPms1UeR0CKQdTZD81yESwMHbtn+TR+dMviakQ== + dependencies: + define-data-property "^1.1.4" + es-errors "^1.3.0" + functions-have-names "^1.2.3" + has-property-descriptors "^1.0.2" + shebang-command@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz" @@ -4828,6 +5157,13 @@ stack-utils@^2.0.3: dependencies: escape-string-regexp "^2.0.0" +stop-iteration-iterator@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/stop-iteration-iterator/-/stop-iteration-iterator-1.0.0.tgz#6a60be0b4ee757d1ed5254858ec66b10c49285e4" + integrity sha512-iCGQj+0l0HOdZ2AEeBADlsRC+vsnDsZsbdSiH1yNSjcfKM7fdpCMfqAL/dwF5BLiw/XhRft/Wax6zQbhq2BcjQ== + dependencies: + internal-slot "^1.0.4" + strict-uri-encode@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz" @@ -5314,11 +5650,32 @@ which-boxed-primitive@^1.0.2: is-string "^1.0.5" is-symbol "^1.0.3" +which-collection@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/which-collection/-/which-collection-1.0.2.tgz#627ef76243920a107e7ce8e96191debe4b16c2a0" + integrity sha512-K4jVyjnBdgvc86Y6BkaLZEN933SwYOuBFkdmBu9ZfkcAbdVbpITnDmjvZ/aQjRXQrv5EPkTnD1s39GiiqbngCw== + dependencies: + is-map "^2.0.3" + is-set "^2.0.3" + is-weakmap "^2.0.2" + is-weakset "^2.0.3" + which-module@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz" integrity sha512-B+enWhmw6cjfVC7kS8Pj9pCrKSc5txArRyaYGe088shv/FGWH+0Rjx/xPgtsWfsUtS27FkP697E4DDhgrgoc0Q== +which-typed-array@^1.1.13: + version "1.1.15" + resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.15.tgz#264859e9b11a649b388bfaaf4f767df1f779b38d" + integrity sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA== + dependencies: + available-typed-arrays "^1.0.7" + call-bind "^1.0.7" + for-each "^0.3.3" + gopd "^1.0.1" + has-tostringtag "^1.0.2" + which-typed-array@^1.1.9: version "1.1.10" resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.10.tgz#74baa2789991905c2076abb317103b866c64e69e" From cf37f49ee2ac8c6f99b3adc3278dfb6c7637bae8 Mon Sep 17 00:00:00 2001 From: Chris Chudzicki Date: Wed, 27 Mar 2024 11:00:00 -0400 Subject: [PATCH 2/4] automatically include zero-count active facets --- src/facet_display/FacetDisplay.test.tsx | 44 ++++++++++++++++++++++++- src/facet_display/FacetDisplay.tsx | 42 +++++++++++++++++++++-- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/src/facet_display/FacetDisplay.test.tsx b/src/facet_display/FacetDisplay.test.tsx index c9de094..81a3290 100644 --- a/src/facet_display/FacetDisplay.test.tsx +++ b/src/facet_display/FacetDisplay.test.tsx @@ -61,7 +61,20 @@ describe("FacetDisplay component", () => { onFacetChange, clearAllFilters } - return { view, spies } + const rerender = (newProps: Partial) => { + view.rerender( + + ) + } + return { view, spies, rerender } } test("Renders facets with expected titles", async () => { @@ -156,4 +169,33 @@ describe("FacetDisplay component", () => { name: "Mechanical Engineering" }) }) + + test("Automically includes a zero-count option for active facets with no matches", () => { + const activeFacets: Facets = { + topic: ["Cats"] + } + const { rerender } = setup({ + props: { + activeFacets, + facetMap: [ + { + ...defaultFacetMap[0], + expandedOnLoad: true + } + ] + } + }) + const checkboxCount = () => screen.getAllByRole("checkbox").length + expect(checkboxCount()).toBe(3) + screen.getByRole("checkbox", { name: "Cats" }) + screen.getByRole("checkbox", { name: "Dogs" }) + screen.getByRole("checkbox", { name: "Monkeys" }) + rerender({ + activeFacets: { + topic: ["Cats", "Dragons"] + } + }) + expect(checkboxCount()).toBe(4) + screen.getByRole("checkbox", { name: "Dragons" }) + }) }) diff --git a/src/facet_display/FacetDisplay.tsx b/src/facet_display/FacetDisplay.tsx index e0a332e..a5f20e0 100644 --- a/src/facet_display/FacetDisplay.tsx +++ b/src/facet_display/FacetDisplay.tsx @@ -1,4 +1,4 @@ -import React from "react" +import React, { useCallback } from "react" import FilterableFacet from "./FilterableFacet" import Facet from "./Facet" import SearchFilter from "./SearchFilter" @@ -9,6 +9,12 @@ export type BucketWithLabel = Bucket & { label: string } interface FacetDisplayProps { facetMap: FacetManifest + /** + * Returns the aggregation options for a given group. + * + * If `activeFacets` includes a facet with no results, that facet will + * automatically be included in the facet options. + */ facetOptions: (group: string) => Aggregation | null activeFacets: Facets clearAllFilters: () => void @@ -47,12 +53,42 @@ const resultsWithLabels = ( return newResults } +/** + * Augment the facet buckets for `groupKey` with active values that have no + * results. + */ +const includeActiveZerosInBuckets = ( + groupKey: string, + buckets: Bucket[], + params: Facets +) => { + const opts = [...buckets] + const active = params[groupKey as keyof Facets] ?? [] + const actives = Array.isArray(active) ? active : [active] + actives.forEach(key => { + if (!opts.find(o => o.key === key)) { + opts.push({ key: String(key), doc_count: 0 }) + } + }) + return opts +} + const AvailableFacets: React.FC> = ({ facetMap, facetOptions, activeFacets, onFacetChange }) => { + const allFacetOptions: FacetDisplayProps["facetOptions"] = useCallback( + name => { + return includeActiveZerosInBuckets( + name, + facetOptions(name) ?? [], + activeFacets + ) + }, + [facetOptions, activeFacets] + ) return ( <> {facetMap.map(facetSetting => @@ -60,7 +96,7 @@ const AvailableFacets: React.FC> = ({ > = ({ title={facetSetting.title} name={facetSetting.name} results={resultsWithLabels( - facetOptions(facetSetting.name) || [], + allFacetOptions(facetSetting.name) || [], facetSetting.labelFunction )} onUpdate={e => From a70a9ec60740502e7fe6a22d495766e7f3bd227a Mon Sep 17 00:00:00 2001 From: Chris Chudzicki Date: Wed, 27 Mar 2024 11:12:28 -0400 Subject: [PATCH 3/4] remove commented out import --- src/facet_display/FacetDisplay.test.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/facet_display/FacetDisplay.test.tsx b/src/facet_display/FacetDisplay.test.tsx index 81a3290..602fe75 100644 --- a/src/facet_display/FacetDisplay.test.tsx +++ b/src/facet_display/FacetDisplay.test.tsx @@ -1,5 +1,4 @@ import React from "react" -// import { shallow } from "enzyme"; import { render, screen, within } from "@testing-library/react" import user from "@testing-library/user-event" From 129f141b2504996b9a7ddd73267c5bf9505675f0 Mon Sep 17 00:00:00 2001 From: Chris Chudzicki Date: Wed, 27 Mar 2024 11:27:35 -0400 Subject: [PATCH 4/4] remove a console.log --- src/facet_display/FilterableFacet.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/facet_display/FilterableFacet.tsx b/src/facet_display/FilterableFacet.tsx index 9546de4..8125c9e 100644 --- a/src/facet_display/FilterableFacet.tsx +++ b/src/facet_display/FilterableFacet.tsx @@ -21,7 +21,6 @@ interface Props { } function FilterableFacet(props: Props) { - console.log("hello from filterable facet") const { name, title, results, selected, onUpdate, expandedOnLoad } = props const [showFacetList, setShowFacetList] = useState(expandedOnLoad)