Skip to content

Commit 0e425ad

Browse files
committed
Build/Test Tools: Cover moving selected posts to Trash in bulk.
Add a browser test that selects two published posts and moves them to Trash through the bulk-action form. Verify both saved statuses become `trash` while an unselected control remains visible and published. Create fixtures through REST and delete only those posts during cleanup. Developed in: #8040 Props juhise, lucatume. See #52895. git-svn-id: https://develop.svn.wordpress.org/trunk@64619 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 06c9868 commit 0e425ad

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,68 @@ test.describe( 'Empty Trash', () => {
116116
await expect( page.locator( '#message' ) ).toContainText( '1 post restored from the Trash.' );
117117
} );
118118
} );
119+
120+
test( 'bulk trashes only the selected posts', async ( {
121+
page,
122+
admin,
123+
requestUtils,
124+
} ) => {
125+
const posts = [];
126+
const titlePrefix = `Bulk trash ${ Date.now() }`;
127+
128+
try {
129+
for ( const suffix of [ 'first', 'second', 'control' ] ) {
130+
posts.push(
131+
await requestUtils.createPost( {
132+
title: `${ titlePrefix } ${ suffix }`,
133+
status: 'publish',
134+
} )
135+
);
136+
}
137+
138+
await admin.visitAdminPage(
139+
'edit.php',
140+
new URLSearchParams( { s: titlePrefix } ).toString()
141+
);
142+
for ( const post of posts.slice( 0, 2 ) ) {
143+
await page
144+
.locator( `#post-${ post.id }` )
145+
.getByRole( 'checkbox' )
146+
.check();
147+
}
148+
await page
149+
.locator( '#bulk-action-selector-top' )
150+
.selectOption( 'trash' );
151+
await page.locator( '#doaction' ).click();
152+
await expect( page.locator( '#message' ) ).toContainText(
153+
'2 posts moved to the Trash.'
154+
);
155+
156+
for ( const post of posts.slice( 0, 2 ) ) {
157+
await expect( page.locator( `#post-${ post.id }` ) ).toHaveCount(
158+
0
159+
);
160+
const savedPost = await requestUtils.rest( {
161+
path: `/wp/v2/posts/${ post.id }`,
162+
params: { context: 'edit' },
163+
} );
164+
expect( savedPost.status ).toBe( 'trash' );
165+
}
166+
await expect(
167+
page.locator( `#post-${ posts[ 2 ].id }` )
168+
).toBeVisible();
169+
const control = await requestUtils.rest( {
170+
path: `/wp/v2/posts/${ posts[ 2 ].id }`,
171+
params: { context: 'edit' },
172+
} );
173+
expect( control.status ).toBe( 'publish' );
174+
} finally {
175+
for ( const post of posts ) {
176+
await requestUtils.rest( {
177+
method: 'DELETE',
178+
path: `/wp/v2/posts/${ post.id }`,
179+
params: { force: true },
180+
} );
181+
}
182+
}
183+
} );

0 commit comments

Comments
 (0)