-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathConnectWidgets.test.tsx
More file actions
93 lines (87 loc) · 3.61 KB
/
Copy pathConnectWidgets.test.tsx
File metadata and controls
93 lines (87 loc) · 3.61 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
import { render, waitFor } from "@testing-library/react-native"
import { ConnectWidget } from "./ConnectWidgets"
import { fullWidgetComponentTestSuite } from "./widgets.test"
import { triggerUrlChange } from "../../test/mocks/react_native"
jest.mock("expo-web-browser", () => {
return {
openAuthSessionAsync: jest.fn().mockResolvedValue({ type: "success" }),
}
})
describe("ConnectWidget", () => {
fullWidgetComponentTestSuite(ConnectWidget)
describe("OAuth", () => {
const testCases: {
label: string
url: string
check: (msg: string) => void
}[] = [
{
label:
"an OAuth deeplink triggers a post message to the web view (public URL with matching host)",
url: "appscheme://oauth_complete?member_guid=MBR-123&status=success",
check: (msg) => expect(msg).toContain("MBR-123"),
},
{
label:
"an OAuth deeplink triggers a post message to the web view (local URL with matching path)",
url: "exp://127.0.0.1:19000/--/oauth_complete?member_guid=MBR-123&status=success",
check: (msg) => expect(msg).toContain("MBR-123"),
},
{
label:
"an OAuth deeplink triggers a post message to the web view (public URL with matching path)",
url: "exp://exp.host/@community/with-webbrowser-redirect/--/oauth_complete?member_guid=MBR-123&status=success",
check: (msg) => expect(msg).toContain("MBR-123"),
},
{
label:
"an OAuth success deeplink includes the right status (public URL with matching host)",
url: "appscheme://oauth_complete?member_guid=MBR-123&status=success",
check: (msg) => expect(msg).toContain("oauthComplete/success"),
},
{
label: "an OAuth success deeplink includes the right status (local URL with matching path)",
url: "exp://127.0.0.1:19000/--/oauth_complete?member_guid=MBR-123&status=success",
check: (msg) => expect(msg).toContain("oauthComplete/success"),
},
{
label:
"an OAuth success deeplink includes the right status (public URL with matching path)",
url: "exp://exp.host/@community/with-webbrowser-redirect/--/oauth_complete?member_guid=MBR-123&status=success",
check: (msg) => expect(msg).toContain("oauthComplete/success"),
},
{
label:
"an OAuth failure deeplink includes the right status (public URL with matching host)",
url: "appscheme://oauth_complete?member_guid=MBR-123&status=error",
check: (msg) => expect(msg).toContain("oauthComplete/error"),
},
{
label: "an OAuth failure deeplink includes the right status (local URL with matching path)",
url: "exp://127.0.0.1:19000/--/oauth_complete?member_guid=MBR-123&status=error",
check: (msg) => expect(msg).toContain("oauthComplete/error"),
},
{
label:
"an OAuth failure deeplink includes the right status (public URL with matching path)",
url: "exp://exp.host/@community/with-webbrowser-redirect/--/oauth_complete?member_guid=MBR-123&status=error",
check: (msg) => expect(msg).toContain("oauthComplete/error"),
},
]
testCases.forEach((testCase) => {
test(testCase.label, async () => {
expect.assertions(1)
const component = render(
<ConnectWidget
url="https://widgets.moneydesktop.com/md/..."
sendOAuthPostMessage={(_ref, msg) => {
testCase.check(msg)
}}
/>,
)
await waitFor(() => component.findByTestId("widget_webview"))
triggerUrlChange(testCase.url)
})
})
})
})