diff --git a/UNRELEASED.md b/UNRELEASED.md index 98fd56384c5..def97f2ef8b 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -57,5 +57,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f - Modernized tests for Message, Menu, Search, SearchDismissOverlay, SearchField, UserMenu and TopBar components. ([#4311](https://github.com/Shopify/polaris-react/pull/4311)) - Modernized tests for 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 MediaCard, and Layout components ([#4393](https://github.com/Shopify/polaris-react/pull/4393)) ### Deprecations diff --git a/src/components/Layout/components/AnnotatedSection/AnnotatedSection.tsx b/src/components/Layout/components/AnnotatedSection/AnnotatedSection.tsx index 2222c279ca0..353f0972fa5 100644 --- a/src/components/Layout/components/AnnotatedSection/AnnotatedSection.tsx +++ b/src/components/Layout/components/AnnotatedSection/AnnotatedSection.tsx @@ -22,14 +22,9 @@ export function AnnotatedSection(props: AnnotatedSectionProps) {
- - {title} - + {title} {descriptionMarkup && ( -
+
{descriptionMarkup}
)} diff --git a/src/components/Layout/tests/Layout.test.tsx b/src/components/Layout/tests/Layout.test.tsx index 51035235184..eaedfc6339b 100644 --- a/src/components/Layout/tests/Layout.test.tsx +++ b/src/components/Layout/tests/Layout.test.tsx @@ -1,103 +1,113 @@ import React from 'react'; -// eslint-disable-next-line no-restricted-imports -import {findByTestID, mountWithAppProvider} from 'test-utilities/legacy'; +import {mountWithApp} from 'test-utilities'; +import {TextContainer} from 'components/TextContainer'; +import {Heading} from 'components/Heading'; +import styles from 'Layout.scss'; import {Section} from '../components'; import {Layout} from '../Layout'; describe('', () => { it('renders children', () => { - const layout = mountWithAppProvider( + const layout = mountWithApp( , ); - expect(layout.find(MyComponent).exists()).toBe(true); + expect(layout).toContainReactComponent(MyComponent); }); it('renders children wrapped in a section', () => { - const layout = mountWithAppProvider( + const layout = mountWithApp( , ); - const section = layout.find(Section); - expect(section.exists()).toBe(true); - expect(section.find(MyComponent).exists()).toBe(true); + expect(layout).toContainReactComponent(Section); + expect(layout.find(Section)).toContainReactComponent(MyComponent); }); describe('', () => { it('renders children', () => { - const annotatedSection = mountWithAppProvider( + const annotatedSection = mountWithApp( , ); - expect(annotatedSection.find(MyComponent).exists()).toBe(true); + expect(annotatedSection).toContainReactComponent(MyComponent); }); it('renders a title', () => { const title = 'Store details'; - const annotatedSection = mountWithAppProvider( - , + const annotatedSection = mountWithApp( + , ); - - expect(findByTestID(annotatedSection, 'AnnotationTitle').text()).toBe( + expect(annotatedSection.find(Heading, {id: 'someId'})).toContainReactText( title, ); }); it('renders a description as a string', () => { const description = 'A good description of this section'; - const annotatedSection = mountWithAppProvider( + const annotatedSection = mountWithApp( , ); - expect( - findByTestID(annotatedSection, 'AnnotationDescription').text(), - ).toBe(description); + const annotedDescriptionTextContainer = annotatedSection.find( + TextContainer, + )!; + + expect(annotedDescriptionTextContainer.find('div')).toContainReactText( + description, + ); }); it('renders a description as a node', () => { - const annotatedSection = mountWithAppProvider( + const annotatedSection = mountWithApp( } />, ); - const annotatedDescription = findByTestID( - annotatedSection, - 'AnnotationDescription', - ); - expect(annotatedDescription.find(MyComponent).exists()).toBe(true); + const annotedDescriptionTextContainer = annotatedSection.find( + TextContainer, + )!; + + expect(annotedDescriptionTextContainer).toContainReactComponent( + MyComponent, + ); }); it('does not render an empty description node', () => { - const annotatedSection = mountWithAppProvider( + const annotatedSection = mountWithApp( , ); - const description = findByTestID( - annotatedSection, - 'AnnotationDescription', - ); - expect(description.exists()).toBe(false); + const annotedDescriptionTextContainer = annotatedSection.find( + TextContainer, + )!; + + expect(annotatedSection).toContainReactComponent(TextContainer); + expect(annotedDescriptionTextContainer).not.toContainReactComponent( + 'div', + { + className: expect.stringContaining(styles.AnnotationDescription), + }, + ); }); it('passes through an ID for deeplinking', () => { - const layout = mountWithAppProvider( + const layout = mountWithApp( , ); - const section = layout.find('#MySection'); - - expect(section.exists()).toBe(true); + expect(layout).toContainReactComponent(Heading, {id: 'MySection'}); }); }); }); diff --git a/src/components/MediaCard/tests/MediaCard.test.tsx b/src/components/MediaCard/tests/MediaCard.test.tsx index 7aec2496986..58f7a737851 100644 --- a/src/components/MediaCard/tests/MediaCard.test.tsx +++ b/src/components/MediaCard/tests/MediaCard.test.tsx @@ -1,8 +1,6 @@ import React from 'react'; import {Heading, Popover, Button, ActionList, Badge} from 'components'; import {mountWithApp} from 'test-utilities'; -// eslint-disable-next-line no-restricted-imports -import {mountWithAppProvider} from 'test-utilities/legacy'; import {MediaCard} from '../MediaCard'; @@ -33,14 +31,12 @@ describe('', () => { {badgeString} ); - const videoCard = mountWithAppProvider( - , - ); + const videoCard = mountWithApp(); - const headerMarkup = videoCard.find('h2'); + const headerMarkup = videoCard.find('h2')!; - expect(headerMarkup.text()).toContain(titleString); - expect(headerMarkup.find('Badge').text()).toBe(badgeString); + expect(headerMarkup.find(Badge)).toContainReactText(badgeString); + expect(headerMarkup).toContainReactText(titleString); }); it('renders the description as a paragraph', () => {