Skip to content

Commit

Permalink
Performance Tests: Support legacy selector for expanded elements (#54690
Browse files Browse the repository at this point in the history
)
  • Loading branch information
WunderBart authored Sep 21, 2023
1 parent 0e34475 commit 6f653f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
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

0 comments on commit 6f653f3

Please sign in to comment.