Skip to content

Commit

Permalink
Including adding of category and retrieving pattern by category to th…
Browse files Browse the repository at this point in the history
…e main flow (#54923)
  • Loading branch information
glendaviesnz authored Oct 2, 2023
1 parent 101306e commit 3cc9af1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/e2e-test-utils-playwright/src/request-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { deleteAllPages, createPage } from './pages';
import { resetPreferences } from './preferences';
import { getSiteSettings, updateSiteSettings } from './site-settings';
import { deleteAllWidgets, addWidgetBlock } from './widgets';
import { deleteAllPatternCategories } from './patterns';

interface StorageState {
cookies: Cookie[];
Expand Down Expand Up @@ -198,6 +199,8 @@ class RequestUtils {
/** @borrows getThemeGlobalStylesRevisions as this.getThemeGlobalStylesRevisions */
getThemeGlobalStylesRevisions: typeof getThemeGlobalStylesRevisions =
getThemeGlobalStylesRevisions.bind( this );
/** @borrows deleteAllPatternCategories as this.deleteAllPatternCategories */
deleteAllPatternCategories = deleteAllPatternCategories.bind( this );
}

export type { StorageState };
Expand Down
31 changes: 31 additions & 0 deletions packages/e2e-test-utils-playwright/src/request-utils/patterns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Internal dependencies
*/
import type { RequestUtils } from './index';

/**
* Delete all pattern categories using REST API.
*
* @see https://developer.wordpress.org/rest-api/reference/categories/#list-categories
* @param this
*/
export async function deleteAllPatternCategories( this: RequestUtils ) {
// List all pattern categories.
// https://developer.wordpress.org/rest-api/reference/categories/#list-categories
const categories = await this.rest( {
path: '/wp/v2/wp_pattern_category',
params: {
per_page: 100,
},
} );

// Delete pattern categories.
// https://developer.wordpress.org/rest-api/reference/categories/#delete-a-category
// "/wp/v2/category" does not yet supports batch requests.
await this.batchRest(
categories.map( ( category: { id: number } ) => ( {
method: 'DELETE',
path: `/wp/v2/wp_pattern_category/${ category.id }?force=true`,
} ) )
);
}
17 changes: 14 additions & 3 deletions test/e2e/specs/editor/various/patterns.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
test.describe( 'Unsynced pattern', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.deleteAllBlocks();
await requestUtils.deleteAllPatternCategories();
} );

test.beforeEach( async ( { admin } ) => {
Expand All @@ -14,6 +15,7 @@ test.describe( 'Unsynced pattern', () => {

test.afterEach( async ( { requestUtils } ) => {
await requestUtils.deleteAllBlocks();
await requestUtils.deleteAllPatternCategories();
} );

test( 'create a new unsynced pattern via the block options menu', async ( {
Expand All @@ -40,6 +42,10 @@ test.describe( 'Unsynced pattern', () => {
await createPatternDialog
.getByRole( 'textbox', { name: 'Name' } )
.fill( 'My unsynced pattern' );
const newCategory = 'Contact details';
await createPatternDialog
.getByRole( 'combobox', { name: 'Categories' } )
.fill( newCategory );
await createPatternDialog
.getByRole( 'checkbox', { name: 'Synced' } )
.setChecked( false );
Expand All @@ -59,10 +65,15 @@ test.describe( 'Unsynced pattern', () => {
// a plain paragraph block.
await page.getByLabel( 'Toggle block inserter' ).click();
await page
.getByRole( 'searchbox', {
name: 'Search for blocks and patterns',
.getByRole( 'tab', {
name: 'Patterns',
} )
.fill( 'My unsynced pattern' );
.click();
await page
.getByRole( 'button', {
name: newCategory,
} )
.click();
await page.getByLabel( 'My unsynced pattern' ).click();

// Just compare the block name and content as the clientIDs will be different.
Expand Down

1 comment on commit 3cc9af1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 3cc9af1.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6375680651
📝 Reported issues:

Please sign in to comment.