Skip to content

Commit e3f9e67

Browse files
authored
e2e tests: fix tests compatibility for WP 6.2 (#271)
1 parent 6d201a1 commit e3f9e67

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-10
lines changed

tests/e2e/block-testimonial.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* WordPress dependencies
33
*/
4-
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
4+
const { test, expect } = require( './fixtures' );
55

66
const PLUGIN_SLUG = 'secure-custom-fields';
77
const TEST_PLUGIN_SLUG = 'scf-test-plugin-testimonial-block';

tests/e2e/field-type-text-term.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,11 @@ test.describe( 'Field Type > Text', () => {
104104

105105
// Visit the category archive page
106106
await page.goto( '/?cat=1' );
107-
107+
108108
// Verify the custom field value appears on the frontend
109-
await page.waitForSelector( '#scf-test-term-title' );
110109
await expect(
111-
page.locator( '#scf-test-term-title' )
112-
).toContainText( 'Term title: Custom Term Value' );
110+
page.getByText( 'Term title: Custom Term Value' )
111+
).toBeVisible();
113112
} );
114113
} );
115114

tests/e2e/field-type-text-user.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,11 @@ test.describe( 'Field Type > Text', () => {
109109
} );
110110
// Visit the author archive page
111111
await page.goto( '/?author=1' );
112-
112+
113113
// Verify the custom field value appears on the frontend
114-
await page.waitForSelector( '#scf-test-user-title' );
115114
await expect(
116-
page.locator( '#scf-test-user-title' )
117-
).toContainText( 'User title: Test User Title' );
115+
page.getByText( 'User title: Test User Title' )
116+
).toBeVisible();
118117

119118
} );
120119
} );

tests/e2e/fixtures.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async function saveCoverage( coverage ) {
3333
);
3434
}
3535

36-
// Extend WordPress test with Istanbul coverage collection
36+
// Extend WordPress test with Istanbul coverage collection and WP version compatibility
3737
const test = wpTest.extend( {
3838
page: async ( { page }, use ) => {
3939
await use( page );
@@ -46,6 +46,57 @@ const test = wpTest.extend( {
4646
}
4747
}
4848
},
49+
50+
// Override editor fixture to provide version-compatible methods.
51+
// WP 6.3+ has "View" button and iframe canvas, WP 6.2 has "Preview" button and no iframe.
52+
editor: async ( { editor, page, context }, use ) => {
53+
// Create extended editor object with version-compatible overrides
54+
const extendedEditor = Object.create( editor, {
55+
// WP 6.2 doesn't have iframe canvas. Return a Promise so
56+
// `await editor.canvas` works correctly for both versions.
57+
canvas: {
58+
get() {
59+
return ( async () => {
60+
const isWP62 = await page.evaluate(
61+
() => document.body.classList.contains( 'branch-6-2' )
62+
);
63+
if ( isWP62 ) {
64+
return page;
65+
}
66+
return page.frameLocator( 'iframe[name="editor-canvas"]' );
67+
} )();
68+
},
69+
},
70+
// WP 6.2 has "Preview" button, WP 6.3+ has "View" button.
71+
openPreviewPage: {
72+
value: async () => {
73+
const isWP62 = await page.evaluate(
74+
() => document.body.classList.contains( 'branch-6-2' )
75+
);
76+
77+
if ( ! isWP62 ) {
78+
return editor.openPreviewPage();
79+
}
80+
81+
const editorTopBar = page.locator(
82+
'role=region[name="Editor top bar"i]'
83+
);
84+
await editorTopBar
85+
.locator( 'role=button[name="Preview"i]' )
86+
.click();
87+
88+
const [ previewPage ] = await Promise.all( [
89+
context.waitForEvent( 'page' ),
90+
page.click( 'role=menuitem[name="Preview in new tab"i]' ),
91+
] );
92+
93+
return previewPage;
94+
},
95+
},
96+
} );
97+
98+
await use( extendedEditor );
99+
},
49100
} );
50101

51102
module.exports = { test, expect };

0 commit comments

Comments
 (0)