Skip to content

Commit b9dd28b

Browse files
committed
chore(grid): add test for tooltip on focus
1 parent 21772b2 commit b9dd28b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

projects/angular/components/ui-grid/src/ui-grid.component.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,33 @@ describe('Component: UiGrid', () => {
285285
expect(Math.round(initialCol1Width + initialCol2Width)).toEqual(Math.round(newCol1Width + newCol2Width));
286286
discardPeriodicTasks();
287287
}));
288+
289+
it('should show tooltip on keyboard focus and hide it on focusout', fakeAsync(() => {
290+
const spyTriggerTooltip = spyOn(grid, 'triggerColumnHeaderTooltip').and.callThrough();
291+
const spyHideTooltip = spyOn(grid, 'hideColumnHeaderTooltip').and.callThrough();
292+
const event = new KeyboardEvent('keydown', { key: 'Tab' });
293+
const focusEvent = new FocusEvent('focus', { bubbles: true });
294+
const focusOutEvent = new FocusEvent('focusout', { bubbles: true });
295+
const [columnHeader1, columnHeader2 ] = document.querySelectorAll('div[role="columnheader"]')!;
296+
297+
columnHeader1.dispatchEvent(event);
298+
fixture.detectChanges();
299+
300+
columnHeader1.dispatchEvent(focusEvent);
301+
fixture.detectChanges();
302+
tick(500);
303+
304+
const tooltip = document.querySelectorAll('.preserve-whitespace');
305+
expect(tooltip).toBeTruthy();
306+
expect(spyTriggerTooltip).toHaveBeenCalled();
307+
308+
columnHeader2.dispatchEvent(focusOutEvent);
309+
fixture.detectChanges();
310+
tick(500);
311+
312+
expect(spyHideTooltip).toHaveBeenCalled();
313+
discardPeriodicTasks();
314+
}));
288315
});
289316

290317
describe('State: populated', () => {

0 commit comments

Comments
 (0)