Skip to content

Commit

Permalink
chore(popover): added new tests for NaN and < 0
Browse files Browse the repository at this point in the history
  • Loading branch information
nickonometry committed Feb 28, 2024
1 parent 46159c5 commit 3b92516
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/lib/popover/popover-foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ export class PopoverFoundation extends BaseClass implements IPopoverFoundation {
return this._hoverDelay;
}
public set hoverDelay(value: number) {
if (isNaN(value) || value < 0) {
value = POPOVER_CONSTANTS.defaults.HOVER_DELAY;
}
if (this._hoverDelay !== value) {
this._hoverDelay = value;
this._adapter.setHostAttribute(POPOVER_CONSTANTS.attributes.HOVER_DELAY, String(this._hoverDelay));
Expand Down
24 changes: 17 additions & 7 deletions src/lib/popover/popover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,15 +701,25 @@ describe('Popover', () => {
});

it('should open with a delay when hovering over the trigger button and a delay is set', async () => {
const harness = await createFixture({ triggerType: 'hover', hoverDelay: 500 });
const harness = await createFixture({ triggerType: 'hover', hoverDelay: 500 });

expect(harness.isOpen).to.be.false;
expect(harness.isOpen).to.be.false;

await harness.hoverTrigger();
await timer(harness.popoverElement.hoverDelay);

expect(harness.isOpen).to.be.true;
});

await harness.hoverTrigger();
await timer(harness.popoverElement.hoverDelay);
it('should set the default hoverDelay value if NaN', async () => {
const harness = await createFixture({ triggerType: 'hover', hoverDelay: 'Testing' });
expect(harness.popoverElement.hoverDelay).to.equal(0);
});

expect(harness.isOpen).to.be.true;
});
it('should set the default hoverDelay value if the hoverDelay < 0', async () => {
const harness = await createFixture({ triggerType: 'hover', hoverDelay: -400 });
expect(harness.popoverElement.hoverDelay).to.equal(0);
});

it('should not close if persistent hover is enabled', async () => {
const harness = await createFixture({ triggerType: 'hover', persistentHover: true });
Expand Down Expand Up @@ -1440,7 +1450,7 @@ interface IPopoverFixtureConfig {
animationType?: PopoverAnimationType;
triggerType?: PopoverTriggerType;
persistentHover?: boolean;
hoverDelay?: number;
hoverDelay?: any;
}

async function createFixture({
Expand Down

0 comments on commit 3b92516

Please sign in to comment.