From 50b0659126a88c9690b9fdfccf755d08617e395e Mon Sep 17 00:00:00 2001 From: Tristan Watanabe Date: Wed, 30 Mar 2022 13:05:43 -0400 Subject: [PATCH] Coachmark (v8): convert tests to use testing-library (#22242) --- .../components/Coachmark/Coachmark.test.tsx | 65 +- .../__snapshots__/Coachmark.test.tsx.snap | 1019 +++++++---------- 2 files changed, 474 insertions(+), 610 deletions(-) diff --git a/packages/react/src/components/Coachmark/Coachmark.test.tsx b/packages/react/src/components/Coachmark/Coachmark.test.tsx index a189dc511f0991..079c781d050749 100644 --- a/packages/react/src/components/Coachmark/Coachmark.test.tsx +++ b/packages/react/src/components/Coachmark/Coachmark.test.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; -import { Coachmark } from './Coachmark'; -import { safeCreate, safeMount } from '@fluentui/test-utilities'; +import { Coachmark, ICoachmarkProps } from './index'; +import { render, within } from '@testing-library/react'; import { resetIds } from '@fluentui/utilities'; import { isConformant } from '../../common/isConformant'; import * as path from 'path'; @@ -30,66 +30,65 @@ describe('Coachmark', () => { it('renders Coachmark (correctly)', () => { ReactDOM.createPortal = jest.fn(element => element); - safeCreate( + const { container } = render( This is a test , - component => { - const tree = component!.toJSON(); - expect(tree).toMatchSnapshot(); - }, ); + expect(container).toMatchSnapshot(); }); it('renders Coachmark (isCollapsed)', () => { ReactDOM.createPortal = jest.fn(element => element); - safeCreate( + const { container } = render( This is a test , - component => { - const tree = component!.toJSON(); - expect(tree).toMatchSnapshot(); - }, ); + expect(container).toMatchSnapshot(); }); it('renders Coachmark (color properties)', () => { ReactDOM.createPortal = jest.fn(element => element); - safeCreate(, component => { - const tree = component!.toJSON(); - expect(tree).toMatchSnapshot(); - }); + const { container } = render(); + expect(container).toMatchSnapshot(); }); // Accessibility Tests: it('correctly applies (ariaAlertText)', () => { - safeMount(, component => { - expect(component.find('[role="alert"]').getDOMNode()).toBeDefined(); - }); + const { getByRole } = render(); + expect(getByRole('alert')).toBeTruthy(); }); it('correctly applies (ariaLabelBy)', () => { - safeMount( - , - component => { - expect(component.find('[role="dialog"]').getDOMNode().getAttribute('aria-labelledby')).toBe('aria label'); - expect(component.find('[id="aria label"]').text()).toBe('aria text'); - }, + const { getByRole } = render( + , ); + + //coachmark is hidden since it has a parent wrapper with role=presentation when not in a collapsed state. + const coachmark = getByRole('dialog', { hidden: true }); + expect(coachmark.getAttribute('aria-labelledby')).toBe('aria label'); + expect(within(coachmark).queryByText('aria text')).toBeTruthy(); }); it('correctly applies (ariaDescribedBy)', () => { - safeMount( - , - component => { - expect(component.find('[role="dialog"]').getDOMNode().getAttribute('aria-describedby')).toBe( - 'aria description', - ); - expect(component.find('[id="aria description"]').text()).toBe('aria description text'); - }, + const { getByRole } = render( + , ); + + //coachmark is hidden since it has a parent wrapper with role=presentation when not in a collapsed state. + const coachmark = getByRole('dialog', { hidden: true }); + expect(coachmark.getAttribute('aria-describedby')).toBe('aria description'); + expect(within(coachmark).queryByText('aria description text')).toBeTruthy(); }); }); diff --git a/packages/react/src/components/Coachmark/__snapshots__/Coachmark.test.tsx.snap b/packages/react/src/components/Coachmark/__snapshots__/Coachmark.test.tsx.snap index 3fd1122f1394e2..5b072d11876376 100644 --- a/packages/react/src/components/Coachmark/__snapshots__/Coachmark.test.tsx.snap +++ b/packages/react/src/components/Coachmark/__snapshots__/Coachmark.test.tsx.snap @@ -1,140 +1,91 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Coachmark renders Coachmark (color properties) 1`] = ` - -
+
-
+
-
-
-
-
+ + +
+
-
- + +
`; exports[`Coachmark renders Coachmark (correctly) 1`] = ` - -
+
-
+
-
-
-
-
+ + +
+
-
- + +
`; exports[`Coachmark renders Coachmark (isCollapsed) 1`] = ` - -
+
-
+
- + +
`;