From 64cf7268508bbcb84fa2d80cc480eab28e9eb939 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Thu, 2 Nov 2023 17:11:33 -0400 Subject: [PATCH] add comments from PR --- .../fixtures}/testAggregations.js | 2 +- pages/search/advanced.tsx | 4 ++-- src/components/ItemFilters/ItemFilter.tsx | 17 +++++++---------- src/components/ItemFilters/ItemFilters.test.tsx | 5 +++++ src/components/ItemFilters/utils.ts | 8 ++++---- src/models/itemFilterData.ts | 10 +++++----- src/types/filterTypes.ts | 6 +++--- 7 files changed, 27 insertions(+), 25 deletions(-) rename {src/components/ItemFilters => __test__/fixtures}/testAggregations.js (98%) diff --git a/src/components/ItemFilters/testAggregations.js b/__test__/fixtures/testAggregations.js similarity index 98% rename from src/components/ItemFilters/testAggregations.js rename to __test__/fixtures/testAggregations.js index 6f988b473..7051400c7 100644 --- a/src/components/ItemFilters/testAggregations.js +++ b/__test__/fixtures/testAggregations.js @@ -80,4 +80,4 @@ const aggs = [ }, ] -export default aggs \ No newline at end of file +export default aggs diff --git a/pages/search/advanced.tsx b/pages/search/advanced.tsx index be2385800..a0b396999 100644 --- a/pages/search/advanced.tsx +++ b/pages/search/advanced.tsx @@ -39,7 +39,7 @@ import type { import { getQueryString } from "../../src/utils/searchUtils" import ItemFilterContainer from "../../src/components/ItemFilters/FiltersContainer" -import testItemAggs from "../../src/components/ItemFilters/testAggregations" +import testItemAggs from "../../__test__/fixtures/testAggregations" /** * The Advanced Search page is responsible for displaying the Advanced Search form fields and @@ -125,7 +125,7 @@ export default function AdvancedSearch() { } /> )} - + Advanced Search
> - selectedFilters: selectedFiltersType + setSelectedFilters: Dispatch> + selectedFilters: SelectedFilters // this type is temporary for dev use only. could end up being different. - submitFilters: Dispatch> + submitFilters: Dispatch> } const ItemFilter = ({ @@ -28,13 +25,13 @@ const ItemFilter = ({ const field = itemFilterData.field() const fieldFormatted = itemFilterData.field(true) const clearFilter = () => { - setSelectedFilters((prevFilters: selectedFiltersType) => { + setSelectedFilters((prevFilters: SelectedFilters) => { return { ...prevFilters, [field]: [] } }) } const handleCheck = (selectedOptions: string[]) => { - setSelectedFilters((prevFilters: selectedFiltersType) => { + setSelectedFilters((prevFilters: SelectedFilters) => { const newFilterSelection = { ...prevFilters, [field]: selectedOptions, @@ -57,7 +54,7 @@ const ItemFilter = ({ // the CheckboxGroup value array are selected. value={selectedFilters[field]} > - {itemFilterData.displayOptions().map(({ value, label }: optionType) => { + {itemFilterData.displayOptions().map(({ value, label }: Option) => { return ( ) diff --git a/src/components/ItemFilters/ItemFilters.test.tsx b/src/components/ItemFilters/ItemFilters.test.tsx index 5021b8927..b1ca741cf 100644 --- a/src/components/ItemFilters/ItemFilters.test.tsx +++ b/src/components/ItemFilters/ItemFilters.test.tsx @@ -9,6 +9,11 @@ import userEvent from "@testing-library/user-event" jest.mock("next/router", () => jest.requireActual("next-router-mock")) describe("Filters container", () => { + it("renders a single filter", () => { + render() + const filters = screen.getAllByTestId("item-filter") + expect(filters.length).toBe(1) + }) it("renders three filter boxes", () => { render() const filters = screen.getAllByTestId("item-filter") diff --git a/src/components/ItemFilters/utils.ts b/src/components/ItemFilters/utils.ts index 1ac15c538..3aae9225c 100644 --- a/src/components/ItemFilters/utils.ts +++ b/src/components/ItemFilters/utils.ts @@ -1,4 +1,4 @@ -import type { selectedFilters as selectedFiltersType } from "../../types/filterTypes" +import type { SelectedFilters } from "../../types/filterTypes" const isRecapLocation = (loc: string) => { return loc.split(":")[1].startsWith("rc") @@ -11,7 +11,7 @@ export const combineRecapLocations = (locations: string[]) => { } else return locations } -type bibPageQueryParams = { +type BibPageQueryParams = { item_location?: string item_format?: string item_status?: string @@ -21,7 +21,7 @@ export const parseQueryParams = ({ item_status, item_format, item_location, -}: bibPageQueryParams) => { +}: BibPageQueryParams) => { return { location: item_location ? combineRecapLocations(item_location.split(",")) @@ -32,7 +32,7 @@ export const parseQueryParams = ({ } export const buildQueryParams = ( - { location, format, status }: selectedFiltersType, + { location, format, status }: SelectedFilters, recapLocations: string[] ) => { const locs = location.map((loc) => { diff --git a/src/models/itemFilterData.ts b/src/models/itemFilterData.ts index c85752dc7..dd7106989 100644 --- a/src/models/itemFilterData.ts +++ b/src/models/itemFilterData.ts @@ -1,23 +1,23 @@ import type { ItemAggregation, ItemAggregationOption, - option as optionType, + Option, } from "../types/filterTypes" export class ItemFilterData { options: ItemAggregationOption[] - _field: string + agg: ItemAggregation constructor(agg: ItemAggregation) { - this._field = agg.field + this.agg = agg this.options = agg.values } - displayOptions(): optionType[] { + displayOptions(): Option[] { return this.options } field(formatted = false) { - const f = this._field + const f = this.agg.field const upperCased = f[0].toUpperCase() + f.substring(1) return formatted ? upperCased : f } diff --git a/src/types/filterTypes.ts b/src/types/filterTypes.ts index a3994257a..2773f8bec 100644 --- a/src/types/filterTypes.ts +++ b/src/types/filterTypes.ts @@ -1,6 +1,6 @@ -export type locations = string[] +export type Locations = string[] -export type selectedFilters = { +export type SelectedFilters = { location: string[] format: string[] status: string[] @@ -21,7 +21,7 @@ export interface ItemAggregation { values: ItemAggregationOption[] } -export type option = { value: string; label: string } +export type Option = { value: string; label: string } export type ReducedItemAggregation = { field: string