diff --git a/polaris-react/src/components/Tooltip/tests/Tooltip.test.tsx b/polaris-react/src/components/Tooltip/tests/Tooltip.test.tsx index b17a4202214..42a4435d49a 100644 --- a/polaris-react/src/components/Tooltip/tests/Tooltip.test.tsx +++ b/polaris-react/src/components/Tooltip/tests/Tooltip.test.tsx @@ -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('', () => { + beforeEach(() => { + testResetHysteresis(); + }); + it('renders its children', () => { const tooltip = mountWithApp( @@ -35,16 +39,94 @@ describe('', () => { expect(tooltipActive.find(TooltipOverlay)).toContainReactComponent('div'); }); + it('renders initially when defaultOpen is true', () => { + const tooltip = mountWithApp( + + link content + , + ); + + expect(tooltip.find(TooltipOverlay)).toContainReactComponent('div'); + }); + it('does not render when active is false', () => { - const tooltipActive = mountWithApp( + const tooltip = mountWithApp( link content , ); - 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( + + link content + , + ); + + expect(tooltip.find(TooltipOverlay)).not.toContainReactComponent('div'); + }); + + it('renders when open is true', () => { + const tooltip = mountWithApp( + + link content + , + ); + + expect(tooltip.find(TooltipOverlay)).toContainReactComponent('div'); + }); + + it('does not render when open is false', () => { + const tooltip = mountWithApp( + + link content + , + ); + + expect(tooltip.find(TooltipOverlay)).not.toContainReactComponent('div'); + }); + + it('renders when open is true and active is false', () => { + const tooltip = mountWithApp( + + link content + , + ); + + expect(tooltip.find(TooltipOverlay)).toContainReactComponent('div'); + }); + + it('renders when open is true and defaultOpen is false', () => { + const tooltip = mountWithApp( + + link content + , + ); + + expect(tooltip.find(TooltipOverlay)).toContainReactComponent('div'); + }); + + it('does not render when open is false and active is true', () => { + const tooltip = mountWithApp( + + link content + , + ); + + expect(tooltip.find(TooltipOverlay)).not.toContainReactComponent('div'); + }); + + it('does not render when open is false and defaultOpen is true', () => { + const tooltip = mountWithApp( + + link content + , ); + + expect(tooltip.find(TooltipOverlay)).not.toContainReactComponent('div'); }); it('does not render when active prop is updated to false', () => { @@ -61,9 +143,23 @@ describe('', () => { expect(tooltip.find(TooltipOverlay)).not.toContainReactComponent('div'); }); + it('renders when defaultOpen prop is updated to false', () => { + const tooltip = mountWithApp( + + link content + , + ); + + 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( - + link content , ); @@ -118,7 +214,7 @@ describe('', () => { it('closes itself when escape is pressed on keyup', () => { const tooltip = mountWithApp( - +
Order #1001
, ); @@ -132,11 +228,11 @@ describe('', () => { }); }); - 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( @@ -151,11 +247,11 @@ describe('', () => { 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( @@ -216,7 +312,7 @@ describe('', () => { const closeSpy = jest.fn(); const tooltip = mountWithApp( - + link content , ); @@ -234,7 +330,7 @@ describe('', () => { const closeSpy = jest.fn(); const tooltip = mountWithApp( - + link content , ); @@ -255,7 +351,7 @@ describe('', () => { link content , @@ -267,7 +363,7 @@ describe('', () => { it("passes 'zIndexOverride' to TooltipOverlay", () => { const tooltip = mountWithApp( - + link content , );