Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance Tests: Support legacy selector for expanded elements #54690

Merged
merged 1 commit into from
Sep 21, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion test/performance/fixtures/perf-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { expect } from '@wordpress/e2e-test-utils-playwright';
*/
import fs from 'fs';
import path from 'path';
import type { Page } from '@playwright/test';
import type { Locator, Page } from '@playwright/test';

/**
* Internal dependencies
Expand Down Expand Up @@ -168,4 +168,14 @@ export class PerfUtils {
dispatch( 'core/block-editor' ).resetBlocks( blocks );
} );
}

async expectExpandedState( locator: Locator, state: 'true' | 'false' ) {
return await Promise.any( [
// eslint-disable-next-line playwright/missing-playwright-await
expect( locator ).toHaveAttribute( 'aria-expanded', state ),
// Legacy selector.
// eslint-disable-next-line playwright/missing-playwright-await
expect( locator ).toHaveAttribute( 'aria-pressed', state ),
] );
}
}
30 changes: 9 additions & 21 deletions test/performance/specs/post-editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* WordPress dependencies
*/
import { test, expect, Metrics } from '@wordpress/e2e-test-utils-playwright';
import { test, Metrics } from '@wordpress/e2e-test-utils-playwright';

/**
* Internal dependencies
Expand Down Expand Up @@ -280,10 +280,7 @@ test.describe( 'Post Editor Performance', () => {

// Open List View.
await listViewToggle.click();
await expect( listViewToggle ).toHaveAttribute(
'aria-expanded',
'true'
);
await perfUtils.expectExpandedState( listViewToggle, 'true' );

// Stop tracing.
await metrics.stopTracing();
Expand All @@ -298,10 +295,7 @@ test.describe( 'Post Editor Performance', () => {

// Close List View
await listViewToggle.click();
await expect( listViewToggle ).toHaveAttribute(
'aria-expanded',
'false'
);
await perfUtils.expectExpandedState( listViewToggle, 'false' );
}
} );
} );
Expand Down Expand Up @@ -336,8 +330,8 @@ test.describe( 'Post Editor Performance', () => {

// Open Inserter.
await globalInserterToggle.click();
await expect( globalInserterToggle ).toHaveAttribute(
'aria-expanded',
await perfUtils.expectExpandedState(
globalInserterToggle,
'true'
);

Expand All @@ -354,8 +348,8 @@ test.describe( 'Post Editor Performance', () => {

// Close Inserter.
await globalInserterToggle.click();
await expect( globalInserterToggle ).toHaveAttribute(
'aria-expanded',
await perfUtils.expectExpandedState(
globalInserterToggle,
'false'
);
}
Expand All @@ -381,10 +375,7 @@ test.describe( 'Post Editor Performance', () => {

// Open Inserter.
await globalInserterToggle.click();
await expect( globalInserterToggle ).toHaveAttribute(
'aria-expanded',
'true'
);
await perfUtils.expectExpandedState( globalInserterToggle, 'true' );

const samples = 10;
const throwaway = 1;
Expand Down Expand Up @@ -447,10 +438,7 @@ test.describe( 'Post Editor Performance', () => {

// Open Inserter.
await globalInserterToggle.click();
await expect( globalInserterToggle ).toHaveAttribute(
'aria-expanded',
'true'
);
await perfUtils.expectExpandedState( globalInserterToggle, 'true' );

const samples = 10;
const throwaway = 1;
Expand Down