-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76dd082
commit 9c67567
Showing
5 changed files
with
166 additions
and
1 deletion.
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
78 changes: 78 additions & 0 deletions
78
src/app/Scenes/SavedSearchAlert/Components/SavedSearchFilterColour.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,78 @@ | ||
import { OwnerType } from "@artsy/cohesion" | ||
import { fireEvent, waitFor } from "@testing-library/react-native" | ||
import { | ||
COLORS_INDEXED_BY_VALUE, | ||
COLORS_OPTIONS, | ||
} from "app/Components/ArtworkFilter/Filters/ColorsOptions" | ||
import { SavedSearchFilterColour } from "app/Scenes/SavedSearchAlert/Components/SavedSearchFilterColour" | ||
import { | ||
SavedSearchModel, | ||
SavedSearchStoreProvider, | ||
savedSearchModel, | ||
} from "app/Scenes/SavedSearchAlert/SavedSearchStore" | ||
import { renderWithWrappers } from "app/utils/tests/renderWithWrappers" | ||
|
||
describe("SavedSearchFilterColour", () => { | ||
it("shows all available color options unselected", () => { | ||
const { getByTestId } = renderWithWrappers( | ||
<SavedSearchStoreProvider runtimeModel={initialData}> | ||
<SavedSearchFilterColour /> | ||
</SavedSearchStoreProvider> | ||
) | ||
|
||
COLORS_OPTIONS.forEach((option) => { | ||
expect(() => | ||
getByTestId(`check-icon-${COLORS_INDEXED_BY_VALUE[option.paramValue as string].name}`) | ||
).toThrow() | ||
}) | ||
}) | ||
|
||
it("shows the right selected state", () => { | ||
const { getByTestId } = renderWithWrappers( | ||
<SavedSearchStoreProvider runtimeModel={{ ...initialData, attributes: { colors: ["red"] } }}> | ||
<SavedSearchFilterColour /> | ||
</SavedSearchStoreProvider> | ||
) | ||
|
||
COLORS_OPTIONS.forEach((option) => { | ||
if (option.paramValue !== "red") { | ||
expect(() => | ||
getByTestId(`check-icon-${COLORS_INDEXED_BY_VALUE[option.paramValue as string].name}`) | ||
).toThrow() | ||
} else { | ||
expect( | ||
getByTestId(`check-icon-${COLORS_INDEXED_BY_VALUE[option.paramValue as string].name}`) | ||
).toBeDefined() | ||
} | ||
}) | ||
}) | ||
|
||
it("Updates selected filters on press", () => { | ||
const { getByTestId, getByText } = renderWithWrappers( | ||
<SavedSearchStoreProvider runtimeModel={initialData}> | ||
<SavedSearchFilterColour /> | ||
</SavedSearchStoreProvider> | ||
) | ||
|
||
fireEvent(getByText("Red"), "onPress") | ||
|
||
waitFor(() => { | ||
expect(getByTestId("check-icon-Red")).toBeDefined() | ||
}) | ||
}) | ||
}) | ||
|
||
const initialData: SavedSearchModel = { | ||
...savedSearchModel, | ||
attributes: { | ||
atAuction: true, | ||
}, | ||
entity: { | ||
artists: [{ id: "artistID", name: "Banksy" }], | ||
owner: { | ||
type: OwnerType.artist, | ||
id: "ownerId", | ||
slug: "ownerSlug", | ||
}, | ||
}, | ||
} |
75 changes: 75 additions & 0 deletions
75
src/app/Scenes/SavedSearchAlert/Components/SavedSearchFilterColour.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,75 @@ | ||
import { Flex, Spacer, Text, useScreenDimensions, useSpace } from "@artsy/palette-mobile" | ||
import { | ||
COLORS_INDEXED_BY_VALUE, | ||
COLORS_OPTIONS, | ||
SWATCHES_PER_ROW, | ||
} from "app/Components/ArtworkFilter/Filters/ColorsOptions" | ||
import { ColorsSwatch } from "app/Components/ArtworkFilter/Filters/ColorsSwatch" | ||
import { SearchCriteria } from "app/Components/ArtworkFilter/SavedSearch/types" | ||
import { SavedSearchStore } from "app/Scenes/SavedSearchAlert/SavedSearchStore" | ||
import { isValueSelected, useSearchCriteriaAttributes } from "app/Scenes/SavedSearchAlert/helpers" | ||
|
||
export const SavedSearchFilterColour = () => { | ||
const selectedAttributes = useSearchCriteriaAttributes(SearchCriteria.colors) as string[] | ||
|
||
const { width } = useScreenDimensions() | ||
const space = useSpace() | ||
|
||
const setValueToAttributesByKeyAction = SavedSearchStore.useStoreActions( | ||
(actions) => actions.setValueToAttributesByKeyAction | ||
) | ||
const removeValueFromAttributesByKeyAction = SavedSearchStore.useStoreActions( | ||
(actions) => actions.removeValueFromAttributesByKeyAction | ||
) | ||
|
||
const handlePress = (value: string) => { | ||
const isSelected = isValueSelected({ | ||
selectedAttributes, | ||
value: value, | ||
}) | ||
|
||
if (isSelected) { | ||
removeValueFromAttributesByKeyAction({ | ||
key: SearchCriteria.colors, | ||
value: value, | ||
}) | ||
} else { | ||
const newValues = (selectedAttributes || []).concat(value) | ||
setValueToAttributesByKeyAction({ | ||
key: SearchCriteria.colors, | ||
value: newValues, | ||
}) | ||
} | ||
} | ||
|
||
return ( | ||
<Flex> | ||
<Text px={2} variant="sm" fontWeight={500}> | ||
Colour | ||
</Text> | ||
<Spacer y={1} /> | ||
<Flex flexDirection="row" flexWrap="wrap" px={1}> | ||
{COLORS_OPTIONS.map((option, i) => { | ||
const color = COLORS_INDEXED_BY_VALUE[String(option.paramValue)] | ||
|
||
return ( | ||
<ColorsSwatch | ||
key={i} | ||
width={(width - space(1) * 2) / SWATCHES_PER_ROW} | ||
selected={isValueSelected({ | ||
selectedAttributes, | ||
value: option.paramValue, | ||
})} | ||
name={color.name} | ||
backgroundColor={color.backgroundColor} | ||
foregroundColor={color.foregroundColor} | ||
onPress={() => { | ||
handlePress(option.paramValue as string) | ||
}} | ||
/> | ||
) | ||
})} | ||
</Flex> | ||
</Flex> | ||
) | ||
} |
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