@planningcenter/tapestry-react 2.6.0 → 2.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Collapse/Collapse.js +3 -1
- package/dist/cjs/Dropdown/Dropdown.js +19 -2
- package/dist/cjs/Input/Input.js +4 -2
- package/dist/cjs/Modal/Modal.js +4 -2
- package/dist/cjs/TimeField/TimeField.js +37 -2
- package/dist/cjs/TimeField/TimeField.test.js +179 -10
- package/dist/cjs/Tooltip/Tooltip.test.js +178 -0
- package/dist/esm/Collapse/Collapse.js +3 -1
- package/dist/esm/Dropdown/Dropdown.js +19 -2
- package/dist/esm/Input/Input.js +4 -2
- package/dist/esm/Modal/Modal.js +4 -2
- package/dist/esm/TimeField/TimeField.js +36 -2
- package/dist/esm/TimeField/TimeField.test.js +153 -10
- package/dist/esm/Tooltip/Tooltip.test.js +160 -0
- package/dist/types/Tooltip/Tooltip.test.d.ts +1 -0
- package/package.json +1 -1
- package/src/Collapse/Collapse.js +1 -1
- package/src/Dropdown/Dropdown.js +12 -1
- package/src/Input/Input.js +7 -0
- package/src/Modal/Modal.js +4 -2
- package/src/TimeField/TimeField.js +35 -2
- package/src/TimeField/TimeField.test.tsx +105 -1
- package/src/Tooltip/Tooltip.test.tsx +136 -0
|
@@ -121,7 +121,7 @@ it('does not change the meridiem on arrow key if arrow keys are ignored', () =>
|
|
|
121
121
|
expect(meridiemInput).toHaveValue('PM')
|
|
122
122
|
})
|
|
123
123
|
|
|
124
|
-
it('
|
|
124
|
+
it('increment hour on arrow up', () => {
|
|
125
125
|
const { hourInput } = setup( { hours: 1, minutes: 42 })
|
|
126
126
|
|
|
127
127
|
expect(hourInput).toHaveValue("01")
|
|
@@ -129,6 +129,110 @@ it('changes the value of hours on arrow up or arrow down', () => {
|
|
|
129
129
|
expect(hourInput).toHaveValue("02")
|
|
130
130
|
})
|
|
131
131
|
|
|
132
|
+
it('increment hour if arrow up on minutes exceeds max value', () => {
|
|
133
|
+
const { hourInput, minuteInput } = setup( { hours: 1, minutes: 59 })
|
|
134
|
+
|
|
135
|
+
expect(hourInput).toHaveValue("01")
|
|
136
|
+
userEvent.type(minuteInput, '{arrowup}')
|
|
137
|
+
expect(hourInput).toHaveValue("02")
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('decrement hour on arrow down', () => {
|
|
141
|
+
const { hourInput } = setup( { hours: 2, minutes: 42 })
|
|
142
|
+
|
|
143
|
+
expect(hourInput).toHaveValue("02")
|
|
144
|
+
userEvent.type(hourInput, '{arrowdown}')
|
|
145
|
+
expect(hourInput).toHaveValue("01")
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
it('decrement hour if arrow down on minutes exceeds min value', () => {
|
|
149
|
+
const { hourInput, minuteInput } = setup( { hours: 2, minutes: 0 })
|
|
150
|
+
|
|
151
|
+
expect(hourInput).toHaveValue("02")
|
|
152
|
+
userEvent.type(minuteInput, '{arrowdown}')
|
|
153
|
+
expect(hourInput).toHaveValue("01")
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it('increment minute on arrow up', () => {
|
|
157
|
+
const { minuteInput } = setup( { hours: 1, minutes: 42 })
|
|
158
|
+
|
|
159
|
+
expect(minuteInput).toHaveValue("42")
|
|
160
|
+
userEvent.type(minuteInput, '{arrowup}')
|
|
161
|
+
expect(minuteInput).toHaveValue("43")
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
it('decrement minute on arrow down', () => {
|
|
165
|
+
const { minuteInput } = setup( { hours: 2, minutes: 43 })
|
|
166
|
+
|
|
167
|
+
expect(minuteInput).toHaveValue("43")
|
|
168
|
+
userEvent.type(minuteInput, '{arrowdown}')
|
|
169
|
+
expect(minuteInput).toHaveValue("42")
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
it('set minute to min value if arrow up on minutes exceeds max value', () => {
|
|
173
|
+
const { minuteInput } = setup( { hours: 1, minutes: 59 })
|
|
174
|
+
|
|
175
|
+
expect(minuteInput).toHaveValue("59")
|
|
176
|
+
userEvent.type(minuteInput, '{arrowup}')
|
|
177
|
+
expect(minuteInput).toHaveValue("00")
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('set minute to max value if arrow down on minutes exceeds min value', () => {
|
|
181
|
+
const { minuteInput } = setup( { hours: 1, minutes: 0 })
|
|
182
|
+
|
|
183
|
+
expect(minuteInput).toHaveValue("00")
|
|
184
|
+
userEvent.type(minuteInput, '{arrowdown}')
|
|
185
|
+
expect(minuteInput).toHaveValue("59")
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
it('toggle meridiem if arrow up on hour exceeds eleven', () => {
|
|
189
|
+
const { hourInput, meridiemInput } = setup( { hours: 11 })
|
|
190
|
+
|
|
191
|
+
expect(meridiemInput).toHaveValue('AM')
|
|
192
|
+
userEvent.type(hourInput, '{arrowup}')
|
|
193
|
+
expect(meridiemInput).toHaveValue('PM')
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
it('toggle meridiem if arrow down on hour exceeds min value', () => {
|
|
197
|
+
const { hourInput, meridiemInput } = setup( { hours: 1 })
|
|
198
|
+
|
|
199
|
+
expect(meridiemInput).toHaveValue('AM')
|
|
200
|
+
userEvent.type(hourInput, '{arrowdown}')
|
|
201
|
+
expect(meridiemInput).toHaveValue('PM')
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
it('set 12 hour clock to min value if arrow up on hour exceeds max value', () => {
|
|
205
|
+
const { hourInput } = setup( { hours: 12 })
|
|
206
|
+
|
|
207
|
+
expect(hourInput).toHaveValue("12")
|
|
208
|
+
userEvent.type(hourInput, '{arrowup}')
|
|
209
|
+
expect(hourInput).toHaveValue("01")
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
it('set 24 hour clock to min value if arrow up on hour exceeds max value', () => {
|
|
213
|
+
const { hourInput } = setup( { hours: 23, twelveHourClock: false })
|
|
214
|
+
|
|
215
|
+
expect(hourInput).toHaveValue("23")
|
|
216
|
+
userEvent.type(hourInput, '{arrowup}')
|
|
217
|
+
expect(hourInput).toHaveValue("00")
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
it('set 12 hour clock to max value if arrow down on hour exceeds min value', () => {
|
|
221
|
+
const { hourInput } = setup( { hours: 1 })
|
|
222
|
+
|
|
223
|
+
expect(hourInput).toHaveValue("01")
|
|
224
|
+
userEvent.type(hourInput, '{arrowdown}')
|
|
225
|
+
expect(hourInput).toHaveValue("12")
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
it('set 24 hour clock to max value if arrow down on hour exceeds min value', () => {
|
|
229
|
+
const { hourInput } = setup( { hours: 0, twelveHourClock: false })
|
|
230
|
+
|
|
231
|
+
expect(hourInput).toHaveValue("00")
|
|
232
|
+
userEvent.type(hourInput, '{arrowdown}')
|
|
233
|
+
expect(hourInput).toHaveValue("23")
|
|
234
|
+
})
|
|
235
|
+
|
|
132
236
|
it('does not change the value of hours on arrow up or arrow down if ignored', () => {
|
|
133
237
|
const { hourInput } = setup( { hours: 1, minutes: 42, ignoredKeys: ['ArrowUp', 'ArrowDown'] })
|
|
134
238
|
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { act, render, screen, waitFor } from '@testing-library/react'
|
|
3
|
+
import userEvent from '@testing-library/user-event'
|
|
4
|
+
import '@testing-library/jest-dom/extend-expect'
|
|
5
|
+
import { Button, Link, StackView, Text, Tooltip, hooks } from '..'
|
|
6
|
+
|
|
7
|
+
describe('Tooltip', () => {
|
|
8
|
+
test('does not render string when closed', () => {
|
|
9
|
+
const string = 'Test Text'
|
|
10
|
+
render(
|
|
11
|
+
<Tooltip title={string}>
|
|
12
|
+
<Text>Tooltip anchor</Text>
|
|
13
|
+
</Tooltip>
|
|
14
|
+
)
|
|
15
|
+
expect(screen.queryByText(string)).toBeNull()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('renders string on hover', async () => {
|
|
19
|
+
const string = 'Test Text'
|
|
20
|
+
render(
|
|
21
|
+
<Tooltip title={string}>
|
|
22
|
+
<Text>Tooltip anchor</Text>
|
|
23
|
+
</Tooltip>
|
|
24
|
+
)
|
|
25
|
+
userEvent.hover(screen.getByText('Tooltip anchor'))
|
|
26
|
+
const tooltip = await screen.findByText(string)
|
|
27
|
+
expect(tooltip).toBeInTheDocument()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('renders string on focus', async () => {
|
|
31
|
+
const string = 'Test Text'
|
|
32
|
+
render(
|
|
33
|
+
<Tooltip title={string} triggerOnFocus={true}>
|
|
34
|
+
<Button>Tooltip anchor</Button>
|
|
35
|
+
</Tooltip>
|
|
36
|
+
)
|
|
37
|
+
userEvent.tab()
|
|
38
|
+
const tooltip = await screen.findByText(string)
|
|
39
|
+
expect(tooltip).toBeInTheDocument()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('removes string after timeout', async () => {
|
|
43
|
+
const string = 'Test Text'
|
|
44
|
+
render(
|
|
45
|
+
<Tooltip title={string}>
|
|
46
|
+
<Text>Tooltip anchor</Text>
|
|
47
|
+
</Tooltip>
|
|
48
|
+
)
|
|
49
|
+
const anchor = screen.getByText('Tooltip anchor')
|
|
50
|
+
expect(screen.queryByText(string)).toBeNull()
|
|
51
|
+
|
|
52
|
+
userEvent.hover(anchor)
|
|
53
|
+
|
|
54
|
+
const tooltip = await screen.findByText(string)
|
|
55
|
+
expect(tooltip).toBeInTheDocument()
|
|
56
|
+
|
|
57
|
+
userEvent.unhover(anchor)
|
|
58
|
+
await waitFor(() => {
|
|
59
|
+
expect(screen.queryByText(string)).not.toBeInTheDocument()
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('stays open when hovering a custom tooltip', () => {
|
|
64
|
+
const CustomTooltip = function () {
|
|
65
|
+
const { hover, hoverProps } = hooks.useHover()
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<Tooltip
|
|
69
|
+
title={
|
|
70
|
+
<Link to="#">
|
|
71
|
+
<StackView>
|
|
72
|
+
<Text data-hover={hover}>{string}</Text>
|
|
73
|
+
</StackView>
|
|
74
|
+
</Link>
|
|
75
|
+
}
|
|
76
|
+
>
|
|
77
|
+
<Button {...hoverProps}>Tooltip anchor</Button>
|
|
78
|
+
</Tooltip>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
const string = 'Test Text'
|
|
82
|
+
render(<CustomTooltip />)
|
|
83
|
+
const anchor = screen.getByText('Tooltip anchor')
|
|
84
|
+
|
|
85
|
+
userEvent.hover(anchor)
|
|
86
|
+
act(() => {
|
|
87
|
+
jest.runAllTimers()
|
|
88
|
+
})
|
|
89
|
+
const tooltip = screen.getByText(string)
|
|
90
|
+
expect(tooltip).toBeInTheDocument()
|
|
91
|
+
|
|
92
|
+
userEvent.unhover(anchor)
|
|
93
|
+
userEvent.hover(tooltip)
|
|
94
|
+
act(() => {
|
|
95
|
+
jest.runAllTimers()
|
|
96
|
+
})
|
|
97
|
+
expect(tooltip).toBeInTheDocument()
|
|
98
|
+
|
|
99
|
+
userEvent.unhover(tooltip)
|
|
100
|
+
act(() => {
|
|
101
|
+
jest.runAllTimers()
|
|
102
|
+
})
|
|
103
|
+
expect(tooltip).not.toBeInTheDocument()
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('cleans up pageViewChange listeners', () => {
|
|
107
|
+
window.removeEventListener = jest
|
|
108
|
+
.fn()
|
|
109
|
+
.mockImplementation((event, callback) => {})
|
|
110
|
+
document.removeEventListener = jest
|
|
111
|
+
.fn()
|
|
112
|
+
.mockImplementation((event, callback) => {})
|
|
113
|
+
|
|
114
|
+
const { unmount } = render(
|
|
115
|
+
<Tooltip title="Test Text">
|
|
116
|
+
<Text>Tooltip anchor</Text>
|
|
117
|
+
</Tooltip>
|
|
118
|
+
)
|
|
119
|
+
unmount()
|
|
120
|
+
|
|
121
|
+
expect(window.removeEventListener).toBeCalledWith(
|
|
122
|
+
'focus',
|
|
123
|
+
expect.any(Function)
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
expect(window.removeEventListener).toBeCalledWith(
|
|
127
|
+
'blur',
|
|
128
|
+
expect.any(Function)
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
expect(document.removeEventListener).toBeCalledWith(
|
|
132
|
+
'visibilitychange',
|
|
133
|
+
expect.any(Function)
|
|
134
|
+
)
|
|
135
|
+
})
|
|
136
|
+
})
|