Skip to content

Commit

Permalink
Initial test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronccasanova committed Mar 22, 2024
1 parent fccd38d commit 0a71758
Showing 1 changed file with 110 additions and 14 deletions.
124 changes: 110 additions & 14 deletions polaris-react/src/components/Tooltip/tests/Tooltip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import React from 'react';
import {mountWithApp} from 'tests/utilities';

import {Link} from '../../Link';
import {Tooltip} from '../Tooltip';
import {testResetHysteresis, Tooltip} from '../Tooltip';
import {TooltipOverlay} from '../components';

describe('<Tooltip />', () => {
beforeEach(() => {
testResetHysteresis();
});

it('renders its children', () => {
const tooltip = mountWithApp(
<Tooltip content="Inner content">
Expand Down Expand Up @@ -35,16 +39,94 @@ describe('<Tooltip />', () => {
expect(tooltipActive.find(TooltipOverlay)).toContainReactComponent('div');
});

it('renders initially when defaultOpen is true', () => {
const tooltip = mountWithApp(
<Tooltip content="Inner content" defaultOpen>
<Link>link content</Link>
</Tooltip>,
);

expect(tooltip.find(TooltipOverlay)).toContainReactComponent('div');
});

it('does not render when active is false', () => {
const tooltipActive = mountWithApp(
const tooltip = mountWithApp(
<Tooltip content="Inner content" active={false}>
<Link>link content</Link>
</Tooltip>,
);

expect(tooltipActive.find(TooltipOverlay)).not.toContainReactComponent(
'div',
expect(tooltip.find(TooltipOverlay)).not.toContainReactComponent('div');
});

it('does not render initially when defaultOpen is false', () => {
const tooltip = mountWithApp(
<Tooltip content="Inner content" defaultOpen={false}>
<Link>link content</Link>
</Tooltip>,
);

expect(tooltip.find(TooltipOverlay)).not.toContainReactComponent('div');
});

it('renders when open is true', () => {
const tooltip = mountWithApp(
<Tooltip content="Inner content" open>
<Link>link content</Link>
</Tooltip>,
);

expect(tooltip.find(TooltipOverlay)).toContainReactComponent('div');
});

it('does not render when open is false', () => {
const tooltip = mountWithApp(
<Tooltip content="Inner content" open={false}>
<Link>link content</Link>
</Tooltip>,
);

expect(tooltip.find(TooltipOverlay)).not.toContainReactComponent('div');
});

it('renders when open is true and active is false', () => {
const tooltip = mountWithApp(
<Tooltip content="Inner content" open active={false}>
<Link>link content</Link>
</Tooltip>,
);

expect(tooltip.find(TooltipOverlay)).toContainReactComponent('div');
});

it('renders when open is true and defaultOpen is false', () => {
const tooltip = mountWithApp(
<Tooltip content="Inner content" open defaultOpen={false}>
<Link>link content</Link>
</Tooltip>,
);

expect(tooltip.find(TooltipOverlay)).toContainReactComponent('div');
});

it('does not render when open is false and active is true', () => {
const tooltip = mountWithApp(
<Tooltip content="Inner content" open={false} active>
<Link>link content</Link>
</Tooltip>,
);

expect(tooltip.find(TooltipOverlay)).not.toContainReactComponent('div');
});

it('does not render when open is false and defaultOpen is true', () => {
const tooltip = mountWithApp(
<Tooltip content="Inner content" open={false} defaultOpen>
<Link>link content</Link>
</Tooltip>,
);

expect(tooltip.find(TooltipOverlay)).not.toContainReactComponent('div');
});

it('does not render when active prop is updated to false', () => {
Expand All @@ -61,9 +143,23 @@ describe('<Tooltip />', () => {
expect(tooltip.find(TooltipOverlay)).not.toContainReactComponent('div');
});

it('renders when defaultOpen prop is updated to false', () => {
const tooltip = mountWithApp(
<Tooltip content="Inner content">
<Link>link content</Link>
</Tooltip>,
);

findWrapperComponent(tooltip)!.trigger('onMouseOver');
expect(tooltip.find(TooltipOverlay)).toContainReactComponent('div');

tooltip.setProps({defaultOpen: false});
expect(tooltip.find(TooltipOverlay)).toContainReactComponent('div');
});

it('passes preventInteraction to TooltipOverlay when dismissOnMouseOut is true', () => {
const tooltip = mountWithApp(
<Tooltip dismissOnMouseOut content="Inner content" active>
<Tooltip dismissOnMouseOut content="Inner content">
<Link>link content</Link>
</Tooltip>,
);
Expand Down Expand Up @@ -118,7 +214,7 @@ describe('<Tooltip />', () => {

it('closes itself when escape is pressed on keyup', () => {
const tooltip = mountWithApp(
<Tooltip active content="This order has shipping labels.">
<Tooltip defaultOpen content="This order has shipping labels.">
<div>Order #1001</div>
</Tooltip>,
);
Expand All @@ -132,11 +228,11 @@ describe('<Tooltip />', () => {
});
});

it('does not call onOpen when initially activated', () => {
it('does not call onOpen initially when defaultOpen is true', () => {
const openSpy = jest.fn();
const tooltip = mountWithApp(
<Tooltip
active
defaultOpen
content="This order has shipping labels."
onOpen={openSpy}
>
Expand All @@ -151,11 +247,11 @@ describe('<Tooltip />', () => {
expect(openSpy).not.toHaveBeenCalled();
});

it('calls onClose when initially activated and then closed', () => {
it('calls onClose initially when defaultOpen is true and then closed', () => {
const closeSpy = jest.fn();
const tooltip = mountWithApp(
<Tooltip
active
defaultOpen
content="This order has shipping labels."
onClose={closeSpy}
>
Expand Down Expand Up @@ -216,7 +312,7 @@ describe('<Tooltip />', () => {
const closeSpy = jest.fn();

const tooltip = mountWithApp(
<Tooltip active content="Inner content" onClose={closeSpy}>
<Tooltip defaultOpen content="Inner content" onClose={closeSpy}>
<Link>link content</Link>
</Tooltip>,
);
Expand All @@ -234,7 +330,7 @@ describe('<Tooltip />', () => {
const closeSpy = jest.fn();

const tooltip = mountWithApp(
<Tooltip active content="Inner content" onClose={closeSpy}>
<Tooltip defaultOpen content="Inner content" onClose={closeSpy}>
<Link>link content</Link>
</Tooltip>,
);
Expand All @@ -255,7 +351,7 @@ describe('<Tooltip />', () => {
<Tooltip
accessibilityLabel={accessibilityLabel}
content="Inner content"
active
defaultOpen
>
<Link>link content</Link>
</Tooltip>,
Expand All @@ -267,7 +363,7 @@ describe('<Tooltip />', () => {

it("passes 'zIndexOverride' to TooltipOverlay", () => {
const tooltip = mountWithApp(
<Tooltip active content="Inner content" zIndexOverride={100}>
<Tooltip defaultOpen content="Inner content" zIndexOverride={100}>
<Link>link content</Link>
</Tooltip>,
);
Expand Down

0 comments on commit 0a71758

Please sign in to comment.