diff --git a/UNRELEASED.md b/UNRELEASED.md index d6fef31e4b1..80fe0ecb908 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -48,7 +48,8 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f - Modernized tests for FormLayout and some components of ColorPicker ([#4330](https://github.com/Shopify/polaris-react/pull/4330)) - Modernized tests for Breadcrumbs, BulkActions, Button, ButtonGroup/Item, and ButtonGroup components([#4315](https://github.com/Shopify/polaris-react/pull/4315)) - Modernized tests for DualThumb ([#4341](https://github.com/Shopify/polaris-react/pull/4341)) -- Modernized tests for AppProvider, AfterInitialMount components([#4331](https://github.com/Shopify/polaris-react/pull/4331)) +- Modernized tests for AppProvider, AfterInitialMount components([#4315](https://github.com/Shopify/polaris-react/pull/4331)) +- Modernized tests for ResourceItem, ResourceList ([#4362](https://github.com/Shopify/polaris-react/pull/4362)) - Modernized tests for SkeletonBodyTest, SkeletonDisplayTest, SkeletonPage, SkeletonThumbnail, and Spinner components ([#4353](https://github.com/Shopify/polaris-react/pull/4353)) - Modernized tests for Message, Menu, Search, SearchDismissOverlay, SearchField, UserMenu and TopBar components. ([#4311](https://github.com/Shopify/polaris-react/pull/4311)) - Modernized tests for Konami, Labelled, and Link components([#4389](https://github.com/Shopify/polaris-react/pull/4389)) diff --git a/src/components/ResourceItem/ResourceItem.tsx b/src/components/ResourceItem/ResourceItem.tsx index a514f1b84e2..74b8ef983c5 100644 --- a/src/components/ResourceItem/ResourceItem.tsx +++ b/src/components/ResourceItem/ResourceItem.tsx @@ -159,9 +159,7 @@ class BaseResourceItem extends Component { let handleMarkup: React.ReactNode = null; const mediaMarkup = media ? ( -
- {media} -
+
{media}
) : null; if (selectable) { @@ -169,15 +167,10 @@ class BaseResourceItem extends Component { name || accessibilityLabel || i18n.translate('Polaris.Common.checkbox'); handleMarkup = ( -
+
{ } else { actionsMarkup = (
- + {buttonsFrom(shortcutActions, { size: 'slim', })} @@ -282,11 +275,7 @@ class BaseResourceItem extends Component { ); const containerMarkup = ( -
+
{ownedMarkup} {content} {actionsMarkup} @@ -335,7 +324,6 @@ class BaseResourceItem extends Component { onBlur={this.handleBlur} onKeyUp={this.handleKeyUp} onMouseOut={this.handleMouseOut} - testID="Item-Wrapper" data-href={url} > {accessibleMarkup} diff --git a/src/components/ResourceItem/tests/ResourceItem.test.tsx b/src/components/ResourceItem/tests/ResourceItem.test.tsx index 3eb66f9fb10..9fdccf5dca9 100644 --- a/src/components/ResourceItem/tests/ResourceItem.test.tsx +++ b/src/components/ResourceItem/tests/ResourceItem.test.tsx @@ -1,11 +1,5 @@ import React from 'react'; -// eslint-disable-next-line no-restricted-imports -import { - findByTestID, - mountWithAppProvider, - trigger, -} from 'test-utilities/legacy'; -import {mountWithApp} from 'test-utilities'; +import {mountWithApp, Node} from 'test-utilities'; import { Avatar, ButtonGroup, @@ -15,8 +9,9 @@ import { Button, } from 'components'; -import {ResourceListContext} from '../../../utilities/resource-list'; import {ResourceItem} from '../ResourceItem'; +import {ResourceListContext} from '../../../utilities/resource-list'; +import styles from '../ResourceItem.scss'; describe('', () => { let spy: jest.SpyInstance; @@ -75,9 +70,12 @@ describe('', () => { const external = false; const ariaLabel = 'View Item'; + const resourceItemFilter = (node: Node) => + node.is('div') && node!.domNode.classList.contains(styles.ResourceItem); + describe('accessibilityLabel', () => { it('is used on the for the aria-label attribute', () => { - const item = mountWithAppProvider( + const item = mountWithApp( ', () => { , ); - expect(item.find(UnstyledLink).prop('aria-label')).toBe( - accessibilityLabel, - ); + expect(item).toContainReactComponent(UnstyledLink, { + 'aria-label': accessibilityLabel, + }); }); }); describe('name', () => { it('is used as the Checkbox label', () => { - const item = mountWithAppProvider( + const item = mountWithApp( ', () => { const expectedLabel = name; - expect(item.find(Checkbox).prop('label')).toBe(expectedLabel); + expect(item).toContainReactComponent(Checkbox, {label: expectedLabel}); }); it('is used on for the aria-label attribute if an `accessibilityLabel` is not provided', () => { - const item = mountWithAppProvider( + const item = mountWithApp( , @@ -120,11 +118,13 @@ describe('', () => { const expectedLabel = `View details for ${name}`; - expect(item.find(UnstyledLink).prop('aria-label')).toBe(expectedLabel); + expect(item).toContainReactComponent(UnstyledLink, { + 'aria-label': expectedLabel, + }); }); it('is used on the disclosure action menu when there are persistent actions', () => { - const item = mountWithAppProvider( + const item = mountWithApp( ', () => { const expectedLabel = `Actions for ${name}`; - expect( - item - .find(Button) - .findWhere( - (node) => - node.prop('plain') && - node.prop('accessibilityLabel') === expectedLabel, - ), - ).toHaveLength(1); + expect(item).toContainReactComponentTimes(Button, 1, { + plain: true, + accessibilityLabel: expectedLabel, + }); }); }); describe('ResourceName.singular', () => { it('is used on for the aria-label attribute if a `name` and `accessibilityLabel` is not provided', () => { - const item = mountWithAppProvider( + const item = mountWithApp( , @@ -161,13 +156,15 @@ describe('', () => { const expectedLabel = `View details for ${mockDefaultContext.resourceName.singular}`; - expect(item.find(UnstyledLink).prop('aria-label')).toBe(expectedLabel); + expect(item).toContainReactComponent(UnstyledLink, { + 'aria-label': expectedLabel, + }); }); }); describe('url', () => { it('does not render an by default', () => { - const element = mountWithAppProvider( + const element = mountWithApp( ', () => { , ); - expect(element.find(UnstyledLink).exists()).toBe(false); + expect(element).not.toContainReactComponent(UnstyledLink); }); it('renders an ', () => { - const element = mountWithAppProvider( + const element = mountWithApp( , ); - expect(element.find(UnstyledLink).exists()).toBe(true); + expect(element).toContainReactComponent(UnstyledLink); }); it('renders an with url', () => { - const element = mountWithAppProvider( + const element = mountWithApp( , ); - expect(element.find(UnstyledLink).prop('url')).toBe(url); + expect(element).toContainReactComponent(UnstyledLink, {url}); }); it('renders an with an aria-label of ariaLabel', () => { - const element = mountWithAppProvider( + const element = mountWithApp( , ); - expect(element.find(UnstyledLink).prop('aria-label')).toBe(ariaLabel); + expect(element).toContainReactComponent(UnstyledLink, { + 'aria-label': ariaLabel, + }); }); it('adds a data-href to the wrapper element', () => { - const element = mountWithAppProvider( + const element = mountWithApp( , ); - expect(findByTestID(element, 'Item-Wrapper').prop('data-href')).toBe(url); + expect(element).toContainReactComponent('div', {'data-href': url} as any); }); }); describe('external', () => { it('renders an with undefined external prop', () => { - const element = mountWithAppProvider( + const element = mountWithApp( , ); - expect(element.find(UnstyledLink).prop('external')).toBeUndefined(); + expect(element).toContainReactComponent(UnstyledLink, { + external: undefined, + }); }); it('renders an with external set to true', () => { - const element = mountWithAppProvider( + const element = mountWithApp( ', () => { , ); - expect(element.find(UnstyledLink).prop('external')).toBe(true); + expect(element).toContainReactComponent(UnstyledLink, { + external: true, + }); }); it('renders an with external set to false', () => { - const element = mountWithAppProvider( + const element = mountWithApp( ', () => { , ); - expect(element.find(UnstyledLink).prop('external')).toBe(false); + expect(element).toContainReactComponent(UnstyledLink, { + external: false, + }); }); }); describe('id', () => { it('is used on the content node and for the description of a link', () => { - const item = mountWithAppProvider( + const item = mountWithApp( ', () => { , ); - expect(findByTestID(item, 'Item-Content').prop('id')).toBe(itemId); - expect(item.find(UnstyledLink).prop('aria-describedby')).toBe(itemId); + expect(item).toContainReactComponent('div', {id: itemId}); + expect(item).toContainReactComponent(UnstyledLink, { + 'aria-describedby': itemId, + }); }); }); describe('onClick()', () => { it('calls onClick when clicking on the item when onClick exists', () => { const onClick = jest.fn(); - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( ', () => { , ); - findByTestID(wrapper, 'Item-Wrapper').simulate('click'); + wrapper.findWhere(resourceItemFilter)!.trigger('onClick', { + stopPropagation: () => {}, + nativeEvent: {}, + }); expect(onClick).toHaveBeenCalledWith(itemId); }); it('calls onClick when clicking on the item when both onClick and url exist', () => { const onClick = jest.fn(); - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( ', () => { , ); - findByTestID(wrapper, 'Item-Wrapper').simulate('click'); + wrapper.findWhere(resourceItemFilter)!.trigger('onClick', { + stopPropagation: () => {}, + nativeEvent: {}, + }); expect(onClick).toHaveBeenCalledWith(itemId); }); it('calls window.open on metaKey + click', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( , ); - const item = findByTestID(wrapper, 'Item-Wrapper'); - trigger(item, 'onClick', { + + wrapper.findWhere(resourceItemFilter)!.trigger('onClick', { stopPropagation: () => {}, nativeEvent: {metaKey: true}, }); @@ -330,57 +343,50 @@ describe('', () => { it('calls onClick when hitting keyUp on the item when onClick and URL exists', () => { const onClick = jest.fn(); - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( , ); - findByTestID(wrapper, 'Item-Wrapper').simulate('keyup', { - key: 'Enter', - }); + wrapper.findWhere(resourceItemFilter)!.trigger('onKeyUp', {key: 'Enter'}); expect(onClick).toHaveBeenCalled(); }); it('does not call onClick when hitting keyUp on non Enter key', () => { const onClick = jest.fn(); - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( , ); - findByTestID(wrapper, 'Item-Wrapper').simulate('keyup', { - key: 'Tab', - }); + wrapper.findWhere(resourceItemFilter)!.trigger('onKeyUp', {key: 'Tab'}); expect(onClick).not.toHaveBeenCalled(); }); it('does not call onClick when hitting keyUp on the item when no URL exists', () => { const onClick = jest.fn(); - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( , ); - findByTestID(wrapper, 'Item-Wrapper').simulate('keyup', { - key: 'Enter', - }); - + wrapper.findWhere(resourceItemFilter)!.trigger('onKeyUp', {key: 'Enter'}); expect(onClick).not.toHaveBeenCalled(); }); it('calls window.open on ctrlKey + click', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( , ); - const item = findByTestID(wrapper, 'Item-Wrapper'); - trigger(item, 'onClick', { + + wrapper.findWhere(resourceItemFilter)!.trigger('onClick', { stopPropagation: () => {}, nativeEvent: {ctrlKey: true}, }); @@ -391,25 +397,29 @@ describe('', () => { describe('Selectable', () => { it('does not call the Item onClick when clicking the LargerSelectionArea', () => { const onClick = jest.fn(); - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( , ); - findByTestID(wrapper, 'LargerSelectionArea').simulate('click'); + wrapper.find('div', {className: styles.Handle})!.trigger('onClick', { + stopPropagation: () => {}, + nativeEvent: {}, + }); expect(onClick).not.toHaveBeenCalled(); }); it('calls onSelectionChange with the id of the item when clicking the LargerSelectionArea', () => { const sortOrder = 0; - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( , ); - findByTestID(wrapper, 'LargerSelectionArea').simulate('click', { + wrapper.find('div', {className: styles.Handle})!.trigger('onClick', { + stopPropagation: () => {}, nativeEvent: {shiftKey: false}, }); expect(mockSelectableContext.onSelectionChange).toHaveBeenCalledWith( @@ -424,7 +434,7 @@ describe('', () => { describe('SelectMode', () => { it('calls onClick when item is clicked', () => { const onClick = jest.fn(); - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( ', () => { , ); - findByTestID(wrapper, 'Item-Wrapper').simulate('click'); + wrapper.findWhere(resourceItemFilter)!.trigger('onClick', { + stopPropagation: () => {}, + nativeEvent: {}, + }); expect(onClick).not.toHaveBeenCalledWith(itemId); }); it('calls onSelectionChange with the id of the item even if url or onClick is present', () => { const onClick = jest.fn(); const sortOrder = 0; - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( ', () => { , ); - findByTestID(wrapper, 'Item-Wrapper').simulate('click', { + wrapper.findWhere(resourceItemFilter)!.trigger('onClick', { + stopPropagation: () => {}, nativeEvent: {shiftKey: false}, }); expect(mockSelectModeContext.onSelectionChange).toHaveBeenCalledWith( @@ -465,33 +479,37 @@ describe('', () => { }); it('renders a checked Checkbox if the item is in the selectedItems context', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( , ); - expect(wrapper.find(Checkbox).props().checked).toBe(true); + expect(wrapper).toContainReactComponent(Checkbox, {checked: true}); }); it('does not call window.open when clicking the item with metaKey', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( , ); - findByTestID(wrapper, 'Item-Wrapper').simulate('click', { + + wrapper.findWhere(resourceItemFilter)!.trigger('onClick', { + stopPropagation: () => {}, nativeEvent: {metaKey: true}, }); expect(spy).not.toHaveBeenCalled(); }); it('does not call window.open when clicking the item with ctrlKey', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( , ); - findByTestID(wrapper, 'Item-Wrapper').simulate('click', { + + wrapper.findWhere(resourceItemFilter)!.trigger('onClick', { + stopPropagation: () => {}, nativeEvent: {ctrlKey: true}, }); expect(spy).not.toHaveBeenCalled(); @@ -500,34 +518,37 @@ describe('', () => { describe('media', () => { it('does not include media if not provided', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( , ); - expect(findByTestID(wrapper, 'Media').exists()).toBe(false); + expect(wrapper).not.toContainReactComponent('div', { + className: styles.Media, + }); }); it('renders a disabled checked Checkbox if loading context is true', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( , ); - expect(wrapper.find(Checkbox).prop('disabled')).toBe(true); + expect(wrapper).toContainReactComponent(Checkbox, {disabled: true}); }); it('includes an if one is provided', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( } /> , ); - expect(findByTestID(wrapper, 'Media').find(Avatar).exists()).toBe(true); + const media = wrapper.find('div', {className: styles.Media}); + expect(media).toContainReactComponent(Avatar); }); it('includes a if one is provided', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( ', () => { /> , ); - expect(findByTestID(wrapper, 'Media').find(Thumbnail).exists()).toBe( - true, - ); + const media = wrapper.find('div', {className: styles.Media}); + expect(media).toContainReactComponent(Thumbnail); }); }); describe('shortcutActions', () => { it('does not render shortcut actions if none are provided', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( , ); - expect(findByTestID(wrapper, 'ShortcutActions').exists()).toBe(false); + expect(wrapper).not.toContainReactComponent('div', { + className: styles.Actions, + }); }); it('renders shortcut actions when some are provided', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( ', () => { /> , ); - expect(findByTestID(wrapper, 'ShortcutActions').exists()).toBe(true); + expect(wrapper).toContainReactComponent('div', { + className: styles.Actions, + }); }); it('renders persistent shortcut actions if persistActions is true', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( ', () => { /> , ); - expect(wrapper.find(ButtonGroup).exists()).toBe(true); + expect(wrapper).toContainReactComponent(ButtonGroup); }); it('does not render while loading', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( ', () => { /> , ); - expect(wrapper.find(ButtonGroup)).toHaveLength(0); + expect(wrapper).not.toContainReactComponent(ButtonGroup); }); }); describe('accessibleMarkup', () => { it('renders with a tab index of -1 when loading is true', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( ', () => { /> , ); - expect(wrapper.find(UnstyledLink).prop('tabIndex')).toBe(-1); + expect(wrapper).toContainReactComponent(UnstyledLink, {tabIndex: -1}); }); it('renders with a tab index of 0 when loading is false', () => { - const wrapper = mountWithAppProvider( + const wrapper = mountWithApp( ', () => { /> , ); - expect(wrapper.find(UnstyledLink).prop('tabIndex')).toBe(0); + expect(wrapper).toContainReactComponent(UnstyledLink, {tabIndex: 0}); }); }); @@ -711,7 +735,7 @@ describe('', () => { describe('dataHref', () => { it('renders a data-href tag on the li when the dataHref prop is specified', () => { - const item = mountWithAppProvider( + const item = mountWithApp( ', () => { , ); - expect(item.find('li').prop('data-href')).toBe('google.com'); + expect(item).toContainReactComponent('li', { + 'data-href': 'google.com', + } as any); }); + it('renders a data-href tag on the li when the dataHref prop is not specified', () => { - const item = mountWithAppProvider( + const item = mountWithApp( ', () => { , ); - expect(item.find('li').prop('data-href')).toBeUndefined(); + expect(item).toContainReactComponent('li', { + 'data-href': undefined, + } as any); }); }); }); diff --git a/src/components/ResourceList/ResourceList.tsx b/src/components/ResourceList/ResourceList.tsx index e3a609fedd9..48ddf77af40 100644 --- a/src/components/ResourceList/ResourceList.tsx +++ b/src/components/ResourceList/ResourceList.tsx @@ -575,9 +575,7 @@ export const ResourceList: ResourceListType = function ResourceList({ ) : null; const headerTitleMarkup = ( -
- {headerTitle()} -
+
{headerTitle()}
); const selectButtonMarkup = isSelectable ? ( @@ -639,7 +637,7 @@ export const ResourceList: ResourceListType = function ResourceList({ isSticky && styles['HeaderWrapper-isSticky'], ); return ( -
+
{headerWrapperOverlay}
diff --git a/src/components/ResourceList/tests/ResourceList.test.tsx b/src/components/ResourceList/tests/ResourceList.test.tsx index a11c9548803..a3047b0828c 100644 --- a/src/components/ResourceList/tests/ResourceList.test.tsx +++ b/src/components/ResourceList/tests/ResourceList.test.tsx @@ -10,16 +10,11 @@ import { EmptyState, } from 'components'; import {mountWithApp} from 'test-utilities'; -// eslint-disable-next-line no-restricted-imports -import { - findByTestID, - mountWithAppProvider, - trigger, -} from 'test-utilities/legacy'; import {SELECT_ALL_ITEMS} from 'utilities/resource-list'; import {BulkActions} from '../../BulkActions'; import {CheckableButton} from '../../CheckableButton'; +import styles from '../ResourceList.scss'; const itemsNoID = [{url: 'item 1'}, {url: 'item 2'}]; const singleItemNoID = [{url: 'item 1'}]; @@ -53,10 +48,10 @@ const defaultWindowWidth = window.innerWidth; describe('', () => { describe('renderItem', () => { it('renders list items', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(resourceList.find('li')).toHaveLength(3); + expect(resourceList).toContainReactComponentTimes('li', 3); }); it('renders custom markup and warns user', () => { @@ -64,10 +59,11 @@ describe('', () => { const warningSpy = jest .spyOn(console, 'warn') .mockImplementation(() => {}); - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(resourceList.find('li').first().text()).toBe('title 1'); + expect(resourceList).toContainReactText('title 1'); + // expect(resourceList.find('li').first().text()).toBe('title 1'); expect(warningSpy).toHaveBeenCalledWith( ' renderItem function should return a .', ); @@ -78,66 +74,65 @@ describe('', () => { describe('Selectable', () => { it('does not render bulk actions if the promotedBulkActions and the bulkActions props are not provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(resourceList.find(BulkActions).exists()).toBe(false); + expect(resourceList).not.toContainReactComponent(BulkActions); }); it('does not render a `CheckableButton` if the `selectable` prop is not provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(resourceList.find(CheckableButton).exists()).toBe(false); + expect(resourceList).not.toContainReactComponent(CheckableButton); }); it('does render bulk actions if the promotedBulkActions prop is provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - - expect(resourceList.find(BulkActions).exists()).toBe(true); + expect(resourceList).toContainReactComponent(BulkActions); }); it('renders bulk actions if the bulkActions prop is provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(resourceList.find(BulkActions).exists()).toBe(true); + expect(resourceList).toContainReactComponent(BulkActions); }); it('renders a `CheckableButton` if the `selectable` prop is true', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(resourceList.find(CheckableButton).exists()).toBe(true); + expect(resourceList).toContainReactComponent(CheckableButton); }); }); describe('hasMoreItems', () => { it('does not add a prop of paginatedSelectAllAction to BulkActions if omitted', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect( - resourceList.find(BulkActions).prop('paginatedSelectAllAction'), - ).toBeUndefined(); + expect(resourceList).toContainReactComponent(BulkActions, { + paginatedSelectAllAction: undefined, + }); }); it('adds a prop of paginatedSelectAllAction to BulkActions if included', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); expect( - resourceList.find(BulkActions).prop('paginatedSelectAllAction'), - ).toBeDefined(); + resourceList.find(BulkActions)!.props.paginatedSelectAllAction, + ).not.toBeUndefined(); }); }); describe('resourceName', () => { describe('resoureName.singular', () => { it('renders default singular resource name when resourceName isn’t provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(findByTestID(resourceList, 'headerTitleWrapper').text()).toBe( - 'Showing 1 item', - ); + const headerTitleWrapper = resourceList.find('div', { + className: styles.HeaderTitleWrapper, + }); + expect(headerTitleWrapper).toContainReactText('Showing 1 item'); }); it('renders the given singular resource name when resourceName is provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { showHeader />, ); - expect(findByTestID(resourceList, 'headerTitleWrapper').text()).toBe( - 'Showing 1 product', - ); + const headerTitleWrapper = resourceList.find('div', { + className: styles.HeaderTitleWrapper, + }); + expect(headerTitleWrapper).toContainReactText('Showing 1 product'); }); }); - describe('resoureName.plural', () => { + describe('resourceName.plural', () => { it('renders default plural resource name when resourceName isn’t provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(findByTestID(resourceList, 'headerTitleWrapper').text()).toBe( - 'Showing 2 items', - ); + const headerTitleWrapper = resourceList.find('div', { + className: styles.HeaderTitleWrapper, + }); + expect(headerTitleWrapper).toContainReactText('Showing 2 items'); }); it('renders the given plural resource name when resourceName is provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { showHeader />, ); - expect(findByTestID(resourceList, 'headerTitleWrapper').text()).toBe( - 'Showing 2 products', - ); + const headerTitleWrapper = resourceList.find('div', { + className: styles.HeaderTitleWrapper, + }); + expect(headerTitleWrapper).toContainReactText('Showing 2 products'); }); }); }); describe('headerTitle', () => { it('prints loading text when loading is true', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect(findByTestID(resourceList, 'headerTitleWrapper').text()).toBe( - 'Loading items', - ); + const headerTitleWrapper = resourceList.find('div', { + className: styles.HeaderTitleWrapper, + }); + expect(headerTitleWrapper).toContainReactText('Loading items'); }); it('prints number of items shown when totalItemsCount is not provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect(findByTestID(resourceList, 'headerTitleWrapper').text()).toBe( - 'Showing 2 products', - ); + const headerTitleWrapper = resourceList.find('div', { + className: styles.HeaderTitleWrapper, + }); + expect(headerTitleWrapper).toContainReactText('Showing 2 products'); }); it('prints number of items shown of totalItemsCount when totalItemsCount is provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect(findByTestID(resourceList, 'headerTitleWrapper').text()).toBe( - 'Showing 2 of 5 products', - ); + const headerTitleWrapper = resourceList.find('div', { + className: styles.HeaderTitleWrapper, + }); + expect(headerTitleWrapper).toContainReactText('Showing 2 of 5 products'); }); it('prints number of items shown of totalItemsCount plural when totalItemsCount is provided and items is one resource', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect(findByTestID(resourceList, 'headerTitleWrapper').text()).toBe( - 'Showing 1 of 5 products', - ); + const headerTitleWrapper = resourceList.find('div', { + className: styles.HeaderTitleWrapper, + }); + expect(headerTitleWrapper).toContainReactText('Showing 1 of 5 products'); }); }); describe('bulkActionsAccessibilityLabel', () => { it('provides the BulkActions with the right accessibilityLabel if there’s 1 item and it isn’t selected', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(resourceList.find(BulkActions).prop('accessibilityLabel')).toBe( - 'Select item', - ); + expect(resourceList).toContainReactComponent(BulkActions, { + accessibilityLabel: 'Select item', + }); }); it('provides the BulkActions with the right accessibilityLabel if there’s 1 item and it is selected', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { selectedItems={['1']} />, ); - expect(resourceList.find(BulkActions).prop('accessibilityLabel')).toBe( - 'Deselect item', - ); + expect(resourceList).toContainReactComponent(BulkActions, { + accessibilityLabel: 'Deselect item', + }); }); it('provides the BulkActions with the right accessibilityLabel if there are multiple items and they are selected', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { selectedItems={['5', '6', '7']} />, ); - expect(resourceList.find(BulkActions).prop('accessibilityLabel')).toBe( - 'Deselect all 3 items', - ); + expect(resourceList).toContainReactComponent(BulkActions, { + accessibilityLabel: 'Deselect all 3 items', + }); }); + it('provides the BulkActions with the right accessibilityLabel if there’s multiple items and some or none are selected', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(resourceList.find(BulkActions).prop('accessibilityLabel')).toBe( - 'Select all 3 items', - ); + expect(resourceList).toContainReactComponent(BulkActions, { + accessibilityLabel: 'Select all 3 items', + }); }); }); describe('onSelectionChange()', () => { it('calls onSelectionChange() when an item is clicked', () => { const onSelectionChange = jest.fn(); - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { onSelectionChange={onSelectionChange} />, ); - const firstItem = resourceList.find(ResourceItem).first(); - findByTestID(firstItem, 'LargerSelectionArea').simulate('click'); + resourceList.find('div', {className: styles.Handle})!.trigger('onClick', { + stopPropagation: () => {}, + nativeEvent: {}, + }); expect(onSelectionChange).toHaveBeenCalled(); }); }); describe('header markup', () => { it('renders header markup if the list isn’t selectable but the showHeader prop is true', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(findByTestID(resourceList, 'ResourceList-Header').exists()).toBe( - true, - ); + expect(resourceList).toContainReactComponent('div', { + className: styles.HeaderWrapper, + }); }); it('doesn’t render header markup if the list is selectable but the showHeader prop is false', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { renderItem={renderItem} />, ); - expect(findByTestID(resourceList, 'ResourceList-Header').exists()).toBe( - false, - ); + expect(resourceList).not.toContainReactComponent('div', { + className: expect.stringContaining(styles.HeaderWrapper), + }); }); it('does not render when items is empty', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - - expect(findByTestID(resourceList, 'ResourceList-Header').exists()).toBe( - false, - ); + expect(resourceList).not.toContainReactComponent('div', { + className: expect.stringContaining(styles.HeaderWrapper), + }); }); it('renders when sort options are given', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { renderItem={renderItem} />, ); - expect(findByTestID(resourceList, 'ResourceList-Header').exists()).toBe( - true, - ); + expect(resourceList).toContainReactComponent('div', { + className: expect.stringContaining(styles.HeaderWrapper), + }); }); it('renders when an alternateTool is provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(findByTestID(resourceList, 'ResourceList-Header').exists()).toBe( - true, - ); + expect(resourceList).toContainReactComponent('div', { + className: expect.stringContaining(styles.HeaderWrapper), + }); }); it('renders when bulkActions are given', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(findByTestID(resourceList, 'ResourceList-Header').exists()).toBe( - true, - ); + expect(resourceList).toContainReactComponent('div', { + className: expect.stringContaining(styles.HeaderWrapper), + }); }); it('renders when promotedBulkActions are given', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(findByTestID(resourceList, 'ResourceList-Header').exists()).toBe( - true, - ); + expect(resourceList).toContainReactComponent('div', { + className: expect.stringContaining(styles.HeaderWrapper), + }); }); it('does not render when sort options, bulkActions and promotedBulkActions are not given', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(findByTestID(resourceList, 'ResourceList-Header').exists()).toBe( - false, - ); + expect(resourceList).not.toContainReactComponent('div', { + className: expect.stringContaining(styles.HeaderWrapper), + }); }); it('renders on non-initial load when items are provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - - expect(findByTestID(resourceList, 'ResourceList-Header')).toHaveLength(0); + // initially not rendered + expect(resourceList).not.toContainReactComponent('div', { + className: expect.stringContaining(styles.HeaderWrapper), + }); + // update props resourceList.setProps({items: itemsWithID}); - resourceList.update(); - expect(findByTestID(resourceList, 'ResourceList-Header')).toHaveLength(1); + // now it's rendered + expect(resourceList).toContainReactComponent('div', { + className: expect.stringContaining(styles.HeaderWrapper), + }); }); it('does not render when EmptySearchResult exists', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( fake filterControl
} />, ); - - expect(resourceList.find(EmptySearchResult).exists()).toBe(true); - expect(findByTestID(resourceList, 'ResourceList-Header')).toHaveLength(0); + expect(resourceList).toContainReactComponent(EmptySearchResult); + expect(resourceList).not.toContainReactComponent('div', { + className: expect.stringContaining(styles.HeaderWrapper), + }); }); }); describe('filterControl', () => { it('renders when exists', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( Test
} />, ); - expect(resourceList.find('#test123').exists()).toBe(true); + expect(resourceList).toContainReactComponent('div', {id: 'test123'}); }); }); @@ -497,7 +508,7 @@ describe('', () => { ); - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect(resourceList.find(EmptyState)).toHaveLength(1); + expect(resourceList).toContainReactComponentTimes(EmptyState, 1); }); it('does not render when exists but items are provided', () => { @@ -522,7 +533,7 @@ describe('', () => { ); - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect(resourceList.find(EmptyState)).toHaveLength(0); + expect(resourceList).not.toContainReactComponent(EmptyState); }); it('does not render when exists, items is empty, but loading is true', () => { @@ -547,7 +558,7 @@ describe('', () => { ); - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect(resourceList.find(EmptyState)).toHaveLength(0); + expect(resourceList).not.toContainReactComponent(EmptyState); }); }); describe('', () => { it('renders when filterControl exists and items is empty', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( fake filterControl
} />, ); - expect(resourceList.find(EmptySearchResult).exists()).toBe(true); + expect(resourceList).toContainReactComponent(EmptySearchResult); }); it('does not render when filterControl does not exist', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(resourceList.find(EmptySearchResult).exists()).toBe(false); + expect(resourceList).not.toContainReactComponent(EmptySearchResult); }); it('does not render when items is not empty', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( Test
} />, ); - expect(resourceList.find(EmptySearchResult).exists()).toBe(false); + expect(resourceList).not.toContainReactComponent(EmptySearchResult); }); it('does not render when filterControl exists, items is empty, and loading is true', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { loading />, ); - expect(resourceList.find(EmptySearchResult).exists()).toBe(false); + expect(resourceList).not.toContainReactComponent(EmptySearchResult); }); it('does not render when filterControl exists, items is empty, and emptyState is set', () => { @@ -616,7 +627,7 @@ describe('', () => { ); - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect(resourceList.find(EmptySearchResult).exists()).toBe(false); + expect(resourceList).not.toContainReactComponent(EmptySearchResult); }); it('renders the provided markup when emptySearchState is set', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect(resourceList.find(EmptySearchResult).exists()).toBe(false); - expect(resourceList.find('div#emptySearchState').exists()).toBe(true); + expect(resourceList).not.toContainReactComponent(EmptySearchResult); + expect(resourceList).toContainReactComponent('div', { + id: 'emptySearchState', + }); }); }); describe('Sorting', () => { it('does not render a sort select if sortOptions aren’t provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(resourceList.find(Select).exists()).toBe(false); + expect(resourceList).not.toContainReactComponent(Select); }); it('renders a sort select if sortOptions are provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { renderItem={renderItem} />, ); - expect(resourceList.find(Select).exists()).toBe(true); + expect(resourceList).toContainReactComponent(Select); }); it('does not render a sort select if an alternateTool is provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { alternateTool={alternateTool} />, ); - expect(resourceList.find(Select).exists()).toBe(false); + expect(resourceList).not.toContainReactComponent(Select); }); describe('sortOptions', () => { it('passes a sortOptions to the Select options', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { renderItem={renderItem} />, ); - expect(resourceList.find(Select).props()).toHaveProperty( - 'options', - sortOptions, - ); + expect(resourceList).toContainReactComponent(Select, { + options: sortOptions, + }); }); }); describe('sortValue', () => { it('passes a sortValue to the Select value', () => { const onSortChange = jest.fn(); - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { renderItem={renderItem} />, ); - expect(resourceList.find(Select).props()).toHaveProperty( - 'value', - 'sortValue', - ); + expect(resourceList).toContainReactComponent(Select, { + value: 'sortValue', + }); }); }); describe('onSortChange', () => { it('calls onSortChange when the Sort Select changes', () => { const onSortChange = jest.fn(); - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { renderItem={renderItem} />, ); - trigger(resourceList.find(Select), 'onChange', 'PRODUCT_TITLE_DESC'); + resourceList.find(Select)!.trigger('onChange', 'PRODUCT_TITLE_DESC'); expect(onSortChange).toHaveBeenCalledWith('PRODUCT_TITLE_DESC'); }); }); @@ -733,25 +744,29 @@ describe('', () => { describe('Alternate Tool', () => { it('does not render if an alternateTool is not provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(resourceList.find('#AlternateTool').exists()).toBe(false); + expect(resourceList).not.toContainReactComponent('div', { + id: 'AlternateTool', + }); }); it('renders if an alternateTool is provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( , ); - expect(resourceList.find('#AlternateTool').exists()).toBe(true); + expect(resourceList).toContainReactComponent('div', { + id: 'AlternateTool', + }); }); it('renders even if sortOptions are provided', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { alternateTool={alternateTool} />, ); - expect(resourceList.find('#AlternateTool').exists()).toBe(true); + expect(resourceList).toContainReactComponent('div', { + id: 'AlternateTool', + }); }); describe('sortOptions', () => { it('passes a sortOptions to the Select options', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { onSortChange={noop} />, ); - expect(resourceList.find(Select).props()).toHaveProperty( - 'options', - sortOptions, - ); + expect(resourceList).toContainReactComponent(Select, { + options: sortOptions, + }); }); }); describe('sortValue', () => { it('passes a sortValue to the Select value', () => { const onSortChange = jest.fn(); - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { renderItem={renderItem} />, ); - expect(resourceList.find(Select).props()).toHaveProperty( - 'value', - 'sortValue', - ); + expect(resourceList).toContainReactComponent(Select, { + value: 'sortValue', + }); }); }); describe('onSortChange', () => { it('calls onSortChange when the Sort Select changes', () => { const onSortChange = jest.fn(); - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { renderItem={renderItem} />, ); - trigger(resourceList.find(Select), 'onChange', 'PRODUCT_TITLE_DESC'); + resourceList.find(Select)!.trigger('onChange', 'PRODUCT_TITLE_DESC'); expect(onSortChange).toHaveBeenCalledWith('PRODUCT_TITLE_DESC'); }); }); @@ -817,7 +832,7 @@ describe('', () => { describe('loading', () => { it('renders a spinner', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect(resourceList.find(Spinner).exists()).toBe(true); + expect(resourceList).toContainReactComponent(Spinner); }); it('renders a spinner after initial load when loading is true', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { ); resourceList.setProps({loading: true}); - expect(resourceList.find(Spinner).exists()).toBe(true); + expect(resourceList).toContainReactComponent(Spinner); }); it('does not render an if loading is true and there are no items', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect(resourceList.find(ResourceItem)).toHaveLength(0); + expect(resourceList).not.toContainReactComponent(ResourceItem); }); }); describe('BulkActions', () => { it('renders on initial load when items are selected', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { selectedItems={['1']} />, ); - expect(resourceList.find(BulkActions)).toHaveLength(1); + expect(resourceList).toContainReactComponentTimes(BulkActions, 1); }); it('enables select mode when items are programmatically selected', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect(resourceList.find(BulkActions).prop('selectMode')).toBe(false); + expect(resourceList).toContainReactComponent(BulkActions, { + selectMode: false, + }); resourceList.setProps({selectedItems: ['1']}); - resourceList.update(); - expect(resourceList.find(BulkActions).prop('selectMode')).toBe(true); + expect(resourceList).toContainReactComponent(BulkActions, { + selectMode: true, + }); }); it('disables select mode when items are deselected programmatically selected', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect(resourceList.find(BulkActions).prop('selectMode')).toBe(true); + expect(resourceList).toContainReactComponent(BulkActions, { + selectMode: true, + }); resourceList.setProps({selectedItems: []}); - resourceList.update(); - expect(resourceList.find(BulkActions).prop('selectMode')).toBe(false); + expect(resourceList).toContainReactComponent(BulkActions, { + selectMode: false, + }); }); describe('focus', () => { @@ -1029,7 +1050,7 @@ describe('', () => { return item.id; } const onSelectionChange = jest.fn(); - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { resolveItemId={resolveItemId} />, ); - const firstItem = resourceList.find(ResourceItem).first(); - findByTestID(firstItem, 'LargerSelectionArea').simulate('click'); - - const lastItem = resourceList.find(ResourceItem).last(); - findByTestID(lastItem, 'LargerSelectionArea').simulate('click', { + const firstItem = resourceList.find(ResourceItem); + firstItem!.find('div', {className: styles.Handle})!.trigger('onClick', { + stopPropagation: () => {}, + nativeEvent: {}, + }); + const allItems = resourceList.findAll(ResourceItem); + const lastItem = allItems[allItems.length - 1]; + lastItem!.find('div', {className: styles.Handle})!.trigger('onClick', { + stopPropagation: () => {}, nativeEvent: {shiftKey: true}, }); - expect(onSelectionChange).toHaveBeenCalledWith(['5', '6', '7']); }); it('does not select shift selected items if resolveItemId was not provided', () => { const onSelectionChange = jest.fn(); - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { onSelectionChange={onSelectionChange} />, ); - const firstItem = resourceList.find(ResourceItem).first(); - findByTestID(firstItem, 'LargerSelectionArea').simulate('click'); - - const lastItem = resourceList.find(ResourceItem).last(); - findByTestID(lastItem, 'LargerSelectionArea').simulate('click', { + const firstItem = resourceList.find(ResourceItem); + firstItem!.find('div', {className: styles.Handle})!.trigger('onClick', { + stopPropagation: () => {}, + nativeEvent: {}, + }); + const allItems = resourceList.findAll(ResourceItem); + const lastItem = allItems[allItems.length - 1]; + lastItem!.find('div', {className: styles.Handle})!.trigger('onClick', { + stopPropagation: () => {}, nativeEvent: {shiftKey: true}, }); @@ -1091,7 +1119,7 @@ describe('', () => { } const onSelectionChange = jest.fn(); - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { resolveItemId={resolveItemId} />, ); - const firstItem = resourceList.find(ResourceItem).first(); - findByTestID(firstItem, 'LargerSelectionArea').simulate('click'); - - const lastItem = resourceList.find(ResourceItem).last(); - findByTestID(lastItem, 'LargerSelectionArea').simulate('click', { + const firstItem = resourceList.find(ResourceItem); + firstItem!.find('div', {className: styles.Handle})!.trigger('onClick', { + stopPropagation: () => {}, + nativeEvent: {}, + }); + const allItems = resourceList.findAll(ResourceItem); + const lastItem = allItems[allItems.length - 1]; + lastItem!.find('div', {className: styles.Handle})!.trigger('onClick', { + stopPropagation: () => {}, nativeEvent: {shiftKey: true}, }); @@ -1118,7 +1150,7 @@ describe('', () => { return item.id; } const onSelectionChange = jest.fn(); - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { resolveItemId={resolveItemId} />, ); - // Sets {lastSeleced: 0} - const firstItem = resourceList.find(ResourceItem).first(); - findByTestID(firstItem, 'LargerSelectionArea').simulate('click'); - - const lastItem = resourceList.find(ResourceItem).last(); - findByTestID(lastItem, 'LargerSelectionArea').simulate('click', { + // Sets {lastSelected: 0} + const firstItem = resourceList.find(ResourceItem); + firstItem!.find('div', {className: styles.Handle})!.trigger('onClick', { + stopPropagation: () => {}, + nativeEvent: {}, + }); + const allItems = resourceList.findAll(ResourceItem); + const lastItem = allItems[allItems.length - 1]; + lastItem!.find('div', {className: styles.Handle})!.trigger('onClick', { + stopPropagation: () => {}, nativeEvent: {shiftKey: true}, }); @@ -1147,7 +1183,7 @@ describe('', () => { }); it('an inline label is hidden on small screen', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { ); setSmallScreen(); - trigger(resourceList.find(EventListener), 'handler'); - - expect(resourceList.find(Select).first().prop('labelInline')).toBe(false); + resourceList.find(EventListener)!.trigger('handler'); + expect(resourceList).toContainReactComponent(Select, { + labelInline: false, + }); }); it('select mode is turned off on large screen when no items are selected', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - trigger(resourceList.find(BulkActions), 'onSelectModeToggle', true); - trigger(resourceList.find(EventListener).first(), 'handler'); - expect(resourceList.find(BulkActions).prop('selectMode')).toBe(false); + resourceList.find(BulkActions)!.trigger('onSelectModeToggle', true); + resourceList.find(EventListener)!.trigger('handler'); + expect(resourceList).toContainReactComponent(BulkActions, { + selectMode: false, + }); }); }); describe('isFiltered', () => { it('renders `selectAllFilteredItems` label if true', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect( - resourceList.find(BulkActions).prop('paginatedSelectAllAction'), - ).toStrictEqual({ - content: 'Select all 2+ customers in this filter', - onAction: expect.any(Function), + expect(resourceList).toContainReactComponent(BulkActions, { + paginatedSelectAllAction: { + content: 'Select all 2+ customers in this filter', + onAction: expect.any(Function), + }, }); }); @@ -1215,13 +1254,13 @@ describe('', () => { resourceList.find(BulkActions)!.find(Button)!.trigger('onClick'); - expect( - resourceList.find(BulkActions)!.prop('paginatedSelectAllText'), - ).toBe('All 2+ customers in this filter are selected.'); + expect(resourceList).toContainReactComponent(BulkActions, { + paginatedSelectAllText: 'All 2+ customers in this filter are selected.', + }); }); it('renders `selectAllItems` label if not passed', () => { - const resourceList = mountWithAppProvider( + const resourceList = mountWithApp( ', () => { />, ); - expect( - resourceList.find(BulkActions).prop('paginatedSelectAllAction'), - ).toStrictEqual({ - content: 'Select all 2+ customers in your store', - onAction: expect.any(Function), + expect(resourceList).toContainReactComponent(BulkActions, { + paginatedSelectAllAction: { + content: 'Select all 2+ customers in your store', + onAction: expect.any(Function), + }, }); }); @@ -1254,9 +1293,9 @@ describe('', () => { resourceList.find(BulkActions)!.find(Button)!.trigger('onClick'); - expect( - resourceList.find(BulkActions)!.prop('paginatedSelectAllText'), - ).toBe('All 2+ customers in your store are selected.'); + expect(resourceList).toContainReactComponent(BulkActions, { + paginatedSelectAllText: 'All 2+ customers in your store are selected.', + }); }); }); }); diff --git a/src/test-utilities/react-testing.tsx b/src/test-utilities/react-testing.tsx index c4142e30cc6..6d690992f36 100644 --- a/src/test-utilities/react-testing.tsx +++ b/src/test-utilities/react-testing.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import {createMount, mount} from '@shopify/react-testing'; +import {createMount, mount, Node} from '@shopify/react-testing'; import translations from '../../locales/en.json'; import { @@ -8,6 +8,7 @@ import { } from '../components'; export {createMount, mount}; +export type {Node}; export const mountWithApp = createMount< WithPolarisTestProviderOptions,