10
10
* governing permissions and limitations under the License.
11
11
*/
12
12
13
- import { act , fireEvent , render } from '@react-spectrum/test-utils' ;
13
+ import { act , pointerMap , render } from '@react-spectrum/test-utils-internal ' ;
14
14
import { CalendarDate } from '@internationalized/date' ;
15
15
import { Example } from '../stories/Example' ;
16
16
import React from 'react' ;
17
+ import userEvent from '@testing-library/user-event' ;
17
18
18
19
describe ( 'useCalendar' , ( ) => {
20
+ let user ;
19
21
beforeAll ( ( ) => {
20
22
jest . useFakeTimers ( ) ;
23
+ user = userEvent . setup ( { delay : null , pointerMap} ) ;
21
24
} ) ;
22
25
23
26
afterEach ( ( ) => {
@@ -36,8 +39,15 @@ describe('useCalendar', () => {
36
39
expect ( document . activeElement ) . toBe ( cell ) ;
37
40
38
41
for ( let i = 0 ; i < count ; i ++ ) {
39
- fireEvent . keyDown ( document . activeElement , { key, ...opts } ) ;
40
- fireEvent . keyUp ( document . activeElement , { key, ...opts } ) ;
42
+ if ( opts ?. shiftKey ) {
43
+ await user . keyboard ( '{Shift>}' ) ;
44
+ }
45
+
46
+ await user . keyboard ( `{${ key } }` ) ;
47
+
48
+ if ( opts ?. shiftKey ) {
49
+ await user . keyboard ( '{/Shift}' ) ;
50
+ }
41
51
}
42
52
43
53
cell = getByLabelText ( value , { exact : false } ) ;
@@ -142,21 +152,19 @@ describe('useCalendar', () => {
142
152
} ) ;
143
153
} ) ;
144
154
145
- function testPagination ( defaultValue , rangeBefore , rangeAfter , rel , count , visibleDuration , pageBehavior ) {
155
+ async function testPagination ( defaultValue , rangeBefore , rangeAfter , rel , count , visibleDuration , pageBehavior ) {
146
156
let { getByTestId, getByLabelText, unmount} = render ( < Example defaultValue = { defaultValue } autoFocus visibleDuration = { visibleDuration } pageBehavior = { pageBehavior } /> ) ;
147
157
let grid = getByTestId ( 'range' ) ;
148
158
expect ( grid ) . toHaveTextContent ( rangeBefore ) ;
149
-
150
159
let btn = getByLabelText ( rel ) ;
151
160
152
161
for ( let i = 0 ; i < count ; i ++ ) {
153
- fireEvent . click ( btn ) ;
162
+ await user . click ( btn ) ;
154
163
}
155
164
156
165
expect ( grid ) . toHaveTextContent ( rangeAfter ) ;
157
-
158
166
unmount ( ) ;
159
- }
167
+ }
160
168
161
169
describe ( 'pagination' , ( ) => {
162
170
it . each `
@@ -165,18 +173,18 @@ describe('useCalendar', () => {
165
173
${ 'going forward two' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'January to February 2019' } | ${ 'May to June 2019' } | ${ 'Next' } | ${ 2 } | ${ { months : 2 } }
166
174
${ 'going backward one' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'January to February 2019' } | ${ 'November to December 2018' } | ${ 'Previous' } | ${ 1 } | ${ { months : 2 } }
167
175
${ 'going backward two' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'January to February 2019' } | ${ 'September to October 2018' } | ${ 'Previous' } | ${ 2 } | ${ { months : 2 } }
168
- ` ( 'should use visible as default value $Name' , ( { defaultValue, rangeBefore, rangeAfter, rel, count, visibleDuration} ) => {
169
- testPagination ( defaultValue , rangeBefore , rangeAfter , rel , count , visibleDuration ) ;
176
+ ` ( 'should use visible as default value $Name' , async ( { defaultValue, rangeBefore, rangeAfter, rel, count, visibleDuration} ) => {
177
+ await testPagination ( defaultValue , rangeBefore , rangeAfter , rel , count , visibleDuration ) ;
170
178
} ) ;
171
-
179
+
172
180
it . each `
173
181
Name | defaultValue | rangeBefore | rangeAfter | rel | count | visibleDuration | pageBehavior
174
182
${ 'going forward one' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'January to February 2019' } | ${ 'February to March 2019' } | ${ 'Next' } | ${ 1 } | ${ { months : 2 } } | ${ 'single' }
175
183
${ 'going forward two' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'January to February 2019' } | ${ 'March to April 2019' } | ${ 'Next' } | ${ 2 } | ${ { months : 2 } } | ${ 'single' }
176
184
${ 'going backward one' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'January to February 2019' } | ${ 'December 2018 to January 2019' } | ${ 'Previous' } | ${ 1 } | ${ { months : 2 } } | ${ 'single' }
177
185
${ 'going backward two' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'January to February 2019' } | ${ 'November to December 2018' } | ${ 'Previous' } | ${ 2 } | ${ { months : 2 } } | ${ 'single' }
178
- ` ( 'should use pageBehavior single $Name' , ( { defaultValue, rangeBefore, rangeAfter, rel, count, visibleDuration, pageBehavior} ) => {
179
- testPagination ( defaultValue , rangeBefore , rangeAfter , rel , count , visibleDuration , pageBehavior ) ;
186
+ ` ( 'should use pageBehavior single $Name' , async ( { defaultValue, rangeBefore, rangeAfter, rel, count, visibleDuration, pageBehavior} ) => {
187
+ await testPagination ( defaultValue , rangeBefore , rangeAfter , rel , count , visibleDuration , pageBehavior ) ;
180
188
} ) ;
181
189
182
190
it . each `
@@ -185,8 +193,8 @@ describe('useCalendar', () => {
185
193
${ 'week going forward two' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'December 23, 2018 to January 12, 2019' } | ${ 'February 3 to 23, 2019' } | ${ 'Next' } | ${ 2 } | ${ { weeks : 3 } }
186
194
${ 'week going backward one' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'December 23, 2018 to January 12, 2019' } | ${ 'December 2 to 22, 2018' } | ${ 'Previous' } | ${ 1 } | ${ { weeks : 3 } }
187
195
${ 'week going backward two' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'December 23, 2018 to January 12, 2019' } | ${ 'November 11 to December 1, 2018' } | ${ 'Previous' } | ${ 2 } | ${ { weeks : 3 } }
188
- ` ( 'should use visible as default $Name' , ( { defaultValue, rangeBefore, rangeAfter, rel, count, visibleDuration, pageBehavior} ) => {
189
- testPagination ( defaultValue , rangeBefore , rangeAfter , rel , count , visibleDuration , pageBehavior ) ;
196
+ ` ( 'should use visible as default $Name' , async ( { defaultValue, rangeBefore, rangeAfter, rel, count, visibleDuration, pageBehavior} ) => {
197
+ await testPagination ( defaultValue , rangeBefore , rangeAfter , rel , count , visibleDuration , pageBehavior ) ;
190
198
} ) ;
191
199
192
200
it . each `
@@ -195,8 +203,8 @@ describe('useCalendar', () => {
195
203
${ 'week going forward four' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'December 23, 2018 to January 12, 2019' } | ${ 'January 20 to February 9, 2019' } | ${ 'Next' } | ${ 4 } | ${ { weeks : 3 } } | ${ 'single' }
196
204
${ 'week going backward one' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'December 23, 2018 to January 12, 2019' } | ${ 'December 16, 2018 to January 5, 2019' } | ${ 'Previous' } | ${ 1 } | ${ { weeks : 3 } } | ${ 'single' }
197
205
${ 'week going backward four' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'December 23, 2018 to January 12, 2019' } | ${ 'November 25 to December 15, 2018' } | ${ 'Previous' } | ${ 4 } | ${ { weeks : 3 } } | ${ 'single' }
198
- ` ( 'should use pageBehavior single $Name' , ( { defaultValue, rangeBefore, rangeAfter, rel, count, visibleDuration, pageBehavior} ) => {
199
- testPagination ( defaultValue , rangeBefore , rangeAfter , rel , count , visibleDuration , pageBehavior ) ;
206
+ ` ( 'should use pageBehavior single $Name' , async ( { defaultValue, rangeBefore, rangeAfter, rel, count, visibleDuration, pageBehavior} ) => {
207
+ await testPagination ( defaultValue , rangeBefore , rangeAfter , rel , count , visibleDuration , pageBehavior ) ;
200
208
} ) ;
201
209
202
210
it . each `
@@ -205,8 +213,8 @@ describe('useCalendar', () => {
205
213
${ 'day going forward two' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'December 30, 2018 to January 3, 2019' } | ${ 'January 9 to 13, 2019' } | ${ 'Next' } | ${ 2 } | ${ { days : 5 } }
206
214
${ 'day going backward one' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'December 30, 2018 to January 3, 2019' } | ${ 'December 25 to 29, 2018' } | ${ 'Previous' } | ${ 1 } | ${ { days : 5 } }
207
215
${ 'day going backward two' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'December 30, 2018 to January 3, 2019' } | ${ 'December 20 to 24, 2018' } | ${ 'Previous' } | ${ 2 } | ${ { days : 5 } }
208
- ` ( 'should use visible as default $Name' , ( { defaultValue, rangeBefore, rangeAfter, rel, count, visibleDuration, pageBehavior} ) => {
209
- testPagination ( defaultValue , rangeBefore , rangeAfter , rel , count , visibleDuration , pageBehavior ) ;
216
+ ` ( 'should use visible as default $Name' , async ( { defaultValue, rangeBefore, rangeAfter, rel, count, visibleDuration, pageBehavior} ) => {
217
+ await testPagination ( defaultValue , rangeBefore , rangeAfter , rel , count , visibleDuration , pageBehavior ) ;
210
218
} ) ;
211
219
212
220
it . each `
@@ -215,8 +223,8 @@ describe('useCalendar', () => {
215
223
${ 'day going forward five' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'December 30, 2018 to January 3, 2019' } | ${ 'January 3 to 7, 2019' } | ${ 'Next' } | ${ 4 } | ${ { days : 5 } } | ${ 'single' }
216
224
${ 'day going backward one' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'December 30, 2018 to January 3, 2019' } | ${ 'December 29, 2018 to January 2, 2019' } | ${ 'Previous' } | ${ 1 } | ${ { days : 5 } } | ${ 'single' }
217
225
${ 'day going backward five' } | ${ new CalendarDate ( 2019 , 1 , 1 ) } | ${ 'December 30, 2018 to January 3, 2019' } | ${ 'December 26 to 30, 2018' } | ${ 'Previous' } | ${ 4 } | ${ { days : 5 } } | ${ 'single' }
218
- ` ( 'should use pageBehavior single $Name' , ( { defaultValue, rangeBefore, rangeAfter, rel, count, visibleDuration, pageBehavior} ) => {
219
- testPagination ( defaultValue , rangeBefore , rangeAfter , rel , count , visibleDuration , pageBehavior ) ;
226
+ ` ( 'should use pageBehavior single $Name' , async ( { defaultValue, rangeBefore, rangeAfter, rel, count, visibleDuration, pageBehavior} ) => {
227
+ await testPagination ( defaultValue , rangeBefore , rangeAfter , rel , count , visibleDuration , pageBehavior ) ;
220
228
} ) ;
221
229
} ) ;
222
230
} ) ;
0 commit comments