Skip to content

Commit 70d7e25

Browse files
committed
Build/Test Tools: Cover changing selected posts to drafts in bulk.
Add a browser test that uses Bulk Edit to change two published posts to drafts. Verify the draft labels after reload and both saved statuses, while an unselected control remains published. Create fixtures through REST and delete only those posts during cleanup. Developed in: #8045 Props juhise, lucatume. See #52895. git-svn-id: https://develop.svn.wordpress.org/trunk@64620 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 0e425ad commit 70d7e25

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,85 @@ test.describe( 'Edit Posts', () => {
139139
).toBeVisible();
140140
} );
141141
} );
142+
143+
test( 'bulk edits only the selected posts', async ( {
144+
page,
145+
admin,
146+
requestUtils,
147+
} ) => {
148+
const posts = [];
149+
const titlePrefix = `Bulk edit ${ Date.now() }`;
150+
151+
try {
152+
for ( const suffix of [ 'first', 'second', 'control' ] ) {
153+
posts.push(
154+
await requestUtils.createPost( {
155+
title: `${ titlePrefix } ${ suffix }`,
156+
status: 'publish',
157+
} )
158+
);
159+
}
160+
161+
await admin.visitAdminPage(
162+
'edit.php',
163+
new URLSearchParams( { s: titlePrefix } ).toString()
164+
);
165+
for ( const post of posts.slice( 0, 2 ) ) {
166+
await page
167+
.locator( `#post-${ post.id }` )
168+
.getByRole( 'checkbox' )
169+
.check();
170+
}
171+
await page
172+
.getByRole( 'combobox', {
173+
name: 'Select bulk action',
174+
exact: true,
175+
} )
176+
.first()
177+
.selectOption( 'edit' );
178+
await page
179+
.getByRole( 'button', { name: 'Apply', exact: true } )
180+
.first()
181+
.click();
182+
const bulkEdit = page.getByRole( 'region', {
183+
name: 'Bulk Edit',
184+
exact: true,
185+
} );
186+
await bulkEdit
187+
.getByRole( 'combobox', { name: 'Status', exact: true } )
188+
.selectOption( 'draft' );
189+
await bulkEdit
190+
.getByRole( 'button', { name: 'Update', exact: true } )
191+
.click();
192+
await expect( page.locator( '#message' ) ).toContainText(
193+
'2 posts updated.'
194+
);
195+
196+
await page.reload();
197+
for ( const post of posts.slice( 0, 2 ) ) {
198+
await expect(
199+
page
200+
.locator( `#post-${ post.id }` )
201+
.getByText( 'Draft', { exact: true } )
202+
).toBeVisible();
203+
const savedPost = await requestUtils.rest( {
204+
path: `/wp/v2/posts/${ post.id }`,
205+
params: { context: 'edit' },
206+
} );
207+
expect( savedPost.status ).toBe( 'draft' );
208+
}
209+
const control = await requestUtils.rest( {
210+
path: `/wp/v2/posts/${ posts[ 2 ].id }`,
211+
params: { context: 'edit' },
212+
} );
213+
expect( control.status ).toBe( 'publish' );
214+
} finally {
215+
for ( const post of posts ) {
216+
await requestUtils.rest( {
217+
method: 'DELETE',
218+
path: `/wp/v2/posts/${ post.id }`,
219+
params: { force: true },
220+
} );
221+
}
222+
}
223+
} );

0 commit comments

Comments
 (0)