/
shortcut-focus-toolbar.spec.js
269 lines (241 loc) · 8.41 KB
/
shortcut-focus-toolbar.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
test.use( {
toolbarUtils: async ( { page, pageUtils }, use ) => {
await use( new ToolbarUtils( { page, pageUtils } ) );
},
} );
test.describe( 'Focus toolbar shortcut (alt + F10)', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
} );
test( 'Focuses correct toolbar in default view options in edit mode', async ( {
editor,
page,
toolbarUtils,
} ) => {
// Test: Focus the top level toolbar from title
await toolbarUtils.moveToToolbarShortcut();
await expect( toolbarUtils.documentToolbarButton ).toBeFocused();
// Test: Focus document toolbar from empty block
await editor.insertBlock( { name: 'core/paragraph' } );
await toolbarUtils.moveToToolbarShortcut();
await expect( toolbarUtils.documentToolbarButton ).toBeFocused();
// Test: Focus block toolbar from block content when block toolbar isn't visible
await editor.insertBlock( { name: 'core/paragraph' } );
await page.keyboard.type(
"Focus to block toolbar when block toolbar isn't visible"
);
await toolbarUtils.moveToToolbarShortcut();
await expect( toolbarUtils.blockToolbarParagraphButton ).toBeFocused();
await expect( toolbarUtils.documentToolbarTooltip ).not.toBeVisible();
// Test: Focus block toolbar from block content when block toolbar is visible
await editor.insertBlock( { name: 'core/paragraph' } );
await page.keyboard.type(
'Focus to block toolbar when block toolbar is visible'
);
// We need to force the toolbar to show. Otherwise, the bug from
// https://github.com/WordPress/gutenberg/pull/49644 won't surface in the e2e tests.
await editor.showBlockToolbar();
await toolbarUtils.moveToToolbarShortcut();
await expect( toolbarUtils.blockToolbarParagraphButton ).toBeFocused();
await expect( toolbarUtils.documentToolbarTooltip ).not.toBeVisible();
} );
test( 'Focuses correct toolbar in default view options in select mode', async ( {
editor,
page,
toolbarUtils,
} ) => {
// Test: Focus the document toolbar from title
await toolbarUtils.useSelectMode();
await toolbarUtils.moveToToolbarShortcut();
await expect( toolbarUtils.documentToolbarButton ).toBeFocused();
// Test: Focus the top level toolbar from empty block
await editor.insertBlock( { name: 'core/paragraph' } );
await toolbarUtils.useSelectMode();
await toolbarUtils.moveToToolbarShortcut();
await expect( toolbarUtils.documentToolbarButton ).toBeFocused();
// Test: Focus the top level toolbar from paragraph block
await editor.insertBlock( { name: 'core/paragraph' } );
await page.keyboard.type(
'Focus top level toolbar from paragraph block in select mode.'
);
await toolbarUtils.useSelectMode();
await toolbarUtils.moveToToolbarShortcut();
await expect( toolbarUtils.documentToolbarButton ).toBeFocused();
} );
test.describe( 'In Top Toolbar option:', () => {
test.beforeEach( async ( { editor } ) => {
// Ensure the fixed toolbar option is on
await editor.setIsFixedToolbar( true );
} );
test( 'Focuses the correct toolbar in edit mode', async ( {
editor,
page,
toolbarUtils,
} ) => {
// Test: Focus the document toolbar from title
await toolbarUtils.moveToToolbarShortcut();
await expect( toolbarUtils.documentToolbarButton ).toBeFocused();
// Test: Focus the block toolbar from empty block
await editor.insertBlock( { name: 'core/paragraph' } );
await toolbarUtils.moveToToolbarShortcut();
await expect(
toolbarUtils.blockToolbarShowDocumentButton
).toBeFocused();
await expect(
toolbarUtils.documentToolbarTooltip
).not.toBeVisible();
// Test: Focus the block toolbar from paragraph block with content
await editor.insertBlock( { name: 'core/paragraph' } );
await page.keyboard.type(
'Focus the block toolbar from paragraph block with content'
);
await toolbarUtils.moveToToolbarShortcut();
await expect(
toolbarUtils.blockToolbarShowDocumentButton
).toBeFocused();
await expect(
toolbarUtils.documentToolbarTooltip
).not.toBeVisible();
} );
test( 'Focuses the correct toolbar in select mode', async ( {
editor,
page,
toolbarUtils,
} ) => {
// Test: Focus the document toolbar from title
await toolbarUtils.useSelectMode();
await toolbarUtils.moveToToolbarShortcut();
await expect( toolbarUtils.documentToolbarButton ).toBeFocused();
// Test: Focus the block toolbar from empty block
await editor.insertBlock( { name: 'core/paragraph' } );
await toolbarUtils.useSelectMode();
await toolbarUtils.moveToToolbarShortcut();
await expect(
toolbarUtils.blockToolbarShowDocumentButton
).toBeFocused();
await expect(
toolbarUtils.documentToolbarTooltip
).not.toBeVisible();
// Test: Focus the block toolbar from paragraph in select mode
await editor.insertBlock( { name: 'core/paragraph' } );
await page.keyboard.type(
'Focus the block toolbar from paragraph in select mode'
);
await toolbarUtils.useSelectMode();
await toolbarUtils.moveToToolbarShortcut();
await expect(
toolbarUtils.blockToolbarShowDocumentButton
).toBeFocused();
await expect(
toolbarUtils.documentToolbarTooltip
).not.toBeVisible();
} );
} );
test.describe( 'Smaller than large viewports', () => {
test.use( {
// Make the viewport small enough to trigger the fixed toolbar
viewport: {
width: 700,
height: 700,
},
} );
test.beforeEach( async ( { editor } ) => {
// Ensure the fixed toolbar option is off
await editor.setIsFixedToolbar( false );
} );
test( 'Focuses the correct toolbar in edit mode', async ( {
editor,
page,
toolbarUtils,
} ) => {
// Test: Focus the document toolbar from title
await toolbarUtils.moveToToolbarShortcut();
await expect( toolbarUtils.documentToolbarButton ).toBeFocused();
// Test: Focus the block toolbar from empty block
await editor.insertBlock( { name: 'core/paragraph' } );
await toolbarUtils.moveToToolbarShortcut();
await expect(
toolbarUtils.blockToolbarParagraphButton
).toBeFocused();
await expect(
toolbarUtils.documentToolbarTooltip
).not.toBeVisible();
// Test: Focus the block toolbar from paragraph block with content
await editor.insertBlock( { name: 'core/paragraph' } );
await page.keyboard.type(
'Focus the block toolbar from paragraph block with content'
);
await toolbarUtils.moveToToolbarShortcut();
await expect(
toolbarUtils.blockToolbarParagraphButton
).toBeFocused();
await expect(
toolbarUtils.documentToolbarTooltip
).not.toBeVisible();
} );
test( 'Focuses the correct toolbar in select mode', async ( {
editor,
page,
toolbarUtils,
} ) => {
// Test: Focus the document toolbar from title
await toolbarUtils.useSelectMode();
await toolbarUtils.moveToToolbarShortcut();
await expect( toolbarUtils.documentToolbarButton ).toBeFocused();
// Test: Focus the block toolbar from empty block
await editor.insertBlock( { name: 'core/paragraph' } );
await toolbarUtils.useSelectMode();
await toolbarUtils.moveToToolbarShortcut();
await expect(
toolbarUtils.blockToolbarParagraphButton
).toBeFocused();
await expect(
toolbarUtils.documentToolbarTooltip
).not.toBeVisible();
// Test: Focus the block toolbar from paragraph in select mode
await editor.insertBlock( { name: 'core/paragraph' } );
await page.keyboard.type(
'Focus the block toolbar from paragraph in select mode'
);
await toolbarUtils.useSelectMode();
await toolbarUtils.moveToToolbarShortcut();
await expect(
toolbarUtils.blockToolbarParagraphButton
).toBeFocused();
await expect(
toolbarUtils.documentToolbarTooltip
).not.toBeVisible();
} );
} );
} );
class ToolbarUtils {
constructor( { page, pageUtils } ) {
this.page = page;
this.pageUtils = pageUtils;
this.documentToolbarButton = this.page.getByRole( 'button', {
name: 'Toggle block inserter',
exact: true,
} );
this.documentToolbarTooltip = this.page.locator(
'text=Toggle block inserter'
);
this.blockToolbarParagraphButton = this.page.getByRole( 'button', {
name: 'Paragraph',
exact: true,
} );
this.blockToolbarShowDocumentButton = this.page.getByRole( 'button', {
name: 'Show document tools',
exact: true,
} );
}
async useSelectMode() {
await this.page.keyboard.press( 'Escape' );
}
async moveToToolbarShortcut() {
await this.pageUtils.pressKeys( 'alt+F10' );
}
}