From 553a2c2fecc42947ec0b9b5a87440fd1017cbbde Mon Sep 17 00:00:00 2001
From: Marin Atanasov <8436925+tyxla@users.noreply.github.com>
Date: Tue, 11 Oct 2022 15:41:33 +0200
Subject: [PATCH] Block Editor: Refactor ColorPaletteControl tests to RTL
(#44869)
---
.../colors-gradients/test/control.js | 126 +++++++-----------
1 file changed, 49 insertions(+), 77 deletions(-)
diff --git a/packages/block-editor/src/components/colors-gradients/test/control.js b/packages/block-editor/src/components/colors-gradients/test/control.js
index f9b792a818cd4..3c6e4a77b5741 100644
--- a/packages/block-editor/src/components/colors-gradients/test/control.js
+++ b/packages/block-editor/src/components/colors-gradients/test/control.js
@@ -2,7 +2,6 @@
* External dependencies
*/
import { render, screen } from '@testing-library/react';
-import { create, act } from 'react-test-renderer';
/**
* Internal dependencies
@@ -11,15 +10,6 @@ import ColorGradientControl from '../control';
const noop = () => {};
-const getButtonWithAriaLabelStartPredicate =
- ( ariaLabelStart ) => ( element ) => {
- return (
- element.type === 'button' &&
- element.props[ 'aria-label' ] &&
- element.props[ 'aria-label' ].startsWith( ariaLabelStart )
- );
- };
-
describe( 'ColorPaletteControl', () => {
it( 'renders tabs if it is possible to select a color and a gradient rendering a color picker at the start', async () => {
render(
@@ -64,25 +54,21 @@ describe( 'ColorPaletteControl', () => {
} );
it( 'renders the color picker and does not render tabs if it is only possible to select a color', async () => {
- let wrapper;
-
- await act( async () => {
- wrapper = create(
-
- );
- } );
+ render(
+
+ );
// Is not showing the two tab buttons.
expect(
@@ -93,43 +79,35 @@ describe( 'ColorPaletteControl', () => {
).not.toBeInTheDocument();
// Is showing the two predefined Colors.
- expect(
- wrapper.root.findAll(
- getButtonWithAriaLabelStartPredicate( 'Color:' )
- )
- ).toHaveLength( 2 );
+ expect( screen.getAllByLabelText( /^Color:/ ) ).toHaveLength( 2 );
} );
it( 'renders the gradient picker and does not render tabs if it is only possible to select a gradient', async () => {
- let wrapper;
-
- await act( async () => {
- wrapper = create(
-
- );
- } );
+ render(
+
+ );
// Is not showing the two tab buttons.
expect(
@@ -140,22 +118,16 @@ describe( 'ColorPaletteControl', () => {
).not.toBeInTheDocument();
// Is showing the two predefined Gradients.
- expect(
- wrapper.root.findAll(
- getButtonWithAriaLabelStartPredicate( 'Gradient:' )
- )
- ).toHaveLength( 2 );
+ expect( screen.getAllByLabelText( /^Gradient:/ ) ).toHaveLength( 2 );
// Is showing the custom gradient picker.
expect(
- wrapper.root.findAll(
- ( element ) =>
- element.props &&
- element.props.className &&
- element.props.className.includes(
- 'components-custom-gradient-picker'
- )
- ).length
- ).toBeGreaterThanOrEqual( 1 );
+ screen.getAllByRole( 'button', {
+ expanded: false,
+ name: /^Gradient control point at position/,
+ } )[ 0 ]
+ ).toHaveClass(
+ 'components-custom-gradient-picker__control-point-button'
+ );
} );
} );