-
Notifications
You must be signed in to change notification settings - Fork 581
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Availability filter to artwork filters (#11100)
* feat: Add artworks availability filter * add filter
- Loading branch information
1 parent
b41ba9f
commit 5510c64
Showing
7 changed files
with
210 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/app/Components/ArtworkFilter/Filters/AvailabilityOptions.tests.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { fireEvent } from "@testing-library/react-native" | ||
import { FilterParamName } from "app/Components/ArtworkFilter/ArtworkFilterHelpers" | ||
import { | ||
ArtworkFiltersState, | ||
ArtworkFiltersStoreProvider, | ||
getArtworkFiltersModel, | ||
} from "app/Components/ArtworkFilter/ArtworkFilterStore" | ||
import { MockFilterScreen } from "app/Components/ArtworkFilter/FilterTestHelper" | ||
import { AvailabilityOptionsScreen } from "app/Components/ArtworkFilter/Filters/AvailabilityOptions.tsx" | ||
import { __globalStoreTestUtils__ } from "app/store/GlobalStore" | ||
import { renderWithWrappers } from "app/utils/tests/renderWithWrappers" | ||
import { getEssentialProps } from "./helper" | ||
|
||
describe(AvailabilityOptionsScreen, () => { | ||
beforeEach(() => { | ||
__globalStoreTestUtils__?.injectFeatureFlags({ AREnableAvailabilityFilter: true }) | ||
}) | ||
|
||
const initialState: ArtworkFiltersState = { | ||
aggregations: [], | ||
appliedFilters: [], | ||
applyFilters: false, | ||
counts: { | ||
total: null, | ||
followedArtists: null, | ||
}, | ||
showFilterArtworksModal: false, | ||
sizeMetric: "cm", | ||
filterType: "artwork", | ||
previouslyAppliedFilters: [], | ||
selectedFilters: [], | ||
} | ||
|
||
const MockAvailabilityOptionsScreen = ({ | ||
initialData = initialState, | ||
}: { | ||
initialData?: ArtworkFiltersState | ||
}) => { | ||
return ( | ||
<ArtworkFiltersStoreProvider | ||
runtimeModel={{ | ||
...getArtworkFiltersModel(), | ||
...initialData, | ||
}} | ||
> | ||
<AvailabilityOptionsScreen {...getEssentialProps()} /> | ||
</ArtworkFiltersStoreProvider> | ||
) | ||
} | ||
|
||
describe("no filters are selected", () => { | ||
it("renders all options", () => { | ||
const { getByText } = renderWithWrappers( | ||
<MockAvailabilityOptionsScreen initialData={initialState} /> | ||
) | ||
|
||
expect(getByText("Only works for sale")).toBeTruthy() | ||
}) | ||
}) | ||
|
||
describe("a filter is selected", () => { | ||
const state: ArtworkFiltersState = { | ||
...initialState, | ||
selectedFilters: [ | ||
{ | ||
displayText: "Only works for sale", | ||
paramName: FilterParamName.forSale, | ||
paramValue: true, | ||
}, | ||
], | ||
} | ||
|
||
it("displays the number of the selected filters on the filter modal screen", () => { | ||
const { getByText } = renderWithWrappers(<MockFilterScreen initialState={state} />) | ||
|
||
expect(getByText("Availability • 1")).toBeTruthy() | ||
}) | ||
|
||
it("toggles selected filters 'ON' and unselected filters 'OFF", async () => { | ||
const { getAllByA11yState } = renderWithWrappers( | ||
<MockAvailabilityOptionsScreen initialData={state} /> | ||
) | ||
|
||
let options = getAllByA11yState({ checked: true }) | ||
|
||
expect(options).toHaveLength(1) | ||
expect(options[0]).toHaveTextContent("Only works for sale") | ||
|
||
fireEvent.press(options[0]) | ||
|
||
options = getAllByA11yState({ checked: false }) | ||
|
||
expect(options).toHaveLength(1) | ||
expect(options[0]).toHaveTextContent("Only works for sale") | ||
}) | ||
}) | ||
}) |
79 changes: 79 additions & 0 deletions
79
src/app/Components/ArtworkFilter/Filters/AvailabilityOptions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { StackScreenProps } from "@react-navigation/stack" | ||
import { | ||
FilterData, | ||
FilterDisplayName, | ||
FilterParamName, | ||
} from "app/Components/ArtworkFilter/ArtworkFilterHelpers" | ||
import { ArtworkFilterNavigationStack } from "app/Components/ArtworkFilter/ArtworkFilterNavigator" | ||
import { | ||
ArtworksFiltersStore, | ||
useSelectedOptionsDisplay, | ||
} from "app/Components/ArtworkFilter/ArtworkFilterStore" | ||
import React, { useState } from "react" | ||
import { MultiSelectOptionScreen } from "./MultiSelectOption" | ||
|
||
type AvailabilityOptionsScreenProps = StackScreenProps< | ||
ArtworkFilterNavigationStack, | ||
"AvailabilityOptionsScreen" | ||
> | ||
|
||
export const OPTIONS: FilterData[] = [ | ||
{ | ||
displayText: "Only works for sale", | ||
paramName: FilterParamName.forSale, | ||
}, | ||
] | ||
|
||
export const AvailabilityOptionsScreen: React.FC<AvailabilityOptionsScreenProps> = ({ | ||
navigation, | ||
}) => { | ||
const selectFiltersAction = ArtworksFiltersStore.useStoreActions( | ||
(state) => state.selectFiltersAction | ||
) | ||
|
||
const selectedOptions = useSelectedOptionsDisplay() | ||
const options = OPTIONS.map((option) => { | ||
const selectedOptionByParamName = selectedOptions.find( | ||
(selectedOption) => selectedOption.paramName === option.paramName | ||
) | ||
|
||
return { | ||
...option, | ||
paramValue: selectedOptionByParamName?.paramValue || undefined, | ||
} | ||
}) | ||
|
||
const [key, setKey] = useState(0) | ||
|
||
const handleSelect = (option: FilterData, updatedValue: boolean) => { | ||
selectFiltersAction({ | ||
displayText: option.displayText, | ||
paramValue: updatedValue || undefined, | ||
paramName: option.paramName, | ||
}) | ||
} | ||
|
||
const handleClear = () => { | ||
options.map((option) => { | ||
selectFiltersAction({ ...option, paramValue: undefined }) | ||
}) | ||
|
||
// Force re-render | ||
setKey((n) => n + 1) | ||
} | ||
|
||
const selected = options.filter((option) => option.paramValue) | ||
|
||
return ( | ||
<MultiSelectOptionScreen | ||
key={key} | ||
onSelect={handleSelect} | ||
filterHeaderText={FilterDisplayName.availability} | ||
filterOptions={options} | ||
navigation={navigation} | ||
{...(selected.length > 0 | ||
? { rightButtonText: "Clear", onRightButtonPress: handleClear } | ||
: {})} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters