1+ /**
2+ * External dependencies
3+ */
4+ import { randomUUID } from 'node:crypto' ;
5+
16/**
27 * Internal dependencies
38 */
49import { test , expect } from '../fixtures' ;
510
611test . 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 ,
0 commit comments