Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit f5f1bd8

Browse files
Shi Shucopybara-github
authored andcommitted
test(tooltip): Add unit tests to check for anchor element click event register/deregister for persistent rich tooltips in the component.
PiperOrigin-RevId: 346618440
1 parent c5dda80 commit f5f1bd8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/mdc-tooltip/test/component.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,35 @@ describe('MDCTooltip', () => {
458458
document.body.removeChild(fixture);
459459
});
460460

461+
it('#initialSyncWithDOM registers click event handler on the anchor element',
462+
() => {
463+
const tooltipElem = fixture.querySelector<HTMLElement>('#tt0')!;
464+
const anchorElem =
465+
fixture.querySelector<HTMLElement>('[aria-describedby]')!;
466+
const component = MDCTooltip.attachTo(tooltipElem);
467+
const foundation = component['foundation'];
468+
spyOn(foundation, 'handleAnchorClick');
469+
470+
emitEvent(anchorElem, 'click');
471+
472+
expect(foundation.handleAnchorClick).toHaveBeenCalled();
473+
component.destroy();
474+
});
475+
476+
it('#destroy deregisters click event handler on the anchor element', () => {
477+
const tooltipElem = fixture.querySelector<HTMLElement>('#tt0')!;
478+
const anchorElem =
479+
fixture.querySelector<HTMLElement>('[aria-describedby]')!;
480+
const component = MDCTooltip.attachTo(tooltipElem);
481+
const foundation = component['foundation'];
482+
spyOn(foundation, 'handleAnchorClick');
483+
484+
component.destroy();
485+
emitEvent(anchorElem, 'click');
486+
487+
expect(foundation.handleAnchorClick).not.toHaveBeenCalled();
488+
});
489+
461490
it('aria-expanded remains false on anchor when mouseenter anchor', () => {
462491
const tooltipElem = fixture.querySelector<HTMLElement>('#tt0')!;
463492
const anchorElem =

0 commit comments

Comments
 (0)