Skip to content

Commit 9f4e523

Browse files
committed
Build/Test Tools: Run post-list E2E specs in parallel.
Scope post fixtures and list assertions to each test, and keep Empty Trash tests serial. Clean up saved drafts within Quick Draft's own tests. Developed in: #15901 Props adrianmoldovanwp. See #66392. git-svn-id: https://develop.svn.wordpress.org/trunk@65412 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d814e53 commit 9f4e523

6 files changed

Lines changed: 145 additions & 105 deletions

‎tests/e2e/playwright.config.js‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ const SERIAL_SPECS = [
2323
'gutenberg-plugin.test.js',
2424
'plugins.test.js',
2525
'themes.test.js',
26-
// These delete all posts or media, including other workers' content.
27-
'cache-control-headers-directives.test.js',
28-
'dashboard.test.js',
29-
'edit-posts.test.js',
30-
'empty-trash-restore-trashed-posts.test.js',
26+
// This deletes all posts, including other workers' content.
27+
'empty-trash.test.js',
3128
];
3229

3330
const config = defineConfig( {

‎tests/e2e/specs/cache-control-headers-directives.test.js‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@
44
import { test, expect } from '../fixtures';
55

66
test.describe( 'Cache Control header directives', () => {
7-
test.beforeAll( async ( { requestUtils } ) => {
8-
await requestUtils.deleteAllPosts();
9-
});
10-
117
test(
128
'No private directive present in cache control when user not logged in.',
13-
async ( { loggedOutPage, admin, editor}
9+
async ( { loggedOutPage, postFactory }
1410
) => {
15-
await admin.createNewPost( { title: 'Hello World' } );
16-
await editor.publishPost();
17-
18-
await admin.visitAdminPage( '/' );
11+
const post = await postFactory.create( {
12+
title: postFactory.uniqueTitle( 'Cache control' ),
13+
status: 'publish',
14+
} );
15+
const { pathname, search } = new URL( post.link );
1916

20-
const response = await loggedOutPage.goto( '/hello-world/' );
17+
const response = await loggedOutPage.goto( pathname + search );
2118
const responseHeaders = response.headers();
2219

2320
const cacheControl = responseHeaders[ 'cache-control' ] ?? '';

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

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,39 @@ import { test, expect } from '../fixtures';
55
import { signIn } from '../fixtures/user';
66

77
test.describe( 'Quick Draft', () => {
8-
test.beforeEach( async ({ requestUtils }) => {
9-
await requestUtils.deleteAllPosts();
8+
// Recent Drafts and the author-filtered post list show only this user's posts.
9+
test.use( { storageState: { cookies: [], origins: [] } } );
10+
let userId;
11+
12+
test.beforeEach( async ( { page, userFactory } ) => {
13+
userId = undefined;
14+
const { user, username, password } = await userFactory.create( {
15+
roles: [ 'administrator' ],
16+
} );
17+
userId = user.id;
18+
await signIn( page, username, password );
19+
await expect(
20+
page.getByRole( 'heading', { name: 'Dashboard', exact: true } )
21+
).toBeVisible();
22+
} );
23+
24+
// Deleting the user would move its saved drafts to the trash.
25+
test.afterEach( async ( { requestUtils } ) => {
26+
// Without an author, the query would match other workers' drafts.
27+
if ( ! userId ) {
28+
return;
29+
}
30+
const drafts = await requestUtils.rest( {
31+
path: '/wp/v2/posts',
32+
params: { author: userId, status: 'draft', per_page: 100 },
33+
} );
34+
for ( const draft of drafts ) {
35+
await requestUtils.rest( {
36+
method: 'DELETE',
37+
path: `/wp/v2/posts/${ draft.id }`,
38+
params: { force: true },
39+
} );
40+
}
1041
} );
1142

1243
test( 'should allow Quick Draft to be created with Title and Content', async ( {
@@ -57,7 +88,7 @@ test.describe( 'Quick Draft', () => {
5788
).toBeVisible();
5889

5990
// Check that the new draft appears in the Posts page.
60-
await admin.visitAdminPage( '/edit.php' );
91+
await admin.visitAdminPage( '/edit.php', `author=${ userId }` );
6192

6293
await expect(
6394
page
@@ -92,7 +123,7 @@ test.describe( 'Quick Draft', () => {
92123
).toHaveText( 'Cannot create a draft post with empty title and content.' );
93124

94125
// Check that no new draft appears in the Posts page.
95-
await admin.visitAdminPage( '/edit.php' );
126+
await admin.visitAdminPage( '/edit.php', `author=${ userId }` );
96127

97128
await expect(
98129
page.getByRole( 'cell', { name: 'No posts found.' } )
@@ -132,7 +163,7 @@ test.describe( 'Quick Draft', () => {
132163
).toHaveText( 'Quick Draft test title' );
133164

134165
// Check that the new draft appears in the Posts page.
135-
await admin.visitAdminPage( '/edit.php' );
166+
await admin.visitAdminPage( '/edit.php', `author=${ userId }` );
136167

137168
await expect(
138169
page
@@ -181,7 +212,7 @@ test.describe( 'Quick Draft', () => {
181212
).toBeVisible();
182213

183214
// Check that the new draft appears in the Posts page.
184-
await admin.visitAdminPage( '/edit.php' );
215+
await admin.visitAdminPage( '/edit.php', `author=${ userId }` );
185216

186217
await expect(
187218
page

‎tests/e2e/specs/edit-posts.test.js‎

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { randomUUID } from 'node:crypto';
5+
16
/**
27
* Internal dependencies
38
*/
49
import { test, expect } from '../fixtures';
510

611
test.describe( 'Edit Posts', () => {
7-
test.beforeEach( async ( { requestUtils }) => {
8-
await requestUtils.deleteAllPosts();
9-
} );
12+
async function visitPostList( admin, title ) {
13+
await admin.visitAdminPage(
14+
'edit.php',
15+
new URLSearchParams( { s: title } ).toString()
16+
);
17+
}
1018

11-
test( 'displays a message in the posts table when no posts are present',async ( {
19+
test( 'displays a message in the posts table when a search finds no posts',async ( {
1220
admin,
1321
page,
1422
} ) => {
15-
await admin.visitAdminPage( '/edit.php' );
23+
await visitPostList( admin, randomUUID() );
1624
await expect(
1725
page.getByRole( 'cell', { name: 'No posts found.' } )
1826
).toBeVisible();
1927
} );
2028

2129
test( 'lists a published post and renders its title and content on the front end', async ( {
2230
admin,
23-
editor,
2431
page,
32+
postFactory,
2533
} ) => {
26-
const title = 'Test Title';
34+
const title = postFactory.uniqueTitle( 'Edit Posts list' );
2735
const content = 'This content should be visible on the published post.';
28-
await admin.createNewPost( { title, content } );
29-
await editor.publishPost();
30-
await admin.visitAdminPage( '/edit.php' );
36+
const post = await postFactory.create( { title, content, status: 'publish' } );
37+
await visitPostList( admin, title );
3138

3239
const listTable = page.getByRole( 'table', { name: 'Table ordered by' } );
3340
await expect( listTable ).toBeVisible();
@@ -36,16 +43,17 @@ test.describe( 'Edit Posts', () => {
3643
await expect(
3744
listTable.locator( '#the-list' ).getByRole( 'row' )
3845
).toHaveCount( 1 );
46+
const row = listTable.locator( `#post-${ post.id }` );
3947

4048
// Expect the title of the post to be correct.
41-
const postLink = listTable.getByRole( 'link', {
49+
const postLink = row.getByRole( 'link', {
4250
name: title,
4351
exact: true,
4452
} );
4553
await expect( postLink ).toBeVisible();
4654

4755
await postLink.hover();
48-
await listTable.getByRole( 'link', { name: `View “${ title }”`, exact: true } ).click();
56+
await row.getByRole( 'link', { name: `View “${ title }”`, exact: true } ).click();
4957
await expect( page.getByRole( 'heading', { name: title, exact: true } ) ).toBeVisible();
5058
await expect( page.getByText( content, { exact: true } ) ).toBeVisible();
5159
} );
@@ -54,17 +62,20 @@ test.describe( 'Edit Posts', () => {
5462
admin,
5563
editor,
5664
page,
65+
postFactory,
5766
} ) => {
58-
const title = 'Test Title';
59-
await admin.createNewPost( { title } );
60-
await editor.publishPost();
61-
await admin.visitAdminPage( '/edit.php' );
67+
const title = postFactory.uniqueTitle( 'Edit Posts edit' );
68+
const post = await postFactory.create( { title, status: 'publish' } );
69+
await visitPostList( admin, title );
6270

6371
const listTable = page.getByRole( 'table', { name: 'Table ordered by' } );
6472
await expect( listTable ).toBeVisible();
6573

6674
// Click the post title (edit) link
67-
await listTable.getByRole( 'link', { name: title, exact: true } ).click();
75+
await listTable
76+
.locator( `#post-${ post.id }` )
77+
.getByRole( 'link', { name: title, exact: true } )
78+
.click();
6879

6980
const editorPostTitle = editor.canvas.getByRole( 'textbox', { name: 'Add title' } );
7081

@@ -76,20 +87,20 @@ test.describe( 'Edit Posts', () => {
7687

7788
test( 'allows an existing post to be quick edited using the Quick Edit button', async ( {
7889
admin,
79-
editor,
8090
page,
81-
pageUtils
91+
pageUtils,
92+
postFactory,
8293
} ) => {
83-
const title = 'Test Title';
84-
await admin.createNewPost( { title } );
85-
await editor.publishPost();
86-
await admin.visitAdminPage( '/edit.php' );
94+
const title = postFactory.uniqueTitle( 'Edit Posts quick edit' );
95+
const post = await postFactory.create( { title, status: 'publish' } );
96+
await visitPostList( admin, title );
8797

8898
const listTable = page.getByRole( 'table', { name: 'Table ordered by' } );
8999
await expect( listTable ).toBeVisible();
100+
const row = listTable.locator( `#post-${ post.id }` );
90101

91102
// // Focus on the post title link.
92-
await listTable.getByRole( 'link', { name: title, exact: true } ).focus();
103+
await row.getByRole( 'link', { name: title, exact: true } ).focus();
93104

94105
// Tab to the Quick Edit button and press Enter to quick edit.
95106
await pageUtils.pressKeys( 'Tab', { times: 2 } );
@@ -108,7 +119,7 @@ test.describe( 'Edit Posts', () => {
108119
await page.getByRole( 'button', { name: 'Update' } ).click();
109120

110121
// Wait for the quick edit button to reappear.
111-
await expect( page.getByRole( 'button', { name: 'Quick Edit' } ) ).toBeVisible();
122+
await expect( row.getByRole( 'button', { name: 'Quick Edit' } ) ).toBeVisible();
112123

113124
// Expect there to be one row in the post list.
114125
await expect(
@@ -117,7 +128,7 @@ test.describe( 'Edit Posts', () => {
117128

118129
// Expect the title of the post to be correct.
119130
await expect(
120-
listTable.getByRole( 'link', {
131+
row.getByRole( 'link', {
121132
name: `${ title } Edited`,
122133
exact: true,
123134
} )
@@ -126,19 +137,19 @@ test.describe( 'Edit Posts', () => {
126137

127138
test( 'allows an existing post to be deleted using the Trash button', async ( {
128139
admin,
129-
editor,
130140
page,
141+
postFactory,
131142
} ) => {
132-
const title = 'Test Title';
133-
await admin.createNewPost( { title } );
134-
await editor.publishPost();
135-
await admin.visitAdminPage( '/edit.php' );
143+
const title = postFactory.uniqueTitle( 'Edit Posts trash' );
144+
const post = await postFactory.create( { title, status: 'publish' } );
145+
await visitPostList( admin, title );
136146

137147
const listTable = page.getByRole( 'table', { name: 'Table ordered by' } );
138148
await expect( listTable ).toBeVisible();
149+
const row = listTable.locator( `#post-${ post.id }` );
139150

140-
await listTable.getByRole( 'link', { name: title, exact: true } ).hover();
141-
await listTable
151+
await row.getByRole( 'link', { name: title, exact: true } ).hover();
152+
await row
142153
.getByRole( 'link', {
143154
name: `Move “${ title }” to the Trash`,
144155
exact: true,

‎tests/e2e/specs/empty-trash-restore-trashed-posts.test.js‎

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
*/
44
import { test, expect } from '../fixtures';
55

6-
const POST_TITLE = 'Test Title';
7-
86
test( 'Undo restores a trashed post to its published status', async ( {
97
page,
108
admin,
@@ -58,55 +56,6 @@ test( 'Undo restores a trashed post to its published status', async ( {
5856
expect( restoredPost.status ).toBe( 'publish' );
5957
} );
6058

61-
test.describe( 'Empty Trash', () => {
62-
test.beforeEach( async ( { requestUtils } ) => {
63-
await requestUtils.deleteAllPosts();
64-
});
65-
66-
test('Empty Trash', async ({ admin, editor, page }) => {
67-
await admin.createNewPost( { title: POST_TITLE } );
68-
await editor.publishPost();
69-
70-
await admin.visitAdminPage( '/edit.php' );
71-
72-
const listTable = page.getByRole( 'table', { name: 'Table ordered by' } );
73-
await expect( listTable ).toBeVisible();
74-
75-
// Move post to trash
76-
await listTable.getByRole( 'link', { name: POST_TITLE, exact: true } ).hover();
77-
await listTable.getByRole( 'link', { name: `Move “${POST_TITLE}” to the Trash` } ).click();
78-
79-
// Empty trash
80-
await page.getByRole( 'link', { name: 'Trash' } ).click();
81-
await page.getByRole( 'button', { name: 'Empty Trash' } ).first().click();
82-
83-
await expect( page.locator( '#message' ) ).toContainText( '1 post permanently deleted.' );
84-
} );
85-
86-
test('Restore trash post', async ( { admin, editor, page }) => {
87-
await admin.createNewPost( { title: POST_TITLE } );
88-
await editor.publishPost();
89-
90-
await admin.visitAdminPage( '/edit.php' );
91-
92-
const listTable = page.getByRole( 'table', { name: 'Table ordered by' } );
93-
await expect( listTable ).toBeVisible();
94-
95-
// Move post to trash
96-
await listTable.getByRole( 'link', { name: POST_TITLE, exact: true } ).hover();
97-
await listTable.getByRole( 'link', { name: `Move “${POST_TITLE}” to the Trash` } ).click();
98-
99-
await page.getByRole( 'link', { name: 'Trash' } ).click();
100-
101-
// Remove post from trash.
102-
await listTable.getByRole( 'cell' ).filter( { hasText: POST_TITLE } ).hover();
103-
await listTable.getByRole( 'link', { name: `Restore “${POST_TITLE}” from the Trash` } ).click();
104-
105-
// Expect for success message for restored post.
106-
await expect( page.locator( '#message' ) ).toContainText( '1 post restored from the Trash.' );
107-
} );
108-
} );
109-
11059
test( 'bulk trashes only the selected posts', async ( {
11160
page,
11261
admin,

0 commit comments

Comments
 (0)