diff --git a/UNRELEASED.md b/UNRELEASED.md index 6093c4c5402..84ea52d6572 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -67,6 +67,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f - Modernized tests for Konami, Labelled, and Link components([#4389](https://github.com/Shopify/polaris-react/pull/4389)) - 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 ResourceItem, ResourceList ([#4362](https://github.com/Shopify/polaris-react/pull/4362)) - 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)) diff --git a/package.json b/package.json index 6b1edc241ca..3a9356d1c7e 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,7 @@ "@shopify/jest-dom-mocks": "^3.0.5", "@shopify/postcss-plugin": "^3.1.1", "@shopify/prettier-config": "^1.1.2", - "@shopify/react-testing": "^3.2.0", + "@shopify/react-testing": "^3.2.4", "@shopify/storybook-a11y-test": "^0.0.1", "@shopify/stylelint-plugin": "^10.0.1", "@shopify/typescript-configs": "^5.0.0", 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..d02a270171e 100644 --- a/src/components/ResourceItem/tests/ResourceItem.test.tsx +++ b/src/components/ResourceItem/tests/ResourceItem.test.tsx @@ -1,10 +1,4 @@ -import React from 'react'; -// eslint-disable-next-line no-restricted-imports -import { - findByTestID, - mountWithAppProvider, - trigger, -} from 'test-utilities/legacy'; +import React, {AllHTMLAttributes} from 'react'; import {mountWithApp} from 'test-utilities'; import { Avatar, @@ -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,16 @@ describe('', () => { const external = false; const ariaLabel = 'View Item'; + function findResourceItem(wrapper: ReturnType) { + return wrapper!.findWhere<'div'>( + (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 +122,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 +160,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'); + findResourceItem(wrapper)!.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'); + findResourceItem(wrapper)!.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', { + + findResourceItem(wrapper)!.trigger('onClick', { stopPropagation: () => {}, nativeEvent: {metaKey: true}, }); @@ -330,57 +347,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', - }); + findResourceItem(wrapper)!.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', - }); + findResourceItem(wrapper)!.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', - }); - + findResourceItem(wrapper)!.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', { + + findResourceItem(wrapper)!.trigger('onClick', { stopPropagation: () => {}, nativeEvent: {ctrlKey: true}, }); @@ -391,25 +401,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 +438,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'); + findResourceItem(wrapper)!.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', { + findResourceItem(wrapper)!.trigger('onClick', { + stopPropagation: () => {}, nativeEvent: {shiftKey: false}, }); expect(mockSelectModeContext.onSelectionChange).toHaveBeenCalledWith( @@ -465,33 +483,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', { + + findResourceItem(wrapper)!.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', { + + findResourceItem(wrapper)!.trigger('onClick', { + stopPropagation: () => {}, nativeEvent: {ctrlKey: true}, }); expect(spy).not.toHaveBeenCalled(); @@ -500,34 +522,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 +739,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 AllHTMLAttributes); }); + 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..32079166daa 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,10 @@ 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(warningSpy).toHaveBeenCalledWith( ' renderItem function should return a .', ); @@ -78,66 +73,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 +507,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 +532,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 +557,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 +626,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 +743,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 +831,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 +1049,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 +1118,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 +1149,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 +1182,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 +1253,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 +1292,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/yarn.lock b/yarn.lock index a1503bae1fa..4ce74b17d7a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2330,12 +2330,12 @@ resolved "https://registry.yarnpkg.com/@shopify/prettier-config/-/prettier-config-1.1.2.tgz#612f87c0cd1196e8b43c85425e587d0fa7f1172d" integrity sha512-5ugCL9sPGzmOaZjeRGaWUWhHgAbemrS6z+R7v6gwiD+BiqSeoFhIY+imLpfdFCVpuOGalpHeCv6o3gv++EHs0A== -"@shopify/react-testing@^3.2.0": - version "3.2.0" - resolved "https://registry.yarnpkg.com/@shopify/react-testing/-/react-testing-3.2.0.tgz#496c6282d4d947277f53b27b83db00cb35b82705" - integrity sha512-ynBOJ5NyAhEMfgu2Neir2dWE5YoiVzrl3HR7dzmpqqnEsQn6S4AqtMxjDUChPeVxem0o8ey2C0kxuezphGAd4A== +"@shopify/react-testing@^3.2.4": + version "3.2.4" + resolved "https://registry.yarnpkg.com/@shopify/react-testing/-/react-testing-3.2.4.tgz#ecc136533270cbb252147318c3c7e300a02d495d" + integrity sha512-BhQgroiGA6VhPMAwsy2LVdNR1tv7nWkAL4uvW1SDiQEHhJmWJ1AyDq5UXKdWeDhoH3DoZOjALX1SFfLkSdIoKQ== dependencies: - "@shopify/useful-types" "^3.0.1" + "@shopify/useful-types" "^3.0.4" jest-matcher-utils "^26.6.2" react-reconciler "^0.26.2" @@ -2365,10 +2365,10 @@ resolved "https://registry.yarnpkg.com/@shopify/typescript-configs/-/typescript-configs-5.0.0.tgz#4cd1339a6a5ab34e7f7d852d155d2c82b731c152" integrity sha512-1TV9pr3UBr1AlGC//4bdeKiQ2qwDuaqCZGfxO2OtIg/EN3luDdf49UNNm/BL9ZiApHcz7kg9Wklc09vhzD24hw== -"@shopify/useful-types@^3.0.1": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@shopify/useful-types/-/useful-types-3.0.1.tgz#1021459d49917ce5bff6b0cb6c34df44a49375b9" - integrity sha512-aWjLNyxGxNKLYKs3evYrars9h8OV2Apc1DcZqkFETnm7EMeoFv16feV21xdwpQxj2W9EwCpw7CSmlvadzXxHyA== +"@shopify/useful-types@^3.0.4": + version "3.0.4" + resolved "https://registry.yarnpkg.com/@shopify/useful-types/-/useful-types-3.0.4.tgz#6b1f0908f60487550542c75acebea1a4f4eff968" + integrity sha512-uHVbNANIdYgWSF+vgL+H7j3ufyNzAbkHIgL0iYPb/C2OreHC1YaQWeMjjPQobzCb5MxultSPgvAbgWuytm3gCA== "@sinonjs/commons@^1.7.0": version "1.7.1"