Skip to content

Commit 861c453

Browse files
committed
test(tooltip): add tests for role switching and transient anchor behavior
1 parent c3eb8b6 commit 861c453

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/components/tooltip/tooltip.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,21 @@ describe('Tooltip', () => {
387387
await hideComplete();
388388
expect(tooltip.open).to.be.false;
389389
});
390+
391+
it('should switch role to "status" when `sticky` is true, and back to "tooltip" when false', async () => {
392+
expect(tooltip.sticky).to.be.false;
393+
tooltip.sticky = true;
394+
await elementUpdated(tooltip);
395+
396+
let internalsRole = (tooltip as any)._internals.role;
397+
expect(internalsRole).to.equal('status');
398+
399+
tooltip.sticky = false;
400+
await elementUpdated(tooltip);
401+
402+
internalsRole = (tooltip as any)._internals.role;
403+
expect(internalsRole).to.equal('tooltip');
404+
});
390405
});
391406

392407
describe('Methods` Tests', () => {
@@ -455,6 +470,30 @@ describe('Tooltip', () => {
455470
DIFF_OPTIONS
456471
);
457472
});
473+
474+
it('calls `show` with a new target, switches anchor, and resets anchor on hide', async () => {
475+
const buttons = Array.from(
476+
tooltip.parentElement!.querySelectorAll('button')
477+
);
478+
479+
const [firstAnchor, secondAnchor] = buttons;
480+
481+
let result = await tooltip.show(firstAnchor);
482+
expect(result).to.be.true;
483+
expect(tooltip.open).to.be.true;
484+
485+
result = await tooltip.show(secondAnchor);
486+
expect(result).to.be.true;
487+
expect(tooltip.open).to.be.true;
488+
489+
result = await tooltip.hide();
490+
expect(result).to.be.true;
491+
expect(tooltip.open).to.be.false;
492+
493+
// The controller's anchor should be null since the anchor is transient
494+
const controllerAnchor = (tooltip as any)._controller.anchor;
495+
expect(controllerAnchor).to.be.null;
496+
});
458497
});
459498

460499
describe('Behaviors', () => {

0 commit comments

Comments
 (0)