@@ -4,7 +4,7 @@ import { sendKeys } from '@web/test-runner-commands';
44import sinon from 'sinon' ;
55import './not-animated-styles.js' ;
66import '../vaadin-date-picker.js' ;
7- import { close , getFocusedCell , getOverlayContent , open , waitForScrollToFinish } from './common.js' ;
7+ import { close , getFocusedCell , getOverlayContent , idleCallback , open , waitForScrollToFinish } from './common.js' ;
88
99describe ( 'keyboard' , ( ) => {
1010 let datepicker ;
@@ -75,7 +75,6 @@ describe('keyboard', () => {
7575 it ( 'should reflect focused date to input' , async ( ) => {
7676 datepicker . value = '2000-01-01' ;
7777 await open ( datepicker ) ;
78- await nextRender ( datepicker ) ;
7978
8079 // Move focus to the calendar
8180 await sendKeys ( { press : 'Tab' } ) ;
@@ -170,8 +169,8 @@ describe('keyboard', () => {
170169 beforeEach ( async ( ) => {
171170 // Open the overlay
172171 await open ( datepicker ) ;
173- await nextRender ( datepicker ) ;
174172 overlayContent = getOverlayContent ( datepicker ) ;
173+ await idleCallback ( ) ;
175174 } ) ;
176175
177176 it ( 'should keep focused attribute when the focus moves to the overlay' , async ( ) => {
@@ -257,70 +256,43 @@ describe('keyboard', () => {
257256 } ) ;
258257
259258 describe ( 'focus date not in the viewport' , ( ) => {
260- let spy ;
261-
262- afterEach ( ( ) => {
263- spy . restore ( ) ;
264- } ) ;
265-
266- it ( 'should focus date scrolled out of the view on input Tab' , async ( ) => {
267- // Move focus to the calendar
268- await sendKeys ( { press : 'Tab' } ) ;
269- await nextRender ( datepicker ) ;
259+ beforeEach ( async ( ) => {
260+ // Disable scrolling animation
261+ const stub = sinon . stub ( overlayContent , 'revealDate' ) . callsFake ( ( date ) => {
262+ stub . wrappedMethod . call ( overlayContent , date , false ) ;
263+ } ) ;
270264
271265 // Scroll to date outside viewport
272266 const date = new Date ( ) ;
273267 date . setFullYear ( date . getFullYear ( ) - 1 ) ;
274268 overlayContent . revealDate ( date ) ;
275- await waitForScrollToFinish ( overlayContent ) ;
269+ await idleCallback ( ) ;
270+ } ) ;
276271
277- // Move focus to the input
278- await sendKeys ( { down : 'Shift' } ) ;
272+ it ( 'should focus date scrolled out of the view on input Tab' , async ( ) => {
273+ // Move focus to the calendar
279274 await sendKeys ( { press : 'Tab' } ) ;
280- await sendKeys ( { up : 'Shift' } ) ;
281-
282- // Do not spy on the DOM element because it can be reused
283- // by infinite scroller. Instead, spy on the native focus.
284- spy = sinon . spy ( HTMLElement . prototype , 'focus' ) ;
285275
286- // Move focus back to the date
287- await sendKeys ( { press : 'Tab' } ) ;
288276 await waitForScrollToFinish ( overlayContent ) ;
289277
290- expect ( spy . calledOnce ) . to . be . true ;
291-
292- const cell = spy . firstCall . thisValue ;
278+ const cell = getFocusedCell ( overlayContent ) ;
279+ expect ( cell ) . to . be . instanceOf ( HTMLTableCellElement ) ;
293280 expect ( cell . hasAttribute ( 'today' ) ) . to . be . true ;
294281 } ) ;
295282
296283 it ( 'should focus date scrolled out of the view on Today button Shift Tab' , async ( ) => {
297- // Move focus to the calendar
298- await sendKeys ( { press : 'Tab' } ) ;
299- await nextRender ( datepicker ) ;
300-
301- // Scroll to date outside viewport
302- const date = new Date ( ) ;
303- date . setFullYear ( date . getFullYear ( ) - 1 ) ;
304- overlayContent . revealDate ( date ) ;
305- await waitForScrollToFinish ( overlayContent ) ;
306-
307284 // Move focus to the Today button
308- await sendKeys ( { press : 'Tab' } ) ;
309-
310- // Do not spy on the DOM element because it can be reused
311- // by infinite scroller. Instead, spy on the native focus.
312- spy = sinon . spy ( HTMLElement . prototype , 'focus' ) ;
285+ overlayContent . $ . todayButton . focus ( ) ;
313286
314- // Move focus back to the date
287+ // Move focus to the calendar
315288 await sendKeys ( { down : 'Shift' } ) ;
316289 await sendKeys ( { press : 'Tab' } ) ;
317290 await sendKeys ( { up : 'Shift' } ) ;
318291
319292 await waitForScrollToFinish ( overlayContent ) ;
320293
321- expect ( spy . calledOnce ) . to . be . true ;
322-
323- const cell = spy . firstCall . thisValue ;
294+ const cell = getFocusedCell ( overlayContent ) ;
295+ expect ( cell ) . to . be . instanceOf ( HTMLTableCellElement ) ;
324296 expect ( cell . hasAttribute ( 'today' ) ) . to . be . true ;
325297 } ) ;
326298 } ) ;
@@ -364,7 +336,6 @@ describe('keyboard', () => {
364336 beforeEach ( async ( ) => {
365337 // Open the overlay
366338 await open ( datepicker ) ;
367- await nextRender ( datepicker ) ;
368339 } ) ;
369340
370341 it ( 'should close the overlay when input is focused' , async ( ) => {
@@ -436,7 +407,6 @@ describe('keyboard', () => {
436407 beforeEach ( async ( ) => {
437408 datepicker . value = '2000-01-01' ;
438409 await open ( datepicker ) ;
439- await nextRender ( datepicker ) ;
440410 input . select ( ) ;
441411 } ) ;
442412
@@ -579,8 +549,7 @@ describe('keyboard', () => {
579549
580550 it ( 'should fire change on selecting date with Enter' , async ( ) => {
581551 // Open the overlay
582- await sendKeys ( { press : 'ArrowDown' } ) ;
583- await nextRender ( datepicker ) ;
552+ await open ( datepicker ) ;
584553
585554 // Move focus to the calendar
586555 await sendKeys ( { press : 'ArrowDown' } ) ;
@@ -592,8 +561,7 @@ describe('keyboard', () => {
592561
593562 it ( 'should fire change on selecting date with Space' , async ( ) => {
594563 // Open the overlay
595- await sendKeys ( { press : 'ArrowDown' } ) ;
596- await nextRender ( datepicker ) ;
564+ await open ( datepicker ) ;
597565
598566 // Move focus to the calendar
599567 await sendKeys ( { press : 'ArrowDown' } ) ;
0 commit comments