Skip to content

Commit 016333f

Browse files
committed
chore: refactor, write tests
1 parent f6bc1e4 commit 016333f

File tree

2 files changed

+78
-12
lines changed

2 files changed

+78
-12
lines changed
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import Geolocation from "@react-native-community/geolocation"
2+
import { screen, waitForElementToBeRemoved } from "@testing-library/react-native"
3+
import { ShowsForYouScreen } from "app/Scenes/Shows/ShowsForYou"
4+
import { setupTestWrapper } from "app/utils/tests/setupTestWrapper"
5+
import mockFetch from "jest-fetch-mock"
6+
7+
jest.mock("@react-native-community/geolocation", () => ({
8+
setRNConfiguration: jest.fn(),
9+
getCurrentPosition: jest.fn((success, _) => {
10+
success({ coords: { latitude: 1, longitude: 2 } })
11+
}),
12+
}))
13+
14+
describe("ShowsForYou", () => {
15+
beforeEach(() => {
16+
jest.clearAllMocks()
17+
})
18+
19+
const { renderWithRelay } = setupTestWrapper({
20+
Component: () => <ShowsForYouScreen />,
21+
})
22+
23+
it("renders shows for you", async () => {
24+
renderWithRelay({
25+
Me: () => ({
26+
showsConnection: {
27+
edges: [
28+
{
29+
node: {
30+
name: "Sebastián Meltz-Collazo",
31+
partner: {
32+
name: "Partner1",
33+
},
34+
},
35+
},
36+
{
37+
node: {
38+
name: "Artsy Editorial",
39+
partner: {
40+
name: "Partner2",
41+
},
42+
},
43+
},
44+
],
45+
},
46+
}),
47+
})
48+
49+
await waitForElementToBeRemoved(() => screen.queryByTestId("articles-screen-placeholder"))
50+
51+
expect(Geolocation.getCurrentPosition).toHaveBeenCalled()
52+
expect(mockFetch).not.toHaveBeenCalled()
53+
54+
expect(screen.getByText("Sebastián Meltz-Collazo")).toBeOnTheScreen()
55+
expect(screen.getByText("Artsy Editorial")).toBeOnTheScreen()
56+
57+
expect(screen.getByText("Partner1")).toBeOnTheScreen()
58+
expect(screen.getByText("Partner2")).toBeOnTheScreen()
59+
})
60+
})

src/app/Scenes/Shows/ShowsForYou.tsx

+18-12
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,19 @@ import {
1111
import { goBack } from "app/system/navigation/navigate"
1212
import { extractNodes } from "app/utils/extractNodes"
1313
import { useFeatureFlag } from "app/utils/hooks/useFeatureFlag"
14-
import { useLocation } from "app/utils/hooks/useLocation"
14+
import { Location, useLocation } from "app/utils/hooks/useLocation"
1515
import { ProvideScreenTrackingWithCohesionSchema } from "app/utils/track"
1616
import { screen } from "app/utils/track/helpers"
1717
import { Suspense, useState } from "react"
1818
import { ActivityIndicator, RefreshControl } from "react-native"
1919
import { graphql, useLazyLoadQuery, usePaginationFragment } from "react-relay"
2020

21-
const ShowsForYou: React.FC = () => {
22-
const enableShowsForYouLocation = useFeatureFlag("AREnableShowsForYouLocation")
21+
interface ShowsForYouProps {
22+
location: Location | null
23+
}
2324

24-
const { location, isLoading } = useLocation({
25-
disabled: !enableShowsForYouLocation,
26-
skipPermissionRequests: true,
27-
})
25+
const ShowsForYou: React.FC<ShowsForYouProps> = ({ location }) => {
26+
const enableShowsForYouLocation = useFeatureFlag("AREnableShowsForYouLocation")
2827

2928
const showsForYouQueryVariables = location
3029
? { near: location, count: 10 }
@@ -35,10 +34,6 @@ const ShowsForYou: React.FC = () => {
3534
showsForYouQueryVariables
3635
)
3736

38-
if (isLoading) {
39-
return <ArticlesPlaceholder title="Shows for You" />
40-
}
41-
4237
return <ShowsForYouList me={queryData.me} />
4338
}
4439

@@ -117,9 +112,20 @@ export const ShowsForYouList: React.FC<{ me: any }> = ({ me }) => {
117112
}
118113

119114
export const ShowsForYouScreen: React.FC = () => {
115+
const enableShowsForYouLocation = useFeatureFlag("AREnableShowsForYouLocation")
116+
117+
const { location, isLoading } = useLocation({
118+
disabled: !enableShowsForYouLocation,
119+
skipPermissionRequests: true,
120+
})
121+
122+
if (isLoading) {
123+
return <ArticlesPlaceholder title="Shows for You" />
124+
}
125+
120126
return (
121127
<Suspense fallback={<ArticlesPlaceholder title="Shows for You" />}>
122-
<ShowsForYou />
128+
<ShowsForYou location={location} />
123129
</Suspense>
124130
)
125131
}

0 commit comments

Comments
 (0)