11import { expect } from '@esm-bundle/chai' ;
22import {
33 arrowDown ,
4+ aTimeout ,
45 enter ,
56 escKeyDown ,
67 fixtureSync ,
78 focusin ,
89 focusout ,
910 mousedown ,
1011 nextFrame ,
12+ nextRender ,
1113 tabKeyDown ,
1214} from '@vaadin/testing-helpers' ;
1315import sinon from 'sinon' ;
@@ -23,7 +25,7 @@ function getHeaderCell(grid, index = 0) {
2325describe ( 'tooltip' , ( ) => {
2426 let grid , tooltip ;
2527
26- beforeEach ( ( ) => {
28+ beforeEach ( async ( ) => {
2729 grid = fixtureSync ( `
2830 <vaadin-grid>
2931 <vaadin-grid-column path="firstName"></vaadin-grid-column>
@@ -41,6 +43,7 @@ describe('tooltip', () => {
4143 tooltip . generator = ( { column, item } ) => {
4244 return column && column . path && item ? `${ column . path } : ${ item [ column . path ] } ` : '' ;
4345 } ;
46+ await nextRender ( ) ;
4447 } ) ;
4548
4649 it ( 'should set manual on the tooltip to true' , ( ) => {
@@ -53,13 +56,32 @@ describe('tooltip', () => {
5356 expect ( tooltip . opened ) . to . be . true ;
5457 } ) ;
5558
59+ it ( 'should use hover delay on cell mouseenter' , async ( ) => {
60+ tooltip . hoverDelay = 10 ;
61+ const cell = getCell ( grid , 0 ) ;
62+ mouseenter ( cell ) ;
63+ expect ( tooltip . opened ) . to . be . false ;
64+ await aTimeout ( 10 ) ;
65+ expect ( tooltip . opened ) . to . be . true ;
66+ } ) ;
67+
5668 it ( 'should hide tooltip on cell mouseleave' , ( ) => {
5769 const cell = getCell ( grid , 0 ) ;
5870 mouseenter ( cell ) ;
5971 mouseleave ( cell ) ;
6072 expect ( tooltip . opened ) . to . be . false ;
6173 } ) ;
6274
75+ it ( 'should use hide delay on cell mouseleave' , async ( ) => {
76+ tooltip . hideDelay = 10 ;
77+ const cell = getCell ( grid , 0 ) ;
78+ mouseenter ( cell ) ;
79+ mouseleave ( cell ) ;
80+ expect ( tooltip . opened ) . to . be . true ;
81+ await aTimeout ( 10 ) ;
82+ expect ( tooltip . opened ) . to . be . false ;
83+ } ) ;
84+
6385 it ( 'should set tooltip target on cell mouseenter' , ( ) => {
6486 const cell = getCell ( grid , 0 ) ;
6587 mouseenter ( cell ) ;
@@ -91,13 +113,31 @@ describe('tooltip', () => {
91113 expect ( tooltip . opened ) . to . be . false ;
92114 } ) ;
93115
116+ it ( 'should not use hide delay on cell mousedown' , ( ) => {
117+ tooltip . hideDelay = 10 ;
118+ const cell = getCell ( grid , 0 ) ;
119+ mouseenter ( cell ) ;
120+ mousedown ( cell ) ;
121+ expect ( tooltip . opened ) . to . be . false ;
122+ } ) ;
123+
94124 it ( 'should show tooltip on cell keyboard focus' , ( ) => {
95125 const cell = getCell ( grid , 0 ) ;
96126 tabKeyDown ( document . body ) ;
97127 focusin ( cell ) ;
98128 expect ( tooltip . opened ) . to . be . true ;
99129 } ) ;
100130
131+ it ( 'should use focus delay on cell keyboard focus' , async ( ) => {
132+ tooltip . focusDelay = 10 ;
133+ const cell = getCell ( grid , 0 ) ;
134+ tabKeyDown ( document . body ) ;
135+ focusin ( cell ) ;
136+ expect ( tooltip . opened ) . to . be . false ;
137+ await aTimeout ( 10 ) ;
138+ expect ( tooltip . opened ) . to . be . true ;
139+ } ) ;
140+
101141 it ( 'should set tooltip target on cell keyboard focus' , ( ) => {
102142 const cell = getCell ( grid , 0 ) ;
103143 tabKeyDown ( document . body ) ;
@@ -151,6 +191,15 @@ describe('tooltip', () => {
151191 expect ( tooltip . opened ) . to . be . false ;
152192 } ) ;
153193
194+ it ( 'should not use hide delay on grid cell content Esc' , ( ) => {
195+ tooltip . hideDelay = 10 ;
196+ const cell = getCell ( grid , 0 ) ;
197+ tabKeyDown ( document . body ) ;
198+ focusin ( cell . _content ) ;
199+ escKeyDown ( cell . _content ) ;
200+ expect ( tooltip . opened ) . to . be . false ;
201+ } ) ;
202+
154203 it ( 'should set tooltip opened to false when the grid is removed' , ( ) => {
155204 const cell = getCell ( grid , 0 ) ;
156205 mouseenter ( cell ) ;
0 commit comments