Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
- Modernized tests for Modal ([#4433](https://github.com/Shopify/polaris-react/pull/4433))
- Modernized tests for Navigation and Navigation.Section ([#4440](https://github.com/Shopify/polaris-react/pull/4440))
- Modernized tests for EmptyState component ([#4427](https://github.com/Shopify/polaris-react/pull/4427))
- Modernized tests for FilterControl, FilterCreator, FilterValueSelector, and DateSelector components ([#](https://github.com/Shopify/polaris-react/pull/))
- Modernized tests for FilterControl, FilterCreator, FilterValueSelector, and DateSelector components ([#4438](https://github.com/Shopify/polaris-react/pull/4438))
- Modernized tests for Pagination, FilterControl, FilterCreator, FilterValueSelector, and DateSelector components ([#4438](https://github.com/Shopify/polaris-react/pull/4438))
- Modernized tests for PopoverOverlay component([#4430](https://github.com/Shopify/polaris-react/pull/4430))

### Deprecations
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import React, {useRef} from 'react';
// eslint-disable-next-line no-restricted-imports
import {
mountWithAppProvider,
ReactWrapper,
trigger,
} from 'test-utilities/legacy';
import {mountWithApp} from 'test-utilities/react-testing';
import {TextContainer, TextField, EventListener} from 'components';

Expand Down Expand Up @@ -60,7 +54,7 @@ describe('<PopoverOverlay />', () => {
);

it('passes activator to PositionedOverlay when active', () => {
const popoverOverlay = mountWithAppProvider(
const popoverOverlay = mountWithApp(
<PopoverOverlay
active
id="PopoverOverlay-1"
Expand All @@ -72,13 +66,13 @@ describe('<PopoverOverlay />', () => {
</PopoverOverlay>,
);

expect(popoverOverlay.find(PositionedOverlay).prop('activator')).toBe(
expect(popoverOverlay).toContainReactComponent(PositionedOverlay, {
activator,
);
});
});

it('passes fullWidth to PositionedOverlay when active', () => {
const popoverOverlay = mountWithAppProvider(
const popoverOverlay = mountWithApp(
<PopoverOverlay
active
id="PopoverOverlay-1"
Expand All @@ -90,11 +84,13 @@ describe('<PopoverOverlay />', () => {
</PopoverOverlay>,
);

expect(popoverOverlay.find(PositionedOverlay).prop('fullWidth')).toBe(true);
expect(popoverOverlay).toContainReactComponent(PositionedOverlay, {
fullWidth: true,
});
});

it('passes fixed to PositionedOverlay when active', () => {
const popoverOverlay = mountWithAppProvider(
const popoverOverlay = mountWithApp(
<PopoverOverlay
active
id="PopoverOverlay-1"
Expand All @@ -106,11 +102,13 @@ describe('<PopoverOverlay />', () => {
</PopoverOverlay>,
);

expect(popoverOverlay.find(PositionedOverlay).prop('fixed')).toBe(true);
expect(popoverOverlay).toContainReactComponent(PositionedOverlay, {
fixed: true,
});
});

it('passes preferredPosition and preferredAlignment to PositionedOverlay when active', () => {
const popoverOverlay = mountWithAppProvider(
const popoverOverlay = mountWithApp(
<PopoverOverlay
active
id="PopoverOverlay-1"
Expand All @@ -123,16 +121,14 @@ describe('<PopoverOverlay />', () => {
</PopoverOverlay>,
);

expect(
popoverOverlay.find(PositionedOverlay).prop('preferredPosition'),
).toBe('above');
expect(
popoverOverlay.find(PositionedOverlay).prop('preferredAlignment'),
).toBe('right');
expect(popoverOverlay).toContainReactComponent(PositionedOverlay, {
preferredPosition: 'above',
preferredAlignment: 'right',
});
});

it('passes default preferredPosition and preferredAlignment to PositionedOverlay when active', () => {
const popoverOverlay = mountWithAppProvider(
const popoverOverlay = mountWithApp(
<PopoverOverlay
active
id="PopoverOverlay-1"
Expand All @@ -143,16 +139,14 @@ describe('<PopoverOverlay />', () => {
</PopoverOverlay>,
);

expect(
popoverOverlay.find(PositionedOverlay).prop('preferredPosition'),
).toBe('below');
expect(
popoverOverlay.find(PositionedOverlay).prop('preferredAlignment'),
).toBe('center');
expect(popoverOverlay).toContainReactComponent(PositionedOverlay, {
preferredPosition: 'below',
preferredAlignment: 'center',
});
});

it('passes preferInputActivator to PositionedOverlay when false', () => {
const popoverOverlay = mountWithAppProvider(
const popoverOverlay = mountWithApp(
<PopoverOverlay
active
id="PopoverOverlay-1"
Expand All @@ -165,9 +159,9 @@ describe('<PopoverOverlay />', () => {
</PopoverOverlay>,
);

expect(
popoverOverlay.find(PositionedOverlay).prop('preferInputActivator'),
).toBe(false);
expect(popoverOverlay).toContainReactComponent(PositionedOverlay, {
preferInputActivator: false,
});
});

it('passes zIndexOverride to PositionedOverlay', () => {
Expand All @@ -189,7 +183,7 @@ describe('<PopoverOverlay />', () => {
});

it("doesn't include a tabindex prop when autofocusTarget is 'none'", () => {
const popoverOverlay = mountWithAppProvider(
const popoverOverlay = mountWithApp(
<PopoverOverlay
active
id="PopoverOverlay-1"
Expand All @@ -203,15 +197,15 @@ describe('<PopoverOverlay />', () => {
</PopoverOverlay>,
);

expect(
popoverOverlay.find(PositionedOverlay).prop('preferInputActivator'),
).toBe(false);
expect(popoverOverlay).toContainReactComponent(PositionedOverlay, {
preferInputActivator: false,
});
});

it('calls the onClose callback when the escape key is pressed', () => {
const spy = jest.fn();

mountWithAppProvider(
mountWithApp(
<PopoverOverlay
active
id="PopoverOverlay-1"
Expand All @@ -229,7 +223,7 @@ describe('<PopoverOverlay />', () => {
it('does not call the onClose callback when a descendent HTMLElement is clicked', () => {
const spy = jest.fn();

const popoverOverlay = mountWithAppProvider(
const popoverOverlay = mountWithApp(
<PopoverOverlay
active
id="PopoverOverlay-1"
Expand All @@ -240,21 +234,21 @@ describe('<PopoverOverlay />', () => {
</PopoverOverlay>,
);

const target = popoverOverlay.find(TextField).find('input').getDOMNode();
const target = popoverOverlay.find(TextField)!.find('input')!.domNode;

const clickEventListener = popoverOverlay
.find(EventListener)
.findWhere((node) => node.prop('event') === 'click');
const clickEventListener = popoverOverlay.find(EventListener, {
event: 'click',
})!;

trigger(clickEventListener, 'handler', {target});
clickEventListener.trigger('handler', {target});

expect(spy).not.toHaveBeenCalled();
});

it('does not call the onClose callback when a descendent SVGElement is clicked', () => {
const spy = jest.fn();

const popoverOverlay = mountWithAppProvider(
const popoverOverlay = mountWithApp(
<PopoverOverlay
active
id="PopoverOverlay-1"
Expand All @@ -272,25 +266,20 @@ describe('<PopoverOverlay />', () => {
</PopoverOverlay>,
);

const target = popoverOverlay
.find(TextField)
.find('svg')
.first()
.getDOMNode();
const target = popoverOverlay.find(TextField)!.find('svg')!.domNode;

const clickEventListener = popoverOverlay
.find(EventListener)
.findWhere((node) => node.prop('event') === 'click');
const clickEventListener = popoverOverlay.find(EventListener, {
event: 'click',
})!;

trigger(clickEventListener, 'handler', {
clickEventListener!.trigger('handler', {
target,
});

expect(spy).not.toHaveBeenCalled();
});

it('starts animating in immediately', () => {
const popoverOverlay = mountWithAppProvider(
const popoverOverlay = mountWithApp(
<PopoverOverlay
active={false}
id="PopoverOverlay-1"
Expand All @@ -303,16 +292,17 @@ describe('<PopoverOverlay />', () => {
);

popoverOverlay.setProps({active: true});
popoverOverlay.update();
expect(popoverOverlay.find(PositionedOverlay).prop('classNames')).toMatch(
/PopoverOverlay-entering/,
);
popoverOverlay.forceUpdate();

expect(popoverOverlay).toContainReactComponent(PositionedOverlay, {
classNames: expect.stringContaining('PopoverOverlay-entering'),
});
});

it('does not render after exiting when the component is updated during exit', () => {
jest.useFakeTimers();

const popoverOverlay = mountWithAppProvider(
const popoverOverlay = mountWithApp(
<PopoverOverlay
active
id="PopoverOverlay-1"
Expand All @@ -324,16 +314,12 @@ describe('<PopoverOverlay />', () => {
);

// Start exiting
close(popoverOverlay);

// Update before exiting is complete
triggerSomeUpdate(popoverOverlay);

popoverOverlay.setProps({active: false});
// Run any timers and a final update for changed state
jest.runOnlyPendingTimers();
popoverOverlay.update();

expect(popoverOverlay.find(PositionedOverlay)).toHaveLength(0);
popoverOverlay.forceUpdate();
expect(popoverOverlay).not.toContainReactComponent(PositionedOverlay);
});

describe('focus', () => {
Expand All @@ -351,7 +337,7 @@ describe('<PopoverOverlay />', () => {

it('focuses the content on mount', () => {
const focusSpy = jest.spyOn(HTMLElement.prototype, 'focus');
mountWithAppProvider(
mountWithApp(
<PopoverOverlay
active
id="PopoverOverlay-1"
Expand All @@ -369,7 +355,7 @@ describe('<PopoverOverlay />', () => {
it('focuses the content on mount and prevents scroll in development', () => {
process.env.NODE_ENV = 'development';
const focusSpy = jest.spyOn(HTMLElement.prototype, 'focus');
mountWithAppProvider(
mountWithApp(
<PopoverOverlay
active
id="PopoverOverlay-1"
Expand Down Expand Up @@ -476,13 +462,3 @@ describe('<PopoverOverlay />', () => {
});

function noop() {}

function close(wrapper: ReactWrapper) {
wrapper.setProps({active: false});
wrapper.update();
}

function triggerSomeUpdate(wrapper: ReactWrapper) {
wrapper.setProps({fullWidth: true});
wrapper.update();
}