/
new-post.spec.js
105 lines (88 loc) · 2.65 KB
/
new-post.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
test.describe( 'new editor state', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activatePlugin(
'gutenberg-test-plugin-post-formats-support'
);
} );
test.afterAll( async ( { requestUtils } ) => {
await requestUtils.deactivatePlugin(
'gutenberg-test-plugin-post-formats-support'
);
} );
test( 'should show the New Post page in Gutenberg', async ( {
admin,
page,
editor,
} ) => {
await admin.createNewPost();
await expect( page ).toHaveURL( /post-new.php/ );
// Should display the blank title.
const title = editor.canvas.locator(
'role=textbox[name="Add title"i]'
);
await expect( title ).toBeEditable();
await expect( title ).toHaveText( '' );
// Should display the View button.
await expect(
page.locator( 'role=button[name="View"i]' )
).toBeVisible();
// Should display the Post Formats UI.
await editor.openDocumentSettingsSidebar();
await expect(
page.locator( 'role=combobox[name="Post Format"i]' )
).toBeVisible();
} );
test( 'should have no history', async ( { admin, page } ) => {
await admin.createNewPost();
await expect(
page.locator( 'role=button[name="Undo"i]' )
).toBeDisabled();
await expect(
page.locator( 'role=button[name="Redo"i]' )
).toBeDisabled();
} );
test( 'should focus the title if the title is empty', async ( {
admin,
editor,
} ) => {
await admin.createNewPost();
await expect(
editor.canvas.locator( 'role=textbox[name="Add title"i]' )
).toBeFocused();
} );
test( 'should not focus the title if the title exists', async ( {
admin,
page,
editor,
} ) => {
await admin.createNewPost();
// Enter a title for this post.
await editor.canvas
.locator( 'role=textbox[name="Add title"i]' )
.type( 'Here is the title' );
// Save the post as a draft.
await editor.saveDraft();
// Reload the browser so a post is loaded with a title.
await page.reload();
await page.waitForSelector( '.edit-post-layout' );
// The document `body` should be the `activeElement`, because nothing is
// focused by default when a post already has a title.
await expect( page.locator( 'body' ) ).toBeFocused();
} );
test( 'should be saveable with sufficient initial edits', async ( {
admin,
page,
} ) => {
await admin.createNewPost( { title: 'Here is the title' } );
// Verify saveable by presence of the Save Draft button.
const saveDraftButton = page.locator(
'role=button[name="Save draft"i]'
);
await expect( saveDraftButton ).toBeVisible();
await expect( saveDraftButton ).toBeEnabled();
} );
} );