Skip to content

Commit

Permalink
[OUR415-314] Fixes eligibility and category lists in Browse Experience (
Browse files Browse the repository at this point in the history
  • Loading branch information
rosschapman authored Nov 6, 2024
1 parent 9aee08b commit 0a8b118
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 33 deletions.
23 changes: 5 additions & 18 deletions app/components/search/Refinements/BrowseRefinementList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,17 @@ import { InstantSearch } from "react-instantsearch-core";
import { render, screen, waitFor } from "@testing-library/react";
import BrowseRefinementList from "components/search/Refinements/BrowseRefinementList";
import { createSearchClient } from "../../../../test/helpers/createSearchClient";
import { createRandomCategories } from "../../../../test/helpers/createRandomCategories";

describe("BrowseRefinementList", () => {
test("renders the default limit of 10 refinements", async () => {
test("renders all categories returned by the search client", async () => {
const numCategories = 25;
const searchClient = createSearchClient({
facets: {
categories: {
A: 54,
B: 35,
C: 28,
D: 24,
E: 18,
F: 14,
G: 14,
H: 12,
I: 45,
J: 79,
K: 1,
L: 31,
},
categories: createRandomCategories(numCategories),
},
});

const expected = 10;

render(
<InstantSearch
searchClient={searchClient}
Expand All @@ -38,7 +25,7 @@ describe("BrowseRefinementList", () => {

await waitFor(() => {
expect(screen.getAllByTestId("browserefinementlist-item")).toHaveLength(
expected
numCategories
);
});
});
Expand Down
4 changes: 4 additions & 0 deletions app/components/search/Refinements/BrowseRefinementList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ interface Props extends UseRefinementListProps {
attribute: string;
}

// Arbitrary upper limit to ensure all refinements are displayed
const MAXIMUM_ITEMS = 9999;

/**
* Facet refinement list component for browse interfaces
*/
Expand All @@ -16,6 +19,7 @@ const BrowseRefinementList = ({ attribute, transform }: Props) => {
attribute,
sortBy: ["name:asc"],
transformItems: transform,
limit: MAXIMUM_ITEMS,
});

useEffect(() => {
Expand Down
3 changes: 2 additions & 1 deletion app/components/search/Refinements/SearchRefinementList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ interface Props extends UseRefinementListProps {
}

const DEFAULT_CONFIG = {
limit: 100,
// Arbitrary upper limit to ensure all refinements are displayed
limit: 9999,
operator: "or" as const,
};

Expand Down
3 changes: 2 additions & 1 deletion app/components/search/Sidebar/Sidebar.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
align-self: flex-start;
border-right: 0;
background-color: #fff;
z-index: $z-index-filters-menu;
}

@media screen and (max-width: $break-tablet-s) {
Expand Down Expand Up @@ -67,7 +68,7 @@

@media screen and (max-width: $break-tablet-s) {
width: 100%;
top: 65px;
top: 131px;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
animation-name: slideUp;
Expand Down
24 changes: 11 additions & 13 deletions app/components/ui/Navigation/DropdownMenu.module.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
@import "../../../styles/utils/_helpers.scss";
@import "../../../styles/utils/_colors.scss";

.navigationMenuContainer {
// Important to override react-burger-menu lib styles
display: flex !important;
flex-direction: column;
align-items: center;

> * {
font-size: 18px;
font-family: Montserrat;
}
.navigationMenuContainer > * {
font-size: 18px;
font-family: Montserrat;
}

.navigationSubMenu {
Expand All @@ -22,6 +15,11 @@
border-radius: $rounded-md;
overflow: hidden;
font-weight: 400;
width: max-content;

@media screen and (max-width: $break-tablet-s) {
top: 46px;
}
}

.navigationMenuHeader {
Expand Down Expand Up @@ -92,11 +90,11 @@

.categoryMenuContainer {
position: relative;
min-width: 160px;

.navigationSubMenu {
top: 50px;
left: 0;
@include r_max($break-tablet-s) {
width: calc(100vw - $general-spacing-xs);
}
}

.navigationMenuHeader {
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@babel/preset-typescript": "^7.24.7",
"@babel/register": "^7.4.4",
"@eslint/js": "^9.10.0",
"@faker-js/faker": "^9.2.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react": "^16.0.1",
Expand Down
20 changes: 20 additions & 0 deletions test/helpers/createRandomCategories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { faker } from "@faker-js/faker";

/**
* Generates an object of categories for use in search refinement components
*
* @param size Customize the number of categories
*/
export function createRandomCategories(size: number) {
const result: { [key: string]: number } = {};

for (let i = 0; i < size; i++) {
// Append incrementor because the current version of faker does not support
// uniqueness
const key = `${faker.company.name()}_${i}`;
const value = faker.number.int(100);
result[key] = value;
}

return result;
}

0 comments on commit 0a8b118

Please sign in to comment.