@@ -8,63 +8,158 @@ test.describe( 'Quick Draft', () => {
88 await requestUtils . deleteAllPosts ( ) ;
99 } ) ;
1010
11- test ( 'Allows draft to be created with Title and Content' , async ( {
11+ test ( 'should allow Quick Draft to be created with Title and Content' , async ( {
1212 admin,
1313 page
1414 } ) => {
1515 await admin . visitAdminPage ( '/' ) ;
1616
17- // Wait for Quick Draft title field to appear.
17+ // Wait for the Quick Draft title field to appear.
1818 const draftTitleField = page . locator (
1919 '#quick-press'
2020 ) . getByRole ( 'textbox' , { name : 'Title' } ) ;
2121
2222 await expect ( draftTitleField ) . toBeVisible ( ) ;
2323
2424 // Focus and fill in a title.
25- await draftTitleField . fill ( 'Test Draft Title ' ) ;
25+ await draftTitleField . fill ( 'Quick Draft test title ' ) ;
2626
27- // Navigate to content field and type in some content
28- await page . keyboard . press ( 'Tab' ) ;
29- await page . keyboard . type ( 'Test Draft Content' ) ;
27+ // Wait for the Quick Draft content textarea to appear.
28+ const quickDraftContentTextarea = page . locator (
29+ '#quick-press'
30+ ) . getByRole ( 'textbox' , { name : 'Content' } ) ;
31+
32+ await expect ( quickDraftContentTextarea ) . toBeVisible ( ) ;
33+
34+ // Focus and fill in some content.
35+ await quickDraftContentTextarea . fill ( 'Quick Draft test content' ) ;
36+
37+ // Wait for the Save Draft button to appear and click it.
38+ const saveDraftButton = page . locator (
39+ '#quick-press'
40+ ) . getByRole ( 'button' , { name : 'Save Draft' } ) ;
3041
31- // Navigate to Save Draft button and press it.
32- await page . keyboard . press ( 'Tab' ) ;
33- await page . keyboard . press ( 'Enter' ) ;
42+ await expect ( saveDraftButton ) . toBeVisible ( ) ;
43+ await saveDraftButton . click ( ) ;
3444
35- // Check that new draft appears in Your Recent Drafts section
45+ // Check that the new draft title appears in the ' Your Recent Drafts' section.
3646 await expect (
3747 page . locator ( '.drafts .draft-title' ) . first ( ) . getByRole ( 'link' )
38- ) . toHaveText ( 'Test Draft Title' ) ;
48+ ) . toHaveText ( 'Quick Draft test title' ) ;
49+
50+ // Check that the new draft content appears in the 'Your Recent Drafts' section.
51+ await expect (
52+ page . locator ( '.drafts .draft-content' ) . first ( )
53+ ) . toHaveText ( 'Quick Draft test content' ) ;
3954
40- // Check that new draft appears in Posts page
55+ // Check that the new draft appears in the Posts page.
4156 await admin . visitAdminPage ( '/edit.php' ) ;
4257
4358 await expect (
4459 page . locator ( '.type-post.status-draft .title' ) . first ( )
45- ) . toContainText ( 'Test Draft Title ' ) ;
60+ ) . toContainText ( 'Quick Draft test title ' ) ;
4661 } ) ;
4762
48- test ( 'Allows draft to be created without Title or Content' , async ( {
63+ test ( 'should prevent Quick Draft from being created without Title and Content' , async ( {
4964 admin,
5065 page
5166 } ) => {
5267 await admin . visitAdminPage ( '/' ) ;
5368
54- // Wait for Save Draft button to appear and click it
69+ // Wait for the Save Draft button to appear and click it.
5570 const saveDraftButton = page . locator (
5671 '#quick-press'
5772 ) . getByRole ( 'button' , { name : 'Save Draft' } ) ;
5873
5974 await expect ( saveDraftButton ) . toBeVisible ( ) ;
6075 await saveDraftButton . click ( ) ;
6176
62- // Check that new draft appears in Your Recent Drafts section
77+ // Check that an admin notice with ARIA role 'alert' appears.
78+ await expect (
79+ page . locator ( '#quick-press' ) . getByRole ( 'alert' )
80+ ) . toHaveText ( 'Cannot create a draft post with empty title and content.' ) ;
81+
82+ // Check that no new draft appears in the Posts page.
83+ await admin . visitAdminPage ( '/edit.php' ) ;
84+
85+ await expect (
86+ page . locator ( '#the-list .no-items .colspanchange' )
87+ ) . toContainText ( 'No posts found.' ) ;
88+ } ) ;
89+
90+ test ( 'should allow Quick Draft to be created with only the Title' , async ( {
91+ admin,
92+ page
93+ } ) => {
94+ await admin . visitAdminPage ( '/' ) ;
95+
96+ // Wait for the Quick Draft title field to appear.
97+ const quickDraftTitleField = page . locator (
98+ '#quick-press'
99+ ) . getByRole ( 'textbox' , { name : 'Title' } ) ;
100+
101+ await expect ( quickDraftTitleField ) . toBeVisible ( ) ;
102+
103+ // Focus and fill in a title.
104+ await quickDraftTitleField . fill ( 'Quick Draft test title' ) ;
105+
106+ // Wait for the Save Draft button to appear and click it.
107+ const saveDraftButton = page . locator (
108+ '#quick-press'
109+ ) . getByRole ( 'button' , { name : 'Save Draft' } ) ;
110+
111+ await expect ( saveDraftButton ) . toBeVisible ( ) ;
112+ await saveDraftButton . click ( ) ;
113+
114+ // Check that the new draft title appears in the 'Your Recent Drafts' section.
115+ await expect (
116+ page . locator ( '.drafts .draft-title' ) . first ( ) . getByRole ( 'link' )
117+ ) . toHaveText ( 'Quick Draft test title' ) ;
118+
119+ // Check that the new draft appears in the Posts page.
120+ await admin . visitAdminPage ( '/edit.php' ) ;
121+
122+ await expect (
123+ page . locator ( '.type-post.status-draft .title' ) . first ( )
124+ ) . toContainText ( 'Quick Draft test title' ) ;
125+ } ) ;
126+
127+ test ( 'should allow Quick Draft to be created with only the Content' , async ( {
128+ admin,
129+ page
130+ } ) => {
131+ await admin . visitAdminPage ( '/' ) ;
132+
133+ // Wait for the Quick Draft content textarea to appear.
134+ const quickDraftContentTextarea = page . locator (
135+ '#quick-press'
136+ ) . getByRole ( 'textbox' , { name : 'Content' } ) ;
137+
138+ await expect ( quickDraftContentTextarea ) . toBeVisible ( ) ;
139+
140+ // Focus and fill in some content.
141+ await quickDraftContentTextarea . fill ( 'Quick Draft test content' ) ;
142+
143+ // Wait for the Save Draft button to appear and click it.
144+ const saveDraftButton = page . locator (
145+ '#quick-press'
146+ ) . getByRole ( 'button' , { name : 'Save Draft' } ) ;
147+
148+ await expect ( saveDraftButton ) . toBeVisible ( ) ;
149+ await saveDraftButton . click ( ) ;
150+
151+ // Check that the new draft title appears in the 'Your Recent Drafts' section.
152+ // This test relies on Twenty Twenty-One being the active theme.
153+ // Twenty Twenty-One alters the default post title from "(no title)" to "Untitled".
63154 await expect (
64155 page . locator ( '.drafts .draft-title' ) . first ( ) . getByRole ( 'link' )
65156 ) . toHaveText ( 'Untitled' ) ;
66157
67- // Check that new draft appears in Posts page
158+ await expect (
159+ page . locator ( '.drafts .draft-content' ) . first ( )
160+ ) . toHaveText ( 'Quick Draft test content' ) ;
161+
162+ // Check that the new draft appears in the Posts page.
68163 await admin . visitAdminPage ( '/edit.php' ) ;
69164
70165 await expect (
0 commit comments