diff --git a/UNRELEASED.md b/UNRELEASED.md
index 6093c4c5402..49eb9708e36 100644
--- a/UNRELEASED.md
+++ b/UNRELEASED.md
@@ -63,8 +63,9 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
- Modernized tests for SkeletonBodyTest, SkeletonDisplayTest, SkeletonPage, SkeletonThumbnail, and Spinner components ([#4353](https://github.com/Shopify/polaris-react/pull/4353))
- Modernized tests for CalloutCard, Caption, CheckableButton, Resizer, VideoThumbnail ([#4387](https://github.com/Shopify/polaris-react/pull/4387))
- Modernized tests for Message, Menu, Search, SearchDismissOverlay, SearchField, UserMenu and TopBar components. ([#4311](https://github.com/Shopify/polaris-react/pull/4311))
-- Modernized test for UnstyledLink, Tag, DisplayText, FileUpload, MessageIndicator, Choice and Dialog ([#4407](https://github.com/Shopify/polaris-react/pull/4407)).
+- Modernized tests for UnstyledLink, Tag, DisplayText, FileUpload, MessageIndicator, Choice and Dialog ([#4407](https://github.com/Shopify/polaris-react/pull/4407)).
- Modernized tests for Konami, Labelled, and Link components([#4389](https://github.com/Shopify/polaris-react/pull/4389))
+- Modernized tests for TextStyle, Collapsible, Tabs ([#4453](https://github.com/Shopify/polaris-react/pull/4453))
- Modernized tests for Scrollable, ScrollTo, ScrollLock, Select, SettingToggle, Sheet, Spinner, and Sticky components([#4386](https://github.com/Shopify/polaris-react/pull/4386))
- 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))
diff --git a/src/components/Collapsible/tests/Collapsible.test.tsx b/src/components/Collapsible/tests/Collapsible.test.tsx
index da0fcae4a7b..eab1eb5f433 100644
--- a/src/components/Collapsible/tests/Collapsible.test.tsx
+++ b/src/components/Collapsible/tests/Collapsible.test.tsx
@@ -1,80 +1,85 @@
import React, {useState, useCallback} from 'react';
-// eslint-disable-next-line no-restricted-imports
-import {mountWithAppProvider} from 'test-utilities/legacy';
import {mountWithApp} from 'test-utilities';
import {Tokens} from 'utilities/theme';
import {Collapsible, CollapsibleProps} from '../Collapsible';
describe('', () => {
- const ariaExpandedSelector = '[aria-expanded=false]';
-
it('does not render its children and indicates hidden with aria-hidden', () => {
- const collapsible = mountWithAppProvider(
+ const collapsible = mountWithApp(
content
,
);
- const hidden = collapsible.find(ariaExpandedSelector);
- expect(hidden.exists()).toBe(true);
+ expect(collapsible).toContainReactComponent('div', {
+ 'aria-expanded': false,
+ });
});
it('renders its children and does not render aria-hidden when open', () => {
- const collapsible = mountWithAppProvider(
+ const collapsible = mountWithApp(
content
,
);
- const hidden = collapsible.find(ariaExpandedSelector);
- expect(hidden.exists()).toBe(false);
- expect(collapsible.contains('content')).toBe(true);
+ expect(collapsible).not.toContainReactComponent('div', {
+ 'aria-expanded': false,
+ });
+
+ expect(collapsible).toContainReactText('content');
});
it('does not render its children when closed', () => {
- const collapsible = mountWithAppProvider(
+ const collapsible = mountWithApp(
content
,
);
- expect(collapsible.contains('content')).toBe(false);
+ expect(collapsible).not.toContainReactComponent('div', {
+ children: expect.stringContaining('content'),
+ });
});
it('renders its children when expandOnPrint is true and open is false', () => {
- const collapsible = mountWithAppProvider(
+ const collapsible = mountWithApp(
content
,
);
- expect(collapsible.contains('content')).toBe(true);
+ expect(collapsible).toContainReactComponent('div', {
+ children: expect.stringContaining('content'),
+ });
});
it('renders its children when expandOnPrint is true and open is true', () => {
- const collapsible = mountWithAppProvider(
+ const collapsible = mountWithApp(
content
,
);
- expect(collapsible.contains('content')).toBe(true);
+ expect(collapsible).toContainReactComponent('div', {
+ children: expect.stringContaining('content'),
+ });
});
describe('Transition', () => {
it('passes a duration property', () => {
const duration = Tokens.duration150;
- const collapsible = mountWithAppProvider(
+ const collapsible = mountWithApp(
,
);
- expect(collapsible.props()).toMatchObject({transition: {duration}});
+ expect(collapsible).toHaveReactProps({transition: {duration}});
});
it('passes a timingFunction property', () => {
const timingFunction = Tokens.ease;
- const collapsible = mountWithAppProvider(
+ const collapsible = mountWithApp(
', () => {
/>,
);
- expect(collapsible.props()).toMatchObject({transition: {timingFunction}});
+ expect(collapsible).toHaveReactProps({transition: {timingFunction}});
});
});
diff --git a/src/components/Tabs/tests/Tabs.test.tsx b/src/components/Tabs/tests/Tabs.test.tsx
index 36da14082fd..fa4ce11ea26 100644
--- a/src/components/Tabs/tests/Tabs.test.tsx
+++ b/src/components/Tabs/tests/Tabs.test.tsx
@@ -1,6 +1,4 @@
import React from 'react';
-// eslint-disable-next-line no-restricted-imports
-import {mountWithAppProvider, trigger} from 'test-utilities/legacy';
import {mountWithApp} from 'test-utilities';
import {Tab, Panel, TabMeasurer} from '../components';
@@ -95,10 +93,12 @@ describe('', () => {
{content: 'Tab 1', id: 'tab-1'},
{content: 'Tab 2', id: 'tab-2'},
];
- const wrapper = mountWithAppProvider();
+ const wrapper = mountWithApp();
- tabs.forEach((tab, index) => {
- expect(wrapper.find('ul').find(Tab).at(index).prop('id')).toBe(tab.id);
+ tabs.forEach((tab) => {
+ expect(wrapper.find('ul')!).toContainReactComponent(Tab, {
+ id: tab.id,
+ });
});
});
@@ -108,38 +108,37 @@ describe('', () => {
{...tabs[1], panelID: 'panel-2'},
];
const content =
Panel contents
;
- const wrapper = mountWithAppProvider(
+ const wrapper = mountWithApp(
{content}
,
);
- panelIDedTabs.forEach((tab, index) => {
- expect(wrapper.find('ul').find(Tab).at(index).prop('panelID')).toBe(
- tab.panelID,
- );
+ panelIDedTabs.forEach((tab) => {
+ expect(wrapper.find('ul')!).toContainReactComponent(Tab, {
+ panelID: tab.panelID,
+ });
});
});
it('uses an auto-generated panelID if none is provided', () => {
const content = Panel contents
;
- const wrapper = mountWithAppProvider(
- {content},
- );
+ const wrapper = mountWithApp({content});
tabs.forEach((_, index) => {
- const panelID = wrapper.find('ul').find(Tab).at(index).prop('panelID');
+ const panelID = wrapper.find('ul')!.findAll(Tab)[index].prop('panelID');
expect(typeof panelID).toBe('string');
expect(panelID).not.toBe('');
});
});
it('sets the panelID to undefined when the tab does not have an associated panel (child)', () => {
- const wrapper = mountWithAppProvider();
+ const wrapper = mountWithApp();
tabs.forEach((_, index) => {
- const panelID = wrapper.find('ul').find(Tab).at(index).prop('panelID');
- expect(panelID).toBeUndefined();
+ expect(wrapper.find('ul')!.findAll(Tab)[index]).toHaveReactProps({
+ panelID: undefined,
+ });
});
});
@@ -148,14 +147,12 @@ describe('', () => {
{...tabs[0], url: 'https://shopify.com'},
{...tabs[1], url: 'https://google.com'},
];
- const wrapper = mountWithAppProvider(
- ,
- );
+ const wrapper = mountWithApp();
urlTabs.forEach((tab, index) => {
- expect(
- wrapper.find('ul').find(Tab).at(index).prop('url'),
- ).toStrictEqual(tab.url);
+ expect(wrapper.find('ul')!.findAll(Tab)[index]).toHaveReactProps({
+ url: tab.url,
+ });
});
});
@@ -164,14 +161,12 @@ describe('', () => {
{...tabs[0], accessibilityLabel: 'Tab 1'},
{...tabs[1], accessibilityLabel: 'Tab 2'},
];
- const wrapper = mountWithAppProvider(
- ,
- );
+ const wrapper = mountWithApp();
labelledTabs.forEach((tab, index) => {
- expect(
- wrapper.find('ul').find(Tab).at(index).prop('accessibilityLabel'),
- ).toStrictEqual(tab.accessibilityLabel);
+ expect(wrapper.find('ul')!.findAll(Tab)[index]).toHaveReactProps({
+ accessibilityLabel: tab.accessibilityLabel,
+ });
});
});
@@ -180,14 +175,14 @@ describe('', () => {
{content: 'Tab 1', id: 'tab-1'},
{content: 'Tab 2', id: 'tab-2'},
];
- const wrapper = mountWithAppProvider(
+ const wrapper = mountWithApp(
,
);
tabsWithContent.forEach((tab, index) => {
- expect(
- wrapper.find('ul').find(Tab).at(index).prop('children'),
- ).toStrictEqual(tab.content);
+ expect(wrapper.find('ul')!.findAll(Tab)[index]).toHaveReactProps({
+ children: tab!.content,
+ });
});
});
@@ -203,14 +198,14 @@ describe('', () => {
id: 'tab-2',
},
];
- const wrapper = mountWithAppProvider(
+ const wrapper = mountWithApp(
,
);
tabsWithContent.forEach((tab, index) => {
- expect(
- wrapper.find('ul').find(Tab).at(index).prop('children'),
- ).toStrictEqual(tab.content);
+ expect(wrapper.find('ul')!.findAll(Tab)[index]).toHaveReactProps({
+ children: tab.content,
+ });
});
});
});
@@ -235,7 +230,7 @@ describe('', () => {
{...tabs[1], panelID: 'panel-2'},
];
- const wrapper = mountWithAppProvider(
+ const wrapper = mountWithApp(
Panel contents
,
@@ -248,35 +243,26 @@ describe('', () => {
describe('panel', () => {
it('renders a Panel for each of the Tabs', () => {
const content = Tab content
;
- const wrapper = mountWithAppProvider(
- {content},
- );
- const panel = wrapper.find(Panel);
- expect(panel).toHaveLength(2);
+ const wrapper = mountWithApp({content});
+ expect(wrapper).toContainReactComponentTimes(Panel, 2);
});
it('renders a Panel with a hidden prop for the non selected tabs', () => {
const content = Tab content
;
- const wrapper = mountWithAppProvider(
- {content},
- );
+ const wrapper = mountWithApp({content});
- const nonSelectedPanel = wrapper.find(Panel).at(1);
- expect(nonSelectedPanel.prop('hidden')).toBe(true);
+ expect(wrapper.findAll(Panel)[1]).toHaveReactProps({hidden: true});
});
it('wraps the children in a Panel with matching aria attributes to the tab', () => {
const content = Tab content
;
- const wrapper = mountWithAppProvider(
- {content},
- );
+ const wrapper = mountWithApp({content});
+
+ const selectedTab = wrapper.find('ul')!.findAll(Tab)[0];
+ const panel = wrapper.findAll(Panel)[0];
- const selectedTab = wrapper.find('ul').find(Tab).at(0);
- const panel = wrapper.find(Panel).at(0);
- expect(panel.exists()).toBe(true);
- expect(panel.contains(content)).toBe(true);
- expect(panel.prop('id')).toBeTruthy();
- expect(panel.prop('id')).toBe(selectedTab.prop('panelID'));
+ expect(panel).toContainReactComponent('p', {children: 'Tab content'});
+ expect(panel).toHaveReactProps({id: selectedTab.prop('panelID')});
});
it('uses a custom panelID', () => {
@@ -285,25 +271,23 @@ describe('', () => {
tabs[1],
];
const content = Tab content
;
- const wrapper = mountWithAppProvider(
+ const wrapper = mountWithApp(
{content}
,
);
- const panel = wrapper.find(Panel).at(0);
- const selectedTab = wrapper.find('ul').find(Tab).at(0);
- expect(panel.prop('id')).toBe(selectedTab.prop('panelID'));
+ const panel = wrapper.findAll(Panel)[0];
+ const selectedTab = wrapper.find('ul')!.findAll(Tab)[0];
+ expect(panel).toHaveReactProps({id: selectedTab.prop('panelID')});
});
});
describe('onSelect()', () => {
it('is called with the index of the clicked tab', () => {
const spy = jest.fn();
- const wrapper = mountWithAppProvider(
- ,
- );
- wrapper.find('ul').find(Tab).at(1).find('button').simulate('click');
+ const wrapper = mountWithApp();
+ wrapper.find('ul')!.findAll(Tab)[1].find('button')!.trigger('onClick');
expect(spy).toHaveBeenCalledWith(1);
});
});
@@ -316,57 +300,52 @@ describe('', () => {
];
it('is not set to anything by default', () => {
- const tabs = mountWithAppProvider();
- expect(tabs.find(TabMeasurer).prop('tabToFocus')).toBe(-1);
+ const tabs = mountWithApp();
+ expect(tabs.find(TabMeasurer)).toHaveReactProps({tabToFocus: -1});
});
it('passes the provided selected value if given', () => {
- const tabs = mountWithAppProvider(
+ const tabs = mountWithApp(
,
);
- expect(tabs.find(TabMeasurer).prop('selected')).toBe(1);
+ expect(tabs.find(TabMeasurer)).toHaveReactProps({selected: 1});
});
describe('ArrowRight', () => {
it('shifts focus to the next tab when pressing ArrowRight', () => {
- const tabs = mountWithAppProvider(
- ,
- );
- trigger(tabs.find('ul'), 'onKeyUp', {
+ const tabs = mountWithApp();
+ tabs.find('ul')!.trigger('onKeyUp', {
key: 'ArrowRight',
});
- expect(tabs.find(TabMeasurer).prop('tabToFocus')).toBe(0);
+ expect(tabs.find(TabMeasurer)).toHaveReactProps({tabToFocus: 0});
});
it('shifts focus to the first tab when pressing ArrowRight on the last tab', () => {
- const tabs = mountWithAppProvider(
- ,
- );
- trigger(tabs.find('ul'), 'onKeyUp', {
+ const tabs = mountWithApp();
+ tabs.find('ul')!.trigger('onKeyUp', {
key: 'ArrowRight',
});
- trigger(tabs.find('ul'), 'onKeyUp', {
+ tabs.find('ul')!.trigger('onKeyUp', {
key: 'ArrowRight',
});
- trigger(tabs.find('ul'), 'onKeyUp', {
+ tabs.find('ul')!.trigger('onKeyUp', {
key: 'ArrowRight',
});
- trigger(tabs.find('ul'), 'onKeyUp', {
+
+ tabs.find('ul')!.trigger('onKeyUp', {
key: 'ArrowRight',
});
- expect(tabs.find(TabMeasurer).prop('tabToFocus')).toBe(0);
+ expect(tabs.find(TabMeasurer)).toHaveReactProps({tabToFocus: 0});
});
});
describe('ArrowLeft', () => {
it('shifts focus to the last tab when pressing ArrowLeft', () => {
- const tabs = mountWithAppProvider(
- ,
- );
- trigger(tabs.find('ul'), 'onKeyUp', {
+ const tabs = mountWithApp();
+ tabs.find('ul')!.trigger('onKeyUp', {
key: 'ArrowLeft',
});
- expect(tabs.find(TabMeasurer).prop('tabToFocus')).toBe(2);
+ expect(tabs.find(TabMeasurer)).toHaveReactProps({tabToFocus: 2});
});
});
});
@@ -408,108 +387,100 @@ describe('', () => {
});
it('passes preferredPosition below to the Popover', () => {
- const tabs = mountWithAppProvider();
- const tabMeasurer = tabs.find(TabMeasurer);
- trigger(tabMeasurer, 'handleMeasurement', {
+ const tabs = mountWithApp();
+ tabs.find(TabMeasurer)!.trigger('handleMeasurement', {
hiddenTabWidths: [82, 160, 150, 100, 80, 120],
containerWidth: 300,
disclosureWidth: 0,
});
- const popover = tabs.find(Popover);
- expect(popover.prop('preferredPosition')).toBe('below');
+ expect(tabs.find(Popover)).toHaveReactProps({preferredPosition: 'below'});
});
it('renders with a button as the activator when there are hiddenTabs', () => {
- const tabs = mountWithAppProvider();
- const tabMeasurer = tabs.find(TabMeasurer);
- trigger(tabMeasurer, 'handleMeasurement', {
+ const tabs = mountWithApp();
+ tabs.find(TabMeasurer)!.trigger('handleMeasurement', {
hiddenTabWidths: [82, 160, 150, 100, 80, 120],
containerWidth: 300,
disclosureWidth: 0,
});
- const popover = tabs.find(Popover);
- expect(popover.prop('activator').type).toBe('button');
+ expect(tabs.find(Popover)!.prop('activator').type).toBe('button');
});
describe('ArrowRight', () => {
it('shifts focus to the first tab when pressing ArrowRight', () => {
- const tabs = mountWithAppProvider();
- const tabMeasurer = tabs.find(TabMeasurer);
- trigger(tabMeasurer, 'handleMeasurement', {
+ const tabs = mountWithApp();
+ tabs.find(TabMeasurer)!.trigger('handleMeasurement', {
hiddenTabWidths: [82, 160, 150, 100, 80, 120],
containerWidth: 300,
disclosureWidth: 0,
});
- const popover = tabs.find(Popover);
- const disclosureActivator = popover.find('.DisclosureActivator');
-
- trigger(disclosureActivator, 'onClick', {
- key: 'Enter',
- });
+ tabs.find(Popover)!.find('button')!.trigger('onClick');
- trigger(tabs.find('ul'), 'onKeyUp', {
+ tabs.find('ul')!.trigger('onKeyUp', {
key: 'ArrowRight',
});
- expect(tabs.find(TabMeasurer).prop('tabToFocus')).toBe(0);
+ expect(tabs).toContainReactComponent(TabMeasurer, {tabToFocus: 0});
});
it('shifts focus to the first hidden tab when the last visible tab is focused and the disclosure popover is active', () => {
- const tabs = mountWithAppProvider();
- const tabMeasurer = tabs.find(TabMeasurer);
- trigger(tabMeasurer, 'handleMeasurement', {
+ const tabs = mountWithApp();
+
+ tabs.find(TabMeasurer)!.trigger('handleMeasurement', {
hiddenTabWidths: [82, 160, 150, 100, 80, 120],
containerWidth: 300,
disclosureWidth: 0,
});
- const popover = tabs.find(Popover);
- const disclosureActivator = popover.find('button');
- disclosureActivator.simulate('click');
+ const popover = tabs.find(Popover)!;
+ const disclosureActivator = popover.find('button')!;
- trigger(disclosureActivator, 'onClick', {
- key: 'Enter',
- });
+ disclosureActivator.trigger('onClick');
- trigger(tabs.find('ul'), 'onKeyUp', {
+ tabs.find('ul')!.trigger('onKeyUp', {
key: 'ArrowRight',
});
- expect(tabs.find(TabMeasurer).prop('tabToFocus')).toBe(0);
+ expect(tabs.find(TabMeasurer)!.prop('tabToFocus')).toBe(0);
- trigger(tabs.find('ul'), 'onKeyUp', {
+ tabs.find('ul')!.trigger('onKeyUp', {
key: 'ArrowRight',
});
- expect(tabs.find(TabMeasurer).prop('tabToFocus')).toBe(1);
+ expect(tabs.find(TabMeasurer)!.prop('tabToFocus')).toBe(1);
});
it('does not shift focus to the first hidden tab when the last visible tab is focused and the disclosure popover is not active', () => {
- const tabs = mountWithAppProvider();
- const tabMeasurer = tabs.find(TabMeasurer);
- trigger(tabMeasurer, 'handleMeasurement', {
+ const tabs = mountWithApp();
+
+ tabs.find(TabMeasurer)!.trigger('handleMeasurement', {
hiddenTabWidths: [82, 160, 150, 100, 80, 120],
containerWidth: 300,
disclosureWidth: 0,
});
- const popover = tabs.find(Popover);
- expect(popover.prop('active')).toBe(false);
+ expect(tabs).toContainReactComponent(Popover, {
+ active: false,
+ });
- trigger(tabs.find('ul'), 'onKeyUp', {
+ tabs.find('ul')!.trigger('onKeyUp', {
key: 'ArrowRight',
});
- expect(tabs.find(TabMeasurer).prop('tabToFocus')).toBe(0);
+ expect(tabs).toContainReactComponent(TabMeasurer, {
+ tabToFocus: 0,
+ });
- trigger(tabs.find('ul'), 'onKeyUp', {
+ tabs.find('ul')!.trigger('onKeyUp', {
key: 'Enter',
});
- expect(tabs.find(TabMeasurer).prop('tabToFocus')).toBe(0);
+ expect(tabs).toContainReactComponent(TabMeasurer, {
+ tabToFocus: 0,
+ });
});
});
});
diff --git a/src/components/TextStyle/tests/TextStyle.test.tsx b/src/components/TextStyle/tests/TextStyle.test.tsx
index 149e51c3a92..5a428287eb7 100644
--- a/src/components/TextStyle/tests/TextStyle.test.tsx
+++ b/src/components/TextStyle/tests/TextStyle.test.tsx
@@ -1,61 +1,56 @@
import React from 'react';
-// eslint-disable-next-line no-restricted-imports
-import {mountWithAppProvider} from 'test-utilities/legacy';
+import {mountWithApp} from 'test-utilities';
import {TextStyle} from '../TextStyle';
describe('', () => {
it('mounts', () => {
- const textStyle = mountWithAppProvider();
- expect(textStyle.exists()).toBe(true);
+ const textStyle = mountWithApp();
+ expect(textStyle).not.toBeNull();
});
it('renders children', () => {
- const textStyle = mountWithAppProvider(
- Hello Polaris,
- );
- expect(textStyle.find('span').text()).toBe('Hello Polaris');
+ const textStyle = mountWithApp(Hello Polaris);
+ expect(textStyle.find('span')).toContainReactText('Hello Polaris');
});
it('renders a span by default', () => {
- const textStyle = mountWithAppProvider(
- Hello Polaris,
- );
- expect(textStyle.find('span')).toHaveLength(1);
+ const textStyle = mountWithApp(Hello Polaris);
+ expect(textStyle).toContainReactComponent('span');
});
it('renders a span when the variant positive is provided', () => {
- const textStyle = mountWithAppProvider(
+ const textStyle = mountWithApp(
Hello Polaris,
);
- expect(textStyle.find('span')).toHaveLength(1);
+ expect(textStyle).toContainReactComponent('span');
});
it('renders a span when the variant negative is provided', () => {
- const textStyle = mountWithAppProvider(
+ const textStyle = mountWithApp(
Hello Polaris,
);
- expect(textStyle.find('span')).toHaveLength(1);
+ expect(textStyle).toContainReactComponent('span');
});
it('renders a span when the variant subdued is provided', () => {
- const textStyle = mountWithAppProvider(
+ const textStyle = mountWithApp(
Hello Polaris,
);
- expect(textStyle.find('span')).toHaveLength(1);
+ expect(textStyle).toContainReactComponent('span');
});
it('renders a span tag when the strong variant is provided', () => {
- const textStyle = mountWithAppProvider(
+ const textStyle = mountWithApp(
Hello Polaris,
);
- expect(textStyle.find('span')).toHaveLength(1);
+ expect(textStyle).toContainReactComponent('span');
});
it('renders a code tag when the code variant is provided', () => {
- const textStyle = mountWithAppProvider(
+ const textStyle = mountWithApp(
Hello Polaris,
);
- expect(textStyle.find('code')).toHaveLength(1);
+ expect(textStyle).toContainReactComponent('code');
});
});