forked from artsy/eigen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDialog.tests.tsx
More file actions
103 lines (88 loc) · 2.71 KB
/
Dialog.tests.tsx
File metadata and controls
103 lines (88 loc) · 2.71 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
import { fireEvent } from "@testing-library/react-native"
import { extractText } from "app/tests/extractText"
import { renderWithWrappersTL } from "app/tests/renderWithWrappers"
import React from "react"
import { Dialog } from "./Dialog"
describe("Dialog", () => {
it("renders without error", () => {
const { getByTestId } = renderWithWrappersTL(
<Dialog
title="title"
isVisible
primaryCta={{
text: "Primary Action Button",
onPress: jest.fn(),
}}
/>
)
expect(extractText(getByTestId("dialog-title"))).toBe("title")
})
it("should render details if it is passed", () => {
const { getByTestId } = renderWithWrappersTL(
<Dialog
title="title"
detail="Some unique detail"
isVisible
primaryCta={{
text: "Primary Action Button",
onPress: jest.fn(),
}}
/>
)
expect(extractText(getByTestId("dialog-detail"))).toBe("Some unique detail")
})
it("should render the primary action button", () => {
const primaryActionMock = jest.fn()
const { getByTestId } = renderWithWrappersTL(
<Dialog
title="title"
isVisible
primaryCta={{
text: "Primary Action Button",
onPress: primaryActionMock,
}}
/>
)
const primaryButton = getByTestId("dialog-primary-action-button")
fireEvent.press(primaryButton)
expect(primaryActionMock).toHaveBeenCalled()
expect(extractText(primaryButton)).toContain("Primary Action Button")
})
it("should render the secondary action button if it is passed", () => {
const secondaryActionMock = jest.fn()
const { getByTestId } = renderWithWrappersTL(
<Dialog
title="title"
isVisible
primaryCta={{
text: "Primary Action Button",
onPress: jest.fn(),
}}
secondaryCta={{
text: "Secondary Action Button",
onPress: secondaryActionMock,
}}
/>
)
const secondaryButton = getByTestId("dialog-secondary-action-button")
fireEvent.press(secondaryButton)
expect(secondaryActionMock).toHaveBeenCalled()
expect(extractText(secondaryButton)).toContain("Secondary Action Button")
})
it("should call onBackgroundPress when backdrop is pressed", () => {
const onBackgroundPressMock = jest.fn()
const { getByTestId } = renderWithWrappersTL(
<Dialog
title="title"
isVisible
onBackgroundPress={onBackgroundPressMock}
primaryCta={{
text: "Primary Action Button",
onPress: jest.fn(),
}}
/>
)
fireEvent.press(getByTestId("dialog-backdrop"))
expect(onBackgroundPressMock).toHaveBeenCalled()
})
})