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
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
- Modernized tests for Message, Menu, Search, SearchDismissOverlay, SearchField, UserMenu and TopBar components. ([#4311](https://github.com/Shopify/polaris-react/pull/4311))
- Modernized tests for MediaCard, and Layout components ([#4393](https://github.com/Shopify/polaris-react/pull/4393))
- Modernized tests for Image and Icon components ([#4418](https://github.com/Shopify/polaris-react/pull/4418))
- Modernized tests for EventListener and EmptySearch components([#4423](https://github.com/Shopify/polaris-react/pull/4423))

### Deprecations
27 changes: 12 additions & 15 deletions src/components/EmptySearchResult/tests/EmptySearchResult.test.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
import React from 'react';
// eslint-disable-next-line no-restricted-imports
import {mountWithAppProvider} from 'test-utilities/legacy';
import {mountWithApp} from 'test-utilities';
import {DisplayText, TextStyle} from 'components';

import {EmptySearchResult} from '../EmptySearchResult';
import {emptySearch} from '../illustrations';

describe('<EmptySearchResult />', () => {
it("displays the title with style 'Display Small'", () => {
const wrapper = mountWithAppProvider(<EmptySearchResult title="Foo" />);
const wrapper = mountWithApp(<EmptySearchResult title="Foo" />);
const displaySmalls = wrapper.findWhere(
(wrap) => wrap.is(DisplayText) && wrap.prop('size') === 'small',
);
expect(displaySmalls).toHaveLength(1);
expect(displaySmalls.first().text()).toBe('Foo');

expect(wrapper).toContainReactComponent(DisplayText, {size: 'small'});
expect(displaySmalls).toContainReactText('Foo');
});

it("displays the description with style 'Body Subdued'", () => {
const wrapper = mountWithAppProvider(
const wrapper = mountWithApp(
<EmptySearchResult title="Foo" description="Bar" />,
);
const subdued = wrapper.findWhere(
(wrap) => wrap.is(TextStyle) && wrap.prop('variation') === 'subdued',
);
expect(subdued).toHaveLength(1);
expect(subdued.first().text()).toBe('Bar');
expect(wrapper).toContainReactComponent(TextStyle, {variation: 'subdued'});
expect(subdued).toContainReactText('Bar');
});

it('does not display an image when `withIllustration` is false', () => {
const wrapper = mountWithAppProvider(<EmptySearchResult title="Foo" />);
const images = wrapper.find('img');
expect(images).toHaveLength(0);
const wrapper = mountWithApp(<EmptySearchResult title="Foo" />);
expect(wrapper).not.toContainReactComponent('img');
});

it('displays the illustration when `withIllustration` is true', () => {
const wrapper = mountWithAppProvider(
const wrapper = mountWithApp(
<EmptySearchResult title="Foo" description="Bar" withIllustration />,
);
const images = wrapper.find('img');
expect(images).toHaveLength(1);
expect(images.first().prop('src')).toBe(emptySearch);
expect(wrapper).toContainReactComponentTimes('img', 1, {src: emptySearch});
});
});
13 changes: 5 additions & 8 deletions src/components/EventListener/tests/EventListener.test.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import React from 'react';
// eslint-disable-next-line no-restricted-imports
import {mountWithAppProvider} from 'test-utilities/legacy';
import {mountWithApp} from 'test-utilities';

import {EventListener} from '../EventListener';

describe('<EventListener />', () => {
it('calls handler when the resize event is fired', () => {
const spy = jest.fn();
mountWithAppProvider(<EventListener event="resize" handler={spy} />);
mountWithApp(<EventListener event="resize" handler={spy} />);
window.dispatchEvent(new Event('resize'));
expect(spy).toHaveBeenCalled();
});

it('does not call handler when a different event is fired', () => {
const spy = jest.fn();
mountWithAppProvider(<EventListener event="click" handler={spy} />);
mountWithApp(<EventListener event="click" handler={spy} />);
window.dispatchEvent(new Event('resize'));
expect(spy).not.toHaveBeenCalled();
});

it('removes listener on update', () => {
const spy = jest.fn();
const eventListener = mountWithAppProvider(
const eventListener = mountWithApp(
<EventListener event="resize" handler={spy} />,
);
eventListener.setProps({event: 'scroll', handler: noop});
Expand All @@ -31,9 +30,7 @@ describe('<EventListener />', () => {

it('removes listener when unmounted', () => {
const spy = jest.fn();
mountWithAppProvider(
<EventListener event="resize" handler={spy} />,
).unmount();
mountWithApp(<EventListener event="resize" handler={spy} />).unmount();
window.dispatchEvent(new Event('resize'));
expect(spy).not.toHaveBeenCalled();
});
Expand Down