Skip to content

Commit e9e15c7

Browse files
committed
Build/Test Tools: Filter E2E lists to test-owned rows.
Filter comment lists by post and find the Quick Edit page by its unique title so other workers cannot push the target off the first page. Reuse the shared settings, logged-out page, and attachment fixtures. Follow-up to r65049. Developed in: #16206 Props adrianmoldovanwp. See #66392, #66455. git-svn-id: https://develop.svn.wordpress.org/trunk@65779 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 31b09c2 commit e9e15c7

6 files changed

Lines changed: 142 additions & 168 deletions

File tree

‎tests/e2e/specs/comments.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ test.describe( 'Front-end comments', () => {
9090
status: 'approved',
9191
} );
9292

93-
await admin.visitAdminPage( '/edit-comments.php' );
93+
await admin.visitAdminPage( '/edit-comments.php', `p=${ post.id }` );
9494
const row = commentRow( page, commentId );
9595
await expect( row ).toBeVisible();
9696
await expect(
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
1+
import { test, expect } from '../fixtures';
22
import { GENERAL_SETTINGS } from '../utils/locks';
33

44
test.describe( 'Settings -> General', { lock: GENERAL_SETTINGS }, () => {
55
test( 'Saving General Settings preserves the active theme options', async ( {
66
admin,
77
page,
8-
requestUtils,
8+
siteSettings,
99
} ) => {
1010
await admin.visitAdminPage( 'options.php' );
1111
const stylesheet = await page.locator( '#stylesheet' ).inputValue();
@@ -20,22 +20,17 @@ test.describe( 'Settings -> General', { lock: GENERAL_SETTINGS }, () => {
2020
originalTagline + ' Updated in General Settings.'
2121
).trimStart();
2222

23-
try {
24-
await tagline.fill( updatedTagline );
25-
await page.getByRole( 'button', { name: 'Save Changes' } ).click();
26-
await expect(
27-
page.locator( '#setting-error-settings_updated' )
28-
).toContainText( 'Settings saved.' );
29-
await expect( tagline ).toHaveValue( updatedTagline );
23+
await siteSettings.remember( [ 'description' ] );
24+
await tagline.fill( updatedTagline );
25+
await page.getByRole( 'button', { name: 'Save Changes' } ).click();
26+
await expect(
27+
page.locator( '#setting-error-settings_updated' )
28+
).toContainText( 'Settings saved.' );
29+
await expect( tagline ).toHaveValue( updatedTagline );
3030

31-
await admin.visitAdminPage( 'options.php' );
32-
await expect( page.locator( '#stylesheet' ) ).toHaveValue( stylesheet );
33-
await expect( page.locator( '#template' ) ).toHaveValue( template );
34-
} finally {
35-
await requestUtils.updateSiteSettings( {
36-
description: originalTagline,
37-
} );
38-
}
31+
await admin.visitAdminPage( 'options.php' );
32+
await expect( page.locator( '#stylesheet' ) ).toHaveValue( stylesheet );
33+
await expect( page.locator( '#template' ) ).toHaveValue( template );
3934
} );
4035
} );
4136

Lines changed: 64 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
/**
2-
* WordPress dependencies
2+
* External dependencies
33
*/
4-
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
4+
import path from 'path';
55

66
/**
7-
* External dependencies
7+
* Internal dependencies
88
*/
9-
import path from 'path';
9+
import { test, expect } from '../fixtures';
10+
import { TEST_SVG_PATH, trackUploads } from '../utils/media-pipeline';
1011

11-
test( 'Test dismissing failed upload works correctly', async ({ page, admin, requestUtils }) => {
12+
test( 'Test dismissing failed upload works correctly', async ({ page, admin }) => {
1213
await admin.visitAdminPage( '/media-new.php' );
1314

1415
// It takes a moment for the multi-file uploader to become available.
1516
const input = page.locator( '#plupload-upload-ui input[type="file"]' );
1617
await expect( input ).toBeAttached( { timeout: 10_000 } );
1718

18-
const testImagePath = path.join(__dirname, '../assets/sample.svg');
19-
2019
// Upload a file that will fail.
21-
await input.setInputFiles( testImagePath );
20+
await input.setInputFiles( TEST_SVG_PATH );
2221

2322
// Ensure the error message is visible.
2423
await expect(
@@ -35,75 +34,69 @@ test( 'Test dismissing failed upload works correctly', async ({ page, admin, req
3534
test( 'uploads a JPEG and shows the completed attachment', async ( {
3635
page,
3736
admin,
38-
requestUtils,
37+
attachments,
3938
} ) => {
40-
let attachmentId;
41-
42-
try {
43-
await admin.visitAdminPage( '/media-new.php' );
44-
const fileChooserPromise = page.waitForEvent( 'filechooser' );
45-
await page
46-
.getByRole( 'button', { name: 'Select Files', exact: true } )
47-
.click();
48-
const fileChooser = await fileChooserPromise;
49-
const uploadResponsePromise = page.waitForResponse( ( response ) => {
50-
if ( response.request().method() !== 'POST' ) {
51-
return false;
52-
}
39+
trackUploads( page, attachments );
40+
await admin.visitAdminPage( '/media-new.php' );
41+
const fileChooserPromise = page.waitForEvent( 'filechooser' );
42+
await page
43+
.getByRole( 'button', { name: 'Select Files', exact: true } )
44+
.click();
45+
const fileChooser = await fileChooserPromise;
46+
const uploadResponsePromise = page.waitForResponse( ( response ) => {
47+
if ( response.request().method() !== 'POST' ) {
48+
return false;
49+
}
5350

54-
const url = new URL( response.url() );
51+
const url = new URL( response.url() );
5552

56-
// Client-side processing creates attachments through the REST API.
57-
if (
58-
url.pathname.endsWith( '/wp/v2/media' ) ||
59-
url.searchParams.get( 'rest_route' ) === '/wp/v2/media'
60-
) {
61-
return true;
62-
}
53+
// Client-side processing creates attachments through the REST API.
54+
if (
55+
url.pathname.endsWith( '/wp/v2/media' ) ||
56+
url.searchParams.get( 'rest_route' ) === '/wp/v2/media'
57+
) {
58+
return true;
59+
}
6360

64-
// Ignore the separate request that fetches completed attachment markup.
65-
return (
66-
url.pathname.endsWith( '/async-upload.php' ) &&
67-
response
68-
.request()
69-
.headers()
70-
[ 'content-type' ]?.startsWith( 'multipart/form-data' )
71-
);
72-
} );
73-
await fileChooser.setFiles(
74-
path.join( __dirname, '../../phpunit/data/images/test-image.jpg' )
61+
// Ignore the separate request that fetches completed attachment markup.
62+
return (
63+
url.pathname.endsWith( '/async-upload.php' ) &&
64+
response
65+
.request()
66+
.headers()
67+
[ 'content-type' ]?.startsWith( 'multipart/form-data' )
7568
);
76-
const uploadResponse = await uploadResponsePromise;
69+
} );
70+
await fileChooser.setFiles(
71+
path.join( __dirname, '../../phpunit/data/images/test-image.jpg' )
72+
);
73+
const uploadResponse = await uploadResponsePromise;
74+
let attachmentId = Number(
75+
uploadResponse.headers()[ 'x-wp-upload-attachment-id' ]
76+
);
77+
if ( ! attachmentId ) {
7778
attachmentId = Number(
78-
uploadResponse.headers()[ 'x-wp-upload-attachment-id' ]
79-
);
80-
if ( ! attachmentId ) {
81-
attachmentId = Number(
82-
uploadResponse.headers()[ 'content-type' ]?.includes(
83-
'application/json'
84-
)
85-
? ( await uploadResponse.json() ).id
86-
: await uploadResponse.text()
87-
);
88-
}
89-
expect( uploadResponse.ok() ).toBe( true );
90-
expect( attachmentId ).toBeGreaterThan( 0 );
91-
92-
await expect(
93-
page.getByText( 'test-image', { exact: true } )
94-
).toBeVisible();
95-
const editLink = page.getByRole( 'link', {
96-
name: 'Edit',
97-
exact: true,
98-
} );
99-
await expect( editLink ).toBeVisible();
100-
await expect( editLink ).toHaveAttribute(
101-
'href',
102-
new RegExp( `[?&]post=${ attachmentId }&` )
79+
uploadResponse.headers()[ 'content-type' ]?.includes(
80+
'application/json'
81+
)
82+
? ( await uploadResponse.json() ).id
83+
: await uploadResponse.text()
10384
);
104-
} finally {
105-
if ( Number.isInteger( attachmentId ) && attachmentId > 0 ) {
106-
await requestUtils.deleteMedia( attachmentId );
107-
}
10885
}
86+
expect( uploadResponse.ok() ).toBe( true );
87+
expect( attachmentId ).toBeGreaterThan( 0 );
88+
attachments.track( attachmentId );
89+
90+
await expect(
91+
page.getByText( 'test-image', { exact: true } )
92+
).toBeVisible();
93+
const editLink = page.getByRole( 'link', {
94+
name: 'Edit',
95+
exact: true,
96+
} );
97+
await expect( editLink ).toBeVisible();
98+
await expect( editLink ).toHaveAttribute(
99+
'href',
100+
new RegExp( `[?&]post=${ attachmentId }&` )
101+
);
109102
} );

‎tests/e2e/specs/moderate-comments.test.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ test.describe( 'Moderate Comments', () => {
7373
postFactory,
7474
requestUtils,
7575
} ) => {
76-
const { comment } = await createPostWithComment(
76+
const { post, comment } = await createPostWithComment(
7777
postFactory,
7878
requestUtils,
7979
'hold'
8080
);
8181

8282
await admin.visitAdminPage(
8383
'/edit-comments.php',
84-
'comment_status=moderated'
84+
`comment_status=moderated&p=${ post.id }`
8585
);
8686

8787
const row = commentRow( page, comment.id );
@@ -104,7 +104,7 @@ test.describe( 'Moderate Comments', () => {
104104
await expect( row ).toBeHidden();
105105
await admin.visitAdminPage(
106106
'/edit-comments.php',
107-
'comment_status=approved'
107+
`comment_status=approved&p=${ post.id }`
108108
);
109109
await expect( row ).toBeVisible();
110110
} );
@@ -115,13 +115,13 @@ test.describe( 'Moderate Comments', () => {
115115
postFactory,
116116
requestUtils,
117117
} ) => {
118-
const { comment } = await createPostWithComment(
118+
const { post, comment } = await createPostWithComment(
119119
postFactory,
120120
requestUtils,
121121
'approved'
122122
);
123123

124-
await admin.visitAdminPage( '/edit-comments.php' );
124+
await admin.visitAdminPage( '/edit-comments.php', `p=${ post.id }` );
125125

126126
const row = commentRow( page, comment.id );
127127
await expect( row ).toBeVisible();
@@ -156,7 +156,7 @@ test.describe( 'Moderate Comments', () => {
156156
'approved'
157157
);
158158

159-
await admin.visitAdminPage( '/edit-comments.php' );
159+
await admin.visitAdminPage( '/edit-comments.php', `p=${ post.id }` );
160160

161161
const row = commentRow( page, comment.id );
162162
await expect( row ).toBeVisible();
@@ -249,7 +249,7 @@ test.describe( 'Moderate Comments', () => {
249249

250250
await admin.visitAdminPage(
251251
'/edit-comments.php',
252-
'comment_status=moderated'
252+
`comment_status=moderated&p=${ post.id }`
253253
);
254254

255255
const firstRow = commentRow( page, comment.id );
@@ -273,7 +273,7 @@ test.describe( 'Moderate Comments', () => {
273273
await expect( secondRow ).toBeHidden();
274274
await admin.visitAdminPage(
275275
'/edit-comments.php',
276-
'comment_status=spam'
276+
`comment_status=spam&p=${ post.id }`
277277
);
278278
await expect( firstRow ).toBeVisible();
279279
await expect( secondRow ).toBeVisible();

‎tests/e2e/specs/pages/quick-edit-page.test.js‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@ test.describe( 'Quick Edit page', () => {
1111
postFactory,
1212
} ) => {
1313
const parentPage = await postFactory.createPage( {
14-
title: 'Quick Edit parent',
14+
title: postFactory.uniqueTitle( 'Quick Edit parent' ),
1515
status: 'publish',
1616
} );
17+
const title = postFactory.uniqueTitle( 'Quick Edit page' );
1718
const createdPage = await postFactory.createPage( {
18-
title: 'Quick Edit page',
19+
title,
1920
status: 'publish',
2021
} );
2122
const pageId = createdPage.id;
2223

23-
await admin.visitAdminPage( 'edit.php?post_type=page' );
24+
await admin.visitAdminPage(
25+
'edit.php',
26+
`post_type=page&s=${ encodeURIComponent( title ) }`
27+
);
2428
const row = postRow( page, pageId );
25-
await row
26-
.getByRole( 'link', { name: 'Quick Edit page', exact: true } )
27-
.hover();
29+
await row.getByRole( 'link', { name: title, exact: true } ).hover();
2830
await row
2931
.getByRole( 'button', {
30-
name: 'Quick edit “Quick Edit page” inline',
32+
name: `Quick edit “${ title }” inline`,
3133
exact: true,
3234
} )
3335
.click();
@@ -48,12 +50,10 @@ test.describe( 'Quick Edit page', () => {
4850
await expect( editRow ).toBeHidden();
4951

5052
await page.reload();
51-
await row
52-
.getByRole( 'link', { name: 'Quick Edit page', exact: true } )
53-
.hover();
53+
await row.getByRole( 'link', { name: title, exact: true } ).hover();
5454
await row
5555
.getByRole( 'button', {
56-
name: 'Quick edit “Quick Edit page” inline',
56+
name: `Quick edit “${ title }” inline`,
5757
exact: true,
5858
} )
5959
.click();

0 commit comments

Comments
 (0)