Repository navigation
Expand file tree
/
Copy pathGlobalSearchInputOverlay.tests.tsx
More file actions
113 lines (83 loc) · 3.63 KB
/
Copy pathGlobalSearchInputOverlay.tests.tsx
File metadata and controls
113 lines (83 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { OwnerType } from "@artsy/cohesion"
import { PortalHost } from "@gorhom/portal"
import { fireEvent, screen } from "@testing-library/react-native"
import { GlobalSearchInputOverlay } from "app/Components/GlobalSearchInput/GlobalSearchInputOverlay"
import { useExperimentFlag } from "app/system/flags/hooks/useExperimentFlag"
import { navigate } from "app/system/navigation/navigate"
import { renderWithWrappers } from "app/utils/tests/renderWithWrappers"
jest.mock("app/system/flags/hooks/useExperimentFlag", () => ({
useExperimentFlag: jest.fn(),
}))
jest.mock("app/utils/hooks/useSelectedTab", () => ({
useSelectedTab: jest.fn().mockReturnValue("home"),
}))
jest.mock("app/system/navigation/navigate", () => ({
navigate: jest.fn(),
}))
const renderOverlay = (props: { hideModal?: () => void } = {}) =>
renderWithWrappers(
<>
<PortalHost name={`${OwnerType.home}-SearchOverlay`} />
<GlobalSearchInputOverlay
ownerType={OwnerType.home}
visible
hideModal={props.hideModal ?? jest.fn()}
/>
</>,
{ includeNavigation: true }
)
describe("GlobalSearchInputOverlay — Search by Photo entry point", () => {
const mockUseExperimentFlag = useExperimentFlag as jest.Mock
beforeEach(() => {
jest.clearAllMocks()
})
it("renders the Search by Photo button when onyx_artsy-lens is on", () => {
mockUseExperimentFlag.mockImplementation((key) => key === "onyx_artsy-lens")
renderOverlay()
expect(screen.getByTestId("search-by-photo-button")).toBeOnTheScreen()
})
it("hides the Search by Photo button when onyx_artsy-lens is off", () => {
mockUseExperimentFlag.mockReturnValue(false)
renderOverlay()
expect(screen.queryByTestId("search-by-photo-button")).not.toBeOnTheScreen()
})
it("dismisses the overlay and navigates to /lens on press", () => {
mockUseExperimentFlag.mockImplementation((key) => key === "onyx_artsy-lens")
const hideModal = jest.fn()
renderOverlay({ hideModal })
fireEvent.press(screen.getByTestId("search-by-photo-button"))
expect(hideModal).toHaveBeenCalledTimes(1)
expect(navigate).toHaveBeenCalledWith("/lens")
})
describe("the camera icon inside the input", () => {
it("carries the icon over from the collapsed search bar", () => {
mockUseExperimentFlag.mockImplementation((key) => key === "onyx_artsy-lens")
renderOverlay()
expect(screen.getByTestId("search-overlay-camera-icon")).toBeOnTheScreen()
})
it("hides the icon when onyx_artsy-lens is off", () => {
mockUseExperimentFlag.mockReturnValue(false)
renderOverlay()
expect(screen.queryByTestId("search-overlay-camera-icon")).not.toBeOnTheScreen()
})
// iOS draws its own clear button in this exact spot once there's text.
it("yields the slot once there is a query for the clear button to clear", () => {
mockUseExperimentFlag.mockImplementation((key) => key === "onyx_artsy-lens")
renderOverlay()
fireEvent.changeText(
screen.getByLabelText("Search artists, artworks, galleries etc."),
"banksy"
)
expect(screen.queryByTestId("search-overlay-camera-icon")).not.toBeOnTheScreen()
expect(screen.getByTestId("search-by-photo-button")).toBeOnTheScreen()
})
it("dismisses the overlay and navigates to /lens on press", () => {
mockUseExperimentFlag.mockImplementation((key) => key === "onyx_artsy-lens")
const hideModal = jest.fn()
renderOverlay({ hideModal })
fireEvent.press(screen.getByTestId("search-overlay-camera-icon"))
expect(hideModal).toHaveBeenCalledTimes(1)
expect(navigate).toHaveBeenCalledWith("/lens")
})
})
})