Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '@wordpress/blocks';
import { RawHTML } from '@wordpress/element';
import { symbol } from '@wordpress/icons';
import { logged } from '@wordpress/deprecated';
import { select, dispatch } from '@wordpress/data';
import * as selectors from '../selectors';
import { store } from '../';
Expand Down Expand Up @@ -5342,6 +5343,10 @@ describe( '__unstableGetClientIdWithClientIdsTree', () => {
} );
} );
describe( '__unstableGetClientIdsTree', () => {
afterEach( () => {
Object.keys( logged ).forEach( ( key ) => delete logged[ key ] );
} );

it( "should return the full content tree starting from the given root, consisting of stripped down block object containing only its client ID and its inner blocks' client IDs", () => {
const state = {
blocks: {
Expand Down Expand Up @@ -5390,6 +5395,7 @@ describe( '__unstableGetClientIdsTree', () => {
],
},
] );
expect( console ).toHaveWarned();
} );
} );

Expand Down
8 changes: 7 additions & 1 deletion packages/blocks/src/api/test/children.jsdom.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest';
import { afterEach, describe, expect, it } from 'vitest';
import { renderToString } from '@wordpress/element';
import { logged } from '@wordpress/deprecated';
import {
getSerializeCapableElement,
concat,
Expand All @@ -8,6 +9,10 @@ import {
} from '../children';
/* eslint-disable testing-library/render-result-naming-convention */

afterEach( () => {
Object.keys( logged ).forEach( ( key ) => delete logged[ key ] );
} );

describe( 'getSerializeCapableElement', () => {
it( 'returns a serialize capable element', () => {
const blockNode = [
Expand Down Expand Up @@ -78,6 +83,7 @@ describe( 'concat', () => {
},
} );

expect( console ).toHaveWarned();
expect( result ).toEqual( [
'Hello ',
{
Expand Down
8 changes: 7 additions & 1 deletion packages/blocks/src/api/test/matchers.jsdom.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { describe, expect, it } from 'vitest';
import { afterEach, describe, expect, it } from 'vitest';
import { parse } from 'hpq';
import { renderToString } from '@wordpress/element';
import { logged } from '@wordpress/deprecated';
import * as sources from '../matchers';

afterEach( () => {
Object.keys( logged ).forEach( ( key ) => delete logged[ key ] );
} );

describe( 'matchers', () => {
describe( 'children()', () => {
it( 'should return a source function', () => {
Expand Down Expand Up @@ -39,6 +44,7 @@ describe( 'matchers', () => {
'<blockquote><p>A delicious sundae dessert</p></blockquote>';
const match = parse( html, sources.node() );

expect( console ).toHaveWarned();
expect( renderToString( match ) ).toBe( `<body>${ html }</body>` );
} );
} );
Expand Down
8 changes: 7 additions & 1 deletion packages/blocks/src/api/test/node.jsdom.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { describe, expect, it } from 'vitest';
import { afterEach, describe, expect, it } from 'vitest';
import { logged } from '@wordpress/deprecated';
import { getNamedNodeMapAsObject, toHTML, fromDOM } from '../node';

afterEach( () => {
Object.keys( logged ).forEach( ( key ) => delete logged[ key ] );
} );

describe( 'getNamedNodeMapAsObject', () => {
it( 'should return an object of node attributes', () => {
const node = document.createElement( 'img' );
Expand Down Expand Up @@ -49,6 +54,7 @@ describe( 'fromDOM', () => {
expect( () => {
fromDOM( document.createDocumentFragment() );
} ).toThrow( TypeError );
expect( console ).toHaveWarned();
} );

it( 'should return an equivalent block node, including children', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, expect, it, vi } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { screen, waitFor } from '@testing-library/react';
import { userEvent } from 'vitest/browser';
import { render } from 'vitest-browser-react';
import { useState } from '@wordpress/element';
import { logged } from '@wordpress/deprecated';
import ColorPalette from '..';

const EXAMPLE_COLORS = [
Expand All @@ -16,6 +17,17 @@ const DUPLICATE_COLOR_PALETTE = [
];
const INITIAL_COLOR = EXAMPLE_COLORS[ 0 ].color;

const DEPRECATION_MESSAGE =
'`asButtons` prop in wp.components.ColorPalette is deprecated since version 7.2. Please use `presentation` instead. Note: `asButtons={ true }` maps to `presentation="toggle-buttons"`. Explicit `presentation` takes precedence.';

beforeEach( () => {
logged[ DEPRECATION_MESSAGE ] = true;
} );

afterEach( () => {
delete logged[ DEPRECATION_MESSAGE ];
} );

const ControlledColorPalette = ( {
onChange,
}: {
Expand Down Expand Up @@ -64,6 +76,7 @@ describe( 'ColorPalette', () => {
} );

it( 'should warn for asButtons and prefer an explicit presentation', async () => {
delete logged[ DEPRECATION_MESSAGE ];
await render(
<ColorPalette
aria-label="Colors"
Expand All @@ -79,9 +92,7 @@ describe( 'ColorPalette', () => {
expect(
screen.getByRole( 'button', { name: 'red' } )
).not.toHaveAttribute( 'aria-pressed' );
expect( console ).toHaveWarnedWith(
'`asButtons` prop in wp.components.ColorPalette is deprecated since version 7.2. Please use `presentation` instead. Note: `asButtons={ true }` maps to `presentation="toggle-buttons"`. Explicit `presentation` takes precedence.'
);
expect( console ).toHaveWarnedWith( DEPRECATION_MESSAGE );
} );

it( 'should preserve asButtons as a toggle-button alias', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, expect, it, vi } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { screen } from '@testing-library/react';
import { userEvent } from 'vitest/browser';
import { render } from 'vitest-browser-react';
import { useState } from '@wordpress/element';
import { logged } from '@wordpress/deprecated';
import { DuotonePicker } from '..';
import type { DuotonePickerProps } from '../types';

Expand All @@ -22,6 +23,17 @@ const COLOR_PALETTE = [
{ color: '#ffffff', name: 'White', slug: 'white' },
];

const DEPRECATION_MESSAGE =
'`asButtons` prop in wp.components.DuotonePicker is deprecated since version 7.2. Please use `presentation` instead. Note: `asButtons={ true }` maps to `presentation="toggle-buttons"`. Explicit `presentation` takes precedence.';

beforeEach( () => {
logged[ DEPRECATION_MESSAGE ] = true;
} );

afterEach( () => {
delete logged[ DEPRECATION_MESSAGE ];
} );

describe( 'DuotonePicker', () => {
it( 'should use matching values only for display in command button presentation', async () => {
const user = userEvent.setup();
Expand Down Expand Up @@ -60,6 +72,7 @@ describe( 'DuotonePicker', () => {
} );

it( 'should warn for asButtons and prefer an explicit presentation', async () => {
delete logged[ DEPRECATION_MESSAGE ];
await render(
<DuotonePicker
aria-label="Duotones"
Expand All @@ -78,9 +91,7 @@ describe( 'DuotonePicker', () => {
name: 'Duotone: Dark Background',
} )
).not.toHaveAttribute( 'aria-pressed' );
expect( console ).toHaveWarnedWith(
'`asButtons` prop in wp.components.DuotonePicker is deprecated since version 7.2. Please use `presentation` instead. Note: `asButtons={ true }` maps to `presentation="toggle-buttons"`. Explicit `presentation` takes precedence.'
);
expect( console ).toHaveWarnedWith( DEPRECATION_MESSAGE );
} );

it( 'should preserve asButtons as a toggle-button alias', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { describe, expect, it, vi } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { screen } from '@testing-library/react';
import { userEvent } from 'vitest/browser';
import { render } from 'vitest-browser-react';
import { logged } from '@wordpress/deprecated';
import GradientPicker from '..';

const GRADIENT_A =
Expand All @@ -14,6 +15,17 @@ const DUPLICATE_GRADIENTS = [
{ name: 'Dark Text', slug: 'dark-text', gradient: GRADIENT_A },
];

const DEPRECATION_MESSAGE =
'`asButtons` prop in wp.components.GradientPicker is deprecated since version 7.2. Please use `presentation` instead. Note: `asButtons={ true }` maps to `presentation="toggle-buttons"`. Explicit `presentation` takes precedence.';

beforeEach( () => {
logged[ DEPRECATION_MESSAGE ] = true;
} );

afterEach( () => {
delete logged[ DEPRECATION_MESSAGE ];
} );

describe( 'GradientPicker', () => {
it( 'should use matching values only for display in command button presentation', async () => {
const user = userEvent.setup();
Expand Down Expand Up @@ -49,6 +61,7 @@ describe( 'GradientPicker', () => {
} );

it( 'should warn for asButtons and prefer an explicit presentation', async () => {
delete logged[ DEPRECATION_MESSAGE ];
await render(
<GradientPicker
aria-label="Gradients"
Expand All @@ -66,9 +79,7 @@ describe( 'GradientPicker', () => {
name: 'Gradient: Dark Background',
} )
).not.toHaveAttribute( 'aria-pressed' );
expect( console ).toHaveWarnedWith(
'`asButtons` prop in wp.components.GradientPicker is deprecated since version 7.2. Please use `presentation` instead. Note: `asButtons={ true }` maps to `presentation="toggle-buttons"`. Explicit `presentation` takes precedence.'
);
expect( console ).toHaveWarnedWith( DEPRECATION_MESSAGE );
} );

it( 'should preserve asButtons as a toggle-button alias', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { describe, expect, it, vi } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { render, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { logged } from '@wordpress/deprecated';
import IsolatedEventContainer from '..';

const DEPRECATION_MESSAGE =
'wp.components.IsolatedEventContainer is deprecated since version 5.7.';

beforeEach( () => {
logged[ DEPRECATION_MESSAGE ] = true;
} );

afterEach( () => {
delete logged[ DEPRECATION_MESSAGE ];
} );

describe( 'IsolatedEventContainer', () => {
it( 'should pass props to container', async () => {
delete logged[ DEPRECATION_MESSAGE ];
const user = userEvent.setup();
const clickHandler = vi.fn();
render(
Expand Down
28 changes: 25 additions & 3 deletions packages/components/src/navigator/test/index.browser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { describe, expect, it, vi } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { userEvent } from 'vitest/browser';
import type { ComponentPropsWithoutRef } from 'react';
import { screen, waitFor } from '@testing-library/react';
import { render } from 'vitest-browser-react';
import { useState } from '@wordpress/element';
import { logged } from '@wordpress/deprecated';
import Button from '../../button';
import { Navigator, useNavigator } from '..';
import { NavigatorToParentButton } from '../legacy';
Expand Down Expand Up @@ -51,6 +52,25 @@ const BUTTON_TEXT = {
goToWithSkipFocus: 'Go to with skipFocus',
};

const DEPRECATION_MESSAGES = {
NavigatorToParentButton:
'wp.components.NavigatorToParentButton is deprecated since version 6.7. Please use wp.components.Navigator.BackButton instead.',
goToParent:
'wp.components.useNavigator().goToParent is deprecated since version 6.7. Please use wp.components.useNavigator().goBack instead.',
};

beforeEach( () => {
for ( const message of Object.values( DEPRECATION_MESSAGES ) ) {
logged[ message ] = true;
}
} );

afterEach( () => {
for ( const message of Object.values( DEPRECATION_MESSAGES ) ) {
delete logged[ message ];
}
} );

type CustomTestOnClickHandler = (
args:
| {
Expand Down Expand Up @@ -856,6 +876,7 @@ describe( 'Navigator', () => {

describe( 'deprecated APIs', () => {
it( 'should log a deprecation notice when using the NavigatorToParentButton component', async () => {
delete logged[ DEPRECATION_MESSAGES.NavigatorToParentButton ];
const user = userEvent.setup();

await render(
Expand All @@ -877,11 +898,12 @@ describe( 'Navigator', () => {

// Rendering `NavigatorToParentButton` logs a deprecation notice
expect( console ).toHaveWarnedWith(
'wp.components.NavigatorToParentButton is deprecated since version 6.7. Please use wp.components.Navigator.BackButton instead.'
DEPRECATION_MESSAGES.NavigatorToParentButton
);
} );

it( 'should log a deprecation notice when using the useNavigator().goToParent() function', async () => {
delete logged[ DEPRECATION_MESSAGES.goToParent ];
const user = userEvent.setup();

await render(
Expand All @@ -902,7 +924,7 @@ describe( 'Navigator', () => {
).toHaveFocus();

expect( console ).toHaveWarnedWith(
'wp.components.useNavigator().goToParent is deprecated since version 6.7. Please use wp.components.useNavigator().goBack instead.'
DEPRECATION_MESSAGES.goToParent
);
} );
} );
Expand Down
21 changes: 15 additions & 6 deletions packages/components/src/surface/test/index.jsdom.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { describe, expect, test } from 'vitest';
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
import { render, screen } from '@testing-library/react';
import { logged } from '@wordpress/deprecated';
import { Surface } from '../index';

// Checking for deprecation warnings before other tests because the `deprecated`
// utility only fires a console.warn the first time a component is rendered.
const DEPRECATION_MESSAGE =
'wp.components.__experimentalSurface is deprecated since version 7.2 and will be removed in version 7.4.';

beforeEach( () => {
logged[ DEPRECATION_MESSAGE ] = true;
} );

afterEach( () => {
delete logged[ DEPRECATION_MESSAGE ];
} );

describe( 'Shows a deprecation warning', () => {
test( 'Surface', () => {
delete logged[ DEPRECATION_MESSAGE ];
render( <Surface>Surface</Surface> );

expect( console ).toHaveWarnedWith(
'wp.components.__experimentalSurface is deprecated since version 7.2 and will be removed in version 7.4.'
);
expect( console ).toHaveWarnedWith( DEPRECATION_MESSAGE );
} );
} );

Expand Down
Loading
Loading