-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
plugins-api.spec.js
254 lines (217 loc) · 6.25 KB
/
plugins-api.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
test.describe( 'Plugins API', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activatePlugin(
'gutenberg-test-plugin-plugins-api'
);
} );
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
} );
test.afterAll( async ( { requestUtils } ) => {
await requestUtils.deactivatePlugin(
'gutenberg-test-plugin-plugins-api'
);
} );
test.describe( 'Post Status Info', () => {
test( 'Should render post status info inside Document Setting sidebar', async ( {
editor,
page,
} ) => {
await editor.openDocumentSettingsSidebar();
await expect(
page
.getByRole( 'region', { name: 'Editor settings' } )
.locator( '.my-post-status-info-plugin' )
).toHaveText( 'My post status info' );
} );
} );
test.describe( 'Publish Panel', () => {
test( 'Should render publish panel inside Pre-publish sidebar', async ( {
editor,
page,
} ) => {
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'A post' );
// Open pre-publish panel.
await page
.getByRole( 'region', { name: 'Editor top bar' } )
.getByRole( 'button', { name: 'Publish' } )
.click();
await expect(
page
.getByRole( 'region', { name: 'Editor publish' } )
.getByRole( 'button', { name: 'My pre publish panel' } )
).toBeVisible();
} );
test( 'Should render publish panel inside Post-publish sidebar', async ( {
editor,
page,
} ) => {
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'A post' );
await editor.publishPost();
await expect(
page
.getByRole( 'region', { name: 'Editor publish' } )
.getByRole( 'button', { name: 'My post publish panel' } )
).toBeVisible();
} );
} );
test.describe( 'Sidebar', () => {
test( 'Should open plugins sidebar using More Menu item and render content', async ( {
page,
} ) => {
await page
.getByRole( 'region', { name: 'Editor top bar' } )
.getByRole( 'button', { name: 'Options' } )
.click();
await page
.getByRole( 'menuitemcheckbox', {
name: 'Plugin more menu title',
} )
.click();
const settingsSidebar = page.getByRole( 'region', {
name: 'Editor settings',
} );
await expect(
settingsSidebar.getByRole( 'textbox', {
name: 'Title',
} )
).toBeVisible();
await expect(
settingsSidebar.getByRole( 'button', {
name: 'Reset',
} )
).toBeVisible();
} );
test( 'Should be pinned by default and can be opened and closed using pinned items', async ( {
page,
} ) => {
const pinnedButton = page
.getByRole( 'region', { name: 'Editor top bar' } )
.getByRole( 'button', { name: 'Plugin title' } );
const pluginField = page
.getByRole( 'region', {
name: 'Editor settings',
} )
.getByRole( 'textbox', {
name: 'Title',
} );
await pinnedButton.click();
await expect( pluginField ).toBeVisible();
await pinnedButton.click();
await expect( pluginField ).toBeHidden();
} );
test( 'Can be pinned and unpinned', async ( { page } ) => {
const pinnedButton = page
.getByRole( 'region', { name: 'Editor top bar' } )
.getByRole( 'button', { name: 'Plugin title' } );
await pinnedButton.click();
await page
.getByRole( 'button', { name: 'Unpin from toolbar' } )
.click();
await expect( pinnedButton ).toBeHidden();
await page.getByRole( 'button', { name: 'Close plugin' } ).click();
await page.reload();
await expect( pinnedButton ).toBeHidden();
await page
.getByRole( 'region', { name: 'Editor top bar' } )
.getByRole( 'button', { name: 'Options' } )
.click();
await page
.getByRole( 'menuitemcheckbox', {
name: 'Plugin more menu title',
} )
.click();
await page
.getByRole( 'button', { name: 'Pin to toolbar' } )
.click();
await expect( pinnedButton ).toBeVisible();
await page.reload();
await expect( pinnedButton ).toBeVisible();
} );
test( 'Should close plugins sidebar using More Menu item', async ( {
page,
} ) => {
const options = page
.getByRole( 'region', { name: 'Editor top bar' } )
.getByRole( 'button', { name: 'Options' } );
const moreMenuItem = page.getByRole( 'menuitemcheckbox', {
name: 'Plugin more menu title',
} );
const pluginField = page
.getByRole( 'region', {
name: 'Editor settings',
} )
.getByRole( 'textbox', {
name: 'Title',
} );
await options.click();
await moreMenuItem.click();
await expect( pluginField ).toBeVisible();
await options.click();
await moreMenuItem.click();
await expect( pluginField ).toBeHidden();
} );
test( 'Should open plugins sidebar using More Menu item on smaller screens', async ( {
page,
pageUtils,
} ) => {
await pageUtils.setBrowserViewport( 'medium' );
await page
.getByRole( 'region', { name: 'Editor top bar' } )
.getByRole( 'button', { name: 'Options' } )
.click();
await page
.getByRole( 'menuitemcheckbox', {
name: 'Plugin more menu title',
} )
.click();
await expect(
page
.getByRole( 'region', {
name: 'Editor settings',
} )
.getByRole( 'textbox', {
name: 'Title',
} )
).toBeVisible();
await pageUtils.setBrowserViewport( 'large' );
} );
} );
test.describe( 'Document Setting Custom Panel', () => {
test( 'Should render a custom panel inside Document Setting sidebar', async ( {
editor,
page,
} ) => {
await editor.openDocumentSettingsSidebar();
await expect(
page
.getByRole( 'region', { name: 'Editor settings' } )
.getByRole( 'button', { name: 'My Custom Panel' } )
).toBeVisible();
} );
} );
test.describe( 'Preview Menu Item', () => {
test( 'Should render and interact with PluginPreviewMenuItem', async ( {
page,
} ) => {
await page
.getByRole( 'region', { name: 'Editor top bar' } )
.locator( '.editor-preview-dropdown__toggle' )
.click();
const customPreviewItem = page.getByRole( 'menuitem', {
name: 'Custom Preview',
} );
await expect( customPreviewItem ).toBeVisible();
await customPreviewItem.click();
await expect( customPreviewItem ).toBeHidden();
} );
} );
} );