@wordpress/e2e-tests 4.0.0 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/e2e-tests",
3
- "version": "4.0.0",
3
+ "version": "4.0.3",
4
4
  "description": "End-To-End (E2E) tests for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -23,11 +23,11 @@
23
23
  "node": ">=12"
24
24
  },
25
25
  "dependencies": {
26
- "@wordpress/e2e-test-utils": "^7.2.0",
27
- "@wordpress/jest-console": "^5.0.2",
28
- "@wordpress/jest-puppeteer-axe": "^4.0.2",
29
- "@wordpress/scripts": "^22.4.0",
30
- "@wordpress/url": "^3.7.0",
26
+ "@wordpress/e2e-test-utils": "^7.2.1",
27
+ "@wordpress/jest-console": "^5.0.3",
28
+ "@wordpress/jest-puppeteer-axe": "^4.0.3",
29
+ "@wordpress/scripts": "^22.4.2",
30
+ "@wordpress/url": "^3.7.1",
31
31
  "chalk": "^4.0.0",
32
32
  "expect-puppeteer": "^4.4.0",
33
33
  "filenamify": "^4.2.0",
@@ -46,5 +46,5 @@
46
46
  "publishConfig": {
47
47
  "access": "public"
48
48
  },
49
- "gitHead": "11eb1241e63c9240018323551c6753f8a5fa96f9"
49
+ "gitHead": "37e930b93fbba88fa024a91eb527a90f855c97f3"
50
50
  }
@@ -1429,5 +1429,43 @@ describe( 'Navigation', () => {
1429
1429
  '//*[contains(@class, "components-snackbar")]/*[text()="Navigation Menu successfully created."]'
1430
1430
  );
1431
1431
  } );
1432
+
1433
+ it( 'should always focus select menu button after item selection', async () => {
1434
+ // Create some navigation menus to work with.
1435
+ await createNavigationMenu( {
1436
+ title: 'Example Navigation',
1437
+ content:
1438
+ '<!-- wp:navigation-link {"label":"WordPress","type":"custom","url":"http://www.wordpress.org/","kind":"custom","isTopLevelLink":true} /-->',
1439
+ } );
1440
+ await createNavigationMenu( {
1441
+ title: 'Second Example Navigation',
1442
+ content:
1443
+ '<!-- wp:navigation-link {"label":"WordPress","type":"custom","url":"http://www.wordpress.org/","kind":"custom","isTopLevelLink":true} /-->',
1444
+ } );
1445
+
1446
+ // Create new post.
1447
+ await createNewPost();
1448
+
1449
+ // Insert new block and wait for the insert to complete.
1450
+ await insertBlock( 'Navigation' );
1451
+ await waitForBlock( 'Navigation' );
1452
+ await page.waitForXPath( START_EMPTY_XPATH );
1453
+
1454
+ // Change menus via the select menu toolbar button.
1455
+ const selectMenuDropdown = await page.waitForSelector(
1456
+ '[aria-label="Select Menu"]'
1457
+ );
1458
+ await selectMenuDropdown.click();
1459
+ const exampleNavigationOption = await page.waitForXPath(
1460
+ '//span[contains(text(), "Second Example Navigation")]'
1461
+ );
1462
+ await exampleNavigationOption.click();
1463
+
1464
+ // Once the options are closed, does select menu button receive focus?
1465
+ const selectMenuDropdown2 = await page.waitForSelector(
1466
+ '[aria-label="Select Menu"]'
1467
+ );
1468
+ await expect( selectMenuDropdown2 ).toHaveFocus();
1469
+ } );
1432
1470
  } );
1433
1471
  } );
@@ -33,9 +33,14 @@ describe( 'Query block', () => {
33
33
  describe( 'Query block insertion', () => {
34
34
  it( 'Carousel', async () => {
35
35
  await insertBlock( 'Query' );
36
+ // Wait for the choose pattern button
37
+ const choosePatternButton = await page.waitForSelector(
38
+ 'div[data-type="core/query"] button.is-primary'
39
+ );
40
+ await choosePatternButton.click();
36
41
  // Wait for pattern blocks to be loaded.
37
42
  await page.waitForSelector(
38
- '.block-editor-block-pattern-setup__container .wp-block-post-title'
43
+ '.block-editor-block-pattern-setup__container iframe[title="Editor canvas"]'
39
44
  );
40
45
  /**
41
46
  * Ensure that carousel is working by checking slider css classes
@@ -70,6 +75,11 @@ describe( 'Query block', () => {
70
75
  } );
71
76
  it( 'Grid view', async () => {
72
77
  await insertBlock( 'Query' );
78
+ // Wait for the choose pattern button
79
+ const choosePatternButton = await page.waitForSelector(
80
+ 'div[data-type="core/query"] button.is-primary'
81
+ );
82
+ await choosePatternButton.click();
73
83
  // Wait for patterns setup to be loaded.
74
84
  await page.waitForSelector(
75
85
  '.block-editor-block-pattern-setup__display-controls'
@@ -80,8 +90,8 @@ describe( 'Query block', () => {
80
90
  );
81
91
  await gridViewButton.click();
82
92
  // Wait for patterns to be loaded and click the wanted pattern.
83
- const gridPattern = await page.waitForXPath(
84
- '//div[@class="block-editor-block-pattern-setup-list__item-title" and contains(text(), "Query Test 2")]'
93
+ const gridPattern = await page.waitForSelector(
94
+ '.block-editor-block-pattern-setup-list__list-item[aria-label="Query Test 2"]'
85
95
  );
86
96
  await gridPattern.click();
87
97
  // Wait for pattern setup to go away.
@@ -9,6 +9,7 @@ import {
9
9
  pressKeyWithModifier,
10
10
  insertBlock,
11
11
  clickBlockToolbarButton,
12
+ openDocumentSettingsSidebar,
12
13
  } from '@wordpress/e2e-test-utils';
13
14
 
14
15
  const getActiveBlockName = async () =>
@@ -701,7 +702,7 @@ describe( 'Writing Flow', () => {
701
702
  ).toBe( 'Table' );
702
703
  } );
703
704
 
704
- it( 'Should unselect all blocks when hitting double escape', async () => {
705
+ it( 'should unselect all blocks when hitting double escape', async () => {
705
706
  // Add demo content.
706
707
  await page.keyboard.press( 'Enter' );
707
708
  await page.keyboard.type( 'Random Paragraph' );
@@ -720,4 +721,33 @@ describe( 'Writing Flow', () => {
720
721
  activeBlockName = await getActiveBlockName();
721
722
  expect( activeBlockName ).toBe( undefined );
722
723
  } );
724
+
725
+ // Checks for regressions of https://github.com/WordPress/gutenberg/issues/40091.
726
+ it( 'does not deselect the block when selecting text outside the editor canvas', async () => {
727
+ await page.keyboard.press( 'Enter' );
728
+ await page.keyboard.type( 'Random Paragraph' );
729
+ await openDocumentSettingsSidebar();
730
+ const blockDescription = await page.waitForSelector(
731
+ '.block-editor-block-card__description'
732
+ );
733
+ const boundingBox = await blockDescription.boundingBox();
734
+ const startPosition = {
735
+ x: boundingBox.x + 10,
736
+ y: boundingBox.y + 8,
737
+ };
738
+ const endPosition = {
739
+ x: startPosition.x + 50,
740
+ y: startPosition.y,
741
+ };
742
+
743
+ await page.mouse.move( startPosition.x, startPosition.y );
744
+ await page.mouse.down();
745
+ await page.mouse.move( endPosition.x, endPosition.y );
746
+ await page.mouse.up();
747
+
748
+ const selectedParagraph = await page.waitForSelector(
749
+ '.wp-block-paragraph.is-selected'
750
+ );
751
+ expect( selectedParagraph ).toBeDefined();
752
+ } );
723
753
  } );
@@ -24,11 +24,21 @@ describe( 'Comment Query Loop', () => {
24
24
  'newest'
25
25
  );
26
26
  } );
27
+ it( 'We show no results message if there are no comments', async () => {
28
+ await trashAllComments();
29
+ await createNewPost();
30
+ await insertBlock( 'Comments Query Loop' );
31
+ await page.waitForSelector( '[data-testid="noresults"]' );
32
+ expect(
33
+ await page.evaluate(
34
+ ( el ) => el.innerText,
35
+ await page.$( '[data-testid="noresults"]' )
36
+ )
37
+ ).toEqual( 'No results found.' );
38
+ } );
27
39
  it( 'Pagination links are working as expected', async () => {
28
40
  await createNewPost();
29
- // Insert the Query Comment Loop block.
30
41
  await insertBlock( 'Comments Query Loop' );
31
- // Insert the Comment Loop form.
32
42
  await insertBlock( 'Post Comments Form' );
33
43
  await publishPost();
34
44
  // Visit the post that was just published.
@@ -89,9 +99,7 @@ describe( 'Comment Query Loop', () => {
89
99
  it( 'Pagination links are not appearing if break comments is not enabled', async () => {
90
100
  await setOption( 'page_comments', '0' );
91
101
  await createNewPost();
92
- // Insert the Query Comment Loop block.
93
102
  await insertBlock( 'Comments Query Loop' );
94
- // Insert the Comment Loop form.
95
103
  await insertBlock( 'Post Comments Form' );
96
104
  await publishPost();
97
105
  // Visit the post that was just published.
@@ -0,0 +1,46 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ insertBlock,
6
+ activateTheme,
7
+ setOption,
8
+ visitSiteEditor,
9
+ openSiteEditorNavigationPanel,
10
+ navigateSiteEditorBackToRoot,
11
+ deleteAllTemplates,
12
+ canvas,
13
+ } from '@wordpress/e2e-test-utils';
14
+
15
+ describe( 'Post Comments Form', () => {
16
+ beforeAll( async () => {
17
+ await activateTheme( 'emptytheme' );
18
+ await deleteAllTemplates( 'wp_template' );
19
+ } );
20
+
21
+ describe( 'placeholder', () => {
22
+ it( 'displays in site editor even when comments are closed by default', async () => {
23
+ await setOption( 'default_comment_status', 'closed' );
24
+
25
+ // Navigate to "Singular" post template
26
+ await visitSiteEditor();
27
+ await openSiteEditorNavigationPanel();
28
+ await navigateSiteEditorBackToRoot();
29
+ await expect( page ).toClick(
30
+ '.components-navigation__item-title',
31
+ { text: /templates/i }
32
+ );
33
+ await expect( page ).toClick( '.components-heading > a', {
34
+ text: /singular/i,
35
+ } );
36
+
37
+ // Insert post comments form
38
+ await insertBlock( 'Post Comments Form' );
39
+
40
+ // Ensure the placeholder is there
41
+ await expect( canvas() ).toMatchElement(
42
+ '.wp-block-post-comments-form .comment-form'
43
+ );
44
+ } );
45
+ } );
46
+ } );
@@ -0,0 +1,42 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ deleteAllTemplates,
6
+ activateTheme,
7
+ visitSiteEditor,
8
+ toggleGlobalStyles,
9
+ openGlobalStylesPanel,
10
+ } from '@wordpress/e2e-test-utils';
11
+
12
+ describe( 'Global styles sidebar', () => {
13
+ beforeAll( async () => {
14
+ await activateTheme( 'emptytheme' );
15
+ await Promise.all( [
16
+ deleteAllTemplates( 'wp_template' ),
17
+ deleteAllTemplates( 'wp_template_part' ),
18
+ ] );
19
+ } );
20
+ afterAll( async () => {
21
+ await Promise.all( [
22
+ deleteAllTemplates( 'wp_template' ),
23
+ deleteAllTemplates( 'wp_template_part' ),
24
+ ] );
25
+ await activateTheme( 'twentytwentyone' );
26
+ } );
27
+ beforeEach( async () => {
28
+ await visitSiteEditor();
29
+ } );
30
+ describe( 'blocks list', () => {
31
+ it( 'should filter results properly', async () => {
32
+ await toggleGlobalStyles();
33
+ await openGlobalStylesPanel( 'Blocks' );
34
+ await page.focus( '.edit-site-block-types-search input' );
35
+ await page.keyboard.type( 'heading' );
36
+ const results = await page.$$(
37
+ '.edit-site-block-types-item-list div[role="listitem"]'
38
+ );
39
+ expect( results.length ).toEqual( 1 );
40
+ } );
41
+ } );
42
+ } );
@@ -1,27 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`Post Editor Template mode Allow creating custom block templates in classic themes 1`] = `
4
- "<a class=\\"skip-link screen-reader-text\\" href=\\"#wp--skip-link--target\\">Skip to content</a>
5
- <header class=\\"wp-block-group\\"><h1 class=\\"wp-block-site-title\\"><a href=\\"http://localhost:8889\\" rel=\\"home\\">gutenberg</a></h1>
6
-
7
- <p class=\\"wp-block-site-tagline\\">Just another WordPress site</p></header>
8
-
9
-
10
-
11
- <hr class=\\"wp-block-separator\\">
12
-
13
-
14
-
15
- <main class=\\"wp-block-group\\" id=\\"wp--skip-link--target\\">
16
- <div class=\\"wp-block-group\\"><div class=\\"wp-block-group__inner-container\\"><div class=\\"wp-block-group__inner-container\\"><h2 class=\\"wp-block-post-title\\">Another FSE Post</h2></div></div></div>
17
-
18
-
19
- <div class=\\"entry-content wp-block-post-content\\">
20
- <p>Hello World</p>
21
- </div></main>
22
-
23
-
24
-
25
- <p>Just a random paragraph added to the template</p>
26
- "
27
- `;
@@ -1,377 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import {
5
- activateTheme,
6
- createNewPost,
7
- insertBlock,
8
- saveDraft,
9
- openPreviewPage,
10
- openDocumentSettingsSidebar,
11
- activatePlugin,
12
- deactivatePlugin,
13
- deleteAllTemplates,
14
- setBrowserViewport,
15
- } from '@wordpress/e2e-test-utils';
16
-
17
- const openSidebarPanelWithTitle = async ( title ) => {
18
- const panel = await page.waitForXPath(
19
- `//div[contains(@class,"edit-post-sidebar")]//button[@class="components-button components-panel__body-toggle"][contains(text(),"${ title }")]`
20
- );
21
-
22
- const expanded = await page.evaluate(
23
- ( element ) => element.getAttribute( 'aria-expanded' ),
24
- panel
25
- );
26
- if ( expanded === 'false' ) {
27
- await panel.click();
28
- }
29
- };
30
-
31
- const disableTemplateWelcomeGuide = async () => {
32
- // Turn off the welcome guide if it's visible.
33
- const isWelcomeGuideActive = await page.evaluate( () =>
34
- wp.data
35
- .select( 'core/edit-post' )
36
- .isFeatureActive( 'welcomeGuideTemplate' )
37
- );
38
- if ( isWelcomeGuideActive ) {
39
- await page.evaluate( () =>
40
- wp.data
41
- .dispatch( 'core/edit-post' )
42
- .toggleFeature( 'welcomeGuideTemplate' )
43
- );
44
- }
45
- };
46
-
47
- const switchToTemplateMode = async () => {
48
- await disableTemplateWelcomeGuide();
49
-
50
- // Switch to template mode.
51
- await openDocumentSettingsSidebar();
52
- await openSidebarPanelWithTitle( 'Template' );
53
- const editTemplateXPath =
54
- "//*[contains(@class, 'edit-post-template__actions')]//button[contains(text(), 'Edit')]";
55
- const switchLink = await page.waitForXPath( editTemplateXPath );
56
- await switchLink.click();
57
-
58
- // Check that we switched properly to edit mode.
59
- await page.waitForXPath(
60
- '//*[text()="Editing template. Changes made here affect all posts and pages that use the template."]'
61
- );
62
- const title = await page.$eval(
63
- '.edit-post-template-top-area',
64
- ( el ) => el.innerText
65
- );
66
- expect( title ).toContain( 'Just an FSE Post\n' );
67
- };
68
-
69
- const createNewTemplate = async ( templateName ) => {
70
- await disableTemplateWelcomeGuide();
71
-
72
- // Create a new custom template.
73
- await openDocumentSettingsSidebar();
74
- await openSidebarPanelWithTitle( 'Template' );
75
- const newTemplateXPath =
76
- "//*[contains(@class, 'edit-post-template__actions')]//button[contains(text(), 'New')]";
77
- const newButton = await page.waitForXPath( newTemplateXPath );
78
- await newButton.click();
79
-
80
- // Fill the template title and submit.
81
- const templateNameInputSelector =
82
- '.edit-post-template__modal .components-text-control__input';
83
- await page.click( templateNameInputSelector );
84
- await page.keyboard.type( templateName );
85
- await page.keyboard.press( 'Enter' );
86
-
87
- // Check that we switched properly to edit mode.
88
- await page.waitForXPath(
89
- '//*[contains(@class, "components-snackbar")]/*[text()="Custom template created. You\'re in template mode now."]'
90
- );
91
- };
92
-
93
- describe( 'Post Editor Template mode', () => {
94
- beforeAll( async () => {
95
- await activatePlugin( 'gutenberg-test-block-templates' );
96
- await deleteAllTemplates( 'wp_template' );
97
- await deleteAllTemplates( 'wp_template_part' );
98
- } );
99
-
100
- afterAll( async () => {
101
- await activateTheme( 'twentytwentyone' );
102
- await deactivatePlugin( 'gutenberg-test-block-templates' );
103
- } );
104
-
105
- it( 'Allow to switch to template mode, edit the template and check the result', async () => {
106
- await activateTheme( 'emptytheme' );
107
- await createNewPost();
108
- // Create a random post.
109
- await page.type( '.editor-post-title__input', 'Just an FSE Post' );
110
- await page.keyboard.press( 'Enter' );
111
- await page.keyboard.type( 'Hello World' );
112
-
113
- // Unselect the blocks.
114
- await page.evaluate( () => {
115
- wp.data.dispatch( 'core/block-editor' ).clearSelectedBlock();
116
- } );
117
-
118
- // Save the post
119
- // Saving shouldn't be necessary but unfortunately,
120
- // there's a template resolution bug forcing us to do so.
121
- await saveDraft();
122
- await page.reload();
123
- await switchToTemplateMode();
124
-
125
- // Edit the template.
126
- await insertBlock( 'Paragraph' );
127
- await page.keyboard.type(
128
- 'Just a random paragraph added to the template'
129
- );
130
-
131
- // Save changes.
132
- const publishButton = await page.waitForXPath(
133
- `//button[contains(text(), 'Publish')]`
134
- );
135
- await publishButton.click();
136
- const saveButton = await page.waitForXPath(
137
- `//div[contains(@class, "entities-saved-states__panel-header")]/button[contains(text(), 'Save')]`
138
- );
139
- await saveButton.click();
140
-
141
- // Preview changes.
142
- const previewPage = await openPreviewPage();
143
- await previewPage.waitForXPath(
144
- '//p[contains(text(), "Just a random paragraph added to the template")]'
145
- );
146
- } );
147
-
148
- it.skip( 'Allow creating custom block templates in classic themes', async () => {
149
- await activateTheme( 'twentytwentyone' );
150
- await createNewPost();
151
- // Create a random post.
152
- await page.type( '.editor-post-title__input', 'Another FSE Post' );
153
- await page.keyboard.press( 'Enter' );
154
- await page.keyboard.type( 'Hello World' );
155
-
156
- // Unselect the blocks.
157
- await page.evaluate( () => {
158
- wp.data.dispatch( 'core/block-editor' ).clearSelectedBlock();
159
- } );
160
-
161
- // Save the post
162
- // Saving shouldn't be necessary but unfortunately,
163
- // there's a template resolution bug forcing us to do so.
164
- await saveDraft();
165
- await page.reload();
166
-
167
- await createNewTemplate( 'Blank Template' );
168
-
169
- // Edit the template.
170
- await insertBlock( 'Paragraph' );
171
- await page.keyboard.type(
172
- 'Just a random paragraph added to the template'
173
- );
174
-
175
- // Save changes.
176
- const publishButton = await page.waitForXPath(
177
- `//button[contains(text(), 'Publish')]`
178
- );
179
- await publishButton.click();
180
- const saveButton = await page.waitForXPath(
181
- `//div[contains(@class, "entities-saved-states__panel-header")]/button[contains(text(), 'Save')]`
182
- );
183
- await saveButton.click();
184
- // Avoid publishing the post
185
- const cancelButton = await page.waitForXPath(
186
- `//button[contains(text(), 'Cancel')]`
187
- );
188
- await cancelButton.click();
189
-
190
- // Preview changes.
191
- const previewPage = await openPreviewPage();
192
- await previewPage.waitForSelector( '.wp-site-blocks' );
193
- const content = await previewPage.evaluate(
194
- () => document.querySelector( '.wp-site-blocks' ).innerHTML
195
- );
196
-
197
- expect( content ).toMatchSnapshot();
198
- } );
199
- } );
200
-
201
- describe( 'Delete Post Template Confirmation Dialog', () => {
202
- beforeAll( async () => {
203
- await activatePlugin( 'gutenberg-test-block-templates' );
204
- await deleteAllTemplates( 'wp_template' );
205
- await deleteAllTemplates( 'wp_template_part' );
206
- await activateTheme( 'twentytwentyone' );
207
- await createNewPost();
208
- // Create a random post.
209
- await page.type( '.editor-post-title__input', 'Just an FSE Post' );
210
- await page.keyboard.press( 'Enter' );
211
- await page.keyboard.type( 'Hello World' );
212
-
213
- // Save the post
214
- // Saving shouldn't be necessary but unfortunately,
215
- // there's a template resolution bug forcing us to do so.
216
- await saveDraft();
217
- await page.reload();
218
- // Unselect the blocks.
219
- await page.evaluate( () => {
220
- wp.data.dispatch( 'core/block-editor' ).clearSelectedBlock();
221
- } );
222
- } );
223
-
224
- afterAll( async () => {
225
- await activateTheme( 'twentytwentyone' );
226
- await deactivatePlugin( 'gutenberg-test-block-templates' );
227
- } );
228
-
229
- [ 'large', 'small' ].forEach( ( viewport ) => {
230
- it( `should retain template if deletion is canceled when the viewport is ${ viewport }`, async () => {
231
- await setBrowserViewport( viewport );
232
-
233
- const isWelcomeGuideActive = await page.evaluate(
234
- () =>
235
- !! wp.data
236
- .select( 'core/preferences' )
237
- .get( 'core/edit-post', 'welcomeGuide' )
238
- );
239
- if ( isWelcomeGuideActive === true ) {
240
- await page.evaluate( () =>
241
- wp.data
242
- .dispatch( 'core/preferences' )
243
- .toggle( 'core/edit-post', 'welcomeGuide' )
244
- );
245
- await page.reload();
246
- await page.waitForSelector( '.edit-post-layout' );
247
- }
248
- if ( viewport === 'small' ) {
249
- await page.waitForXPath( '//button[@aria-label="Settings"]' );
250
- await openDocumentSettingsSidebar();
251
- }
252
- const templateTitle = `${ viewport } Viewport Deletion Test`;
253
-
254
- await createNewTemplate( templateTitle );
255
- // Edit the template
256
- if ( viewport === 'small' ) {
257
- await page.waitForXPath( `//h2[text()="${ templateTitle }"]` );
258
- const closeDocumentSettingsButton = await page.waitForXPath(
259
- '//button[@aria-label="Close settings"]'
260
- );
261
- await closeDocumentSettingsButton.click();
262
- }
263
- await insertBlock( 'Paragraph' );
264
- await page.keyboard.type(
265
- 'Just a random paragraph added to the template'
266
- );
267
-
268
- // Save changes
269
- const publishButton = await page.waitForXPath(
270
- `//button[contains(text(), 'Publish')]`
271
- );
272
- await publishButton.click();
273
- const saveButton = await page.waitForXPath(
274
- `//div[contains(@class, "entities-saved-states__panel-header")]/button[contains(text(), 'Save')]`
275
- );
276
- await saveButton.click();
277
- // Avoid publishing the post
278
- // Select the cancel button via parent div's class, because the text `Cancel` is used on another button as well
279
- const cancelButton = await page.waitForXPath(
280
- `//div[contains(@class,"editor-post-publish-panel__header-cancel-button")]/button[not(@disabled)]`
281
- );
282
- await cancelButton.click();
283
-
284
- const templateDropdown = await page.waitForXPath(
285
- `//button[contains(text(), '${ templateTitle }')]`
286
- );
287
- await templateDropdown.click();
288
- const deleteTemplateButton = await page.waitForXPath(
289
- '//button[@role="menuitem"][@aria-label="Delete template"]'
290
- );
291
- await deleteTemplateButton.click();
292
-
293
- await page.waitForXPath(
294
- `//*[text()="Are you sure you want to delete the ${ templateTitle } template? It may be used by other pages or posts."]`
295
- );
296
- const dialogCancelButton = await page.waitForXPath(
297
- '//*[@role="dialog"][not(@id="wp-link-wrap")]//button[text()="Cancel"]'
298
- );
299
- await dialogCancelButton.click();
300
-
301
- const exitTemplateModeButton = await page.waitForXPath(
302
- '//button[text()="Back"]'
303
- );
304
- await exitTemplateModeButton.click();
305
-
306
- await page.waitForXPath(
307
- '//button[@aria-label="Settings"][@aria-expanded="false"]'
308
- );
309
- await openDocumentSettingsSidebar();
310
-
311
- const element = await page.waitForXPath(
312
- '//h2/button[contains(text(), "Template")]/../..//select'
313
- );
314
- const value = await element.getProperty( 'value' );
315
- const currentTemplateSlug = await value.jsonValue();
316
-
317
- expect( currentTemplateSlug ).toBe(
318
- `wp-custom-template-${ viewport }-viewport-deletion-test`
319
- );
320
- } );
321
-
322
- it( `should delete template if deletion is confirmed when the viewport is ${ viewport }`, async () => {
323
- const templateTitle = `${ viewport } Viewport Deletion Test`;
324
-
325
- await setBrowserViewport( viewport );
326
-
327
- await switchToTemplateMode();
328
- if ( viewport === 'small' ) {
329
- const closeDocumentSettingsButton = await page.waitForXPath(
330
- '//div[contains(@class,"interface-complementary-area-header__small")]/button[@aria-label="Close settings"]'
331
- );
332
- await closeDocumentSettingsButton.click();
333
- }
334
-
335
- const templateDropdown = await page.waitForXPath(
336
- `//button[contains(text(), '${ templateTitle }')]`
337
- );
338
- await templateDropdown.click();
339
-
340
- const deleteTemplateButton = await page.waitForXPath(
341
- '//button[@role="menuitem"][@aria-label="Delete template"]'
342
- );
343
- await deleteTemplateButton.click();
344
-
345
- await page.waitForXPath(
346
- `//*[text()="Are you sure you want to delete the ${ templateTitle } template? It may be used by other pages or posts."]`
347
- );
348
- const dialogConfirmButton = await page.waitForXPath(
349
- '//*[@role="dialog"][not(@id="wp-link-wrap")]//button[text()="OK"]'
350
- );
351
-
352
- await dialogConfirmButton.click();
353
-
354
- // Saving isn't technically necessary, but for themes without any specified templates,
355
- // the removal of the Templates dropdown is delayed. A save and reload allows for this
356
- // delay and prevents flakiness
357
- await saveDraft();
358
- await page.reload();
359
-
360
- const optionElementHandlers = await page.$x(
361
- '//h2/button[contains(text(), "Template")]/../..//select/option'
362
- );
363
- const availableTemplates = [];
364
- for ( const elem of optionElementHandlers ) {
365
- const elemName = await elem.getProperty( 'textContent' );
366
- const templateName = await elemName.jsonValue();
367
- availableTemplates.push( templateName );
368
- }
369
-
370
- expect(
371
- availableTemplates.includes(
372
- `${ viewport } Viewport Deletion Test`
373
- )
374
- ).toBe( false );
375
- } );
376
- } );
377
- } );
@@ -1,90 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import {
5
- deleteAllTemplates,
6
- activateTheme,
7
- visitSiteEditor,
8
- } from '@wordpress/e2e-test-utils';
9
-
10
- async function getDocumentSettingsTitle() {
11
- const titleElement = await page.waitForSelector(
12
- '.edit-site-document-actions__title'
13
- );
14
-
15
- return titleElement.evaluate( ( el ) => el.textContent );
16
- }
17
-
18
- async function getDocumentSettingsSecondaryTitle() {
19
- const secondaryTitleElement = await page.waitForSelector(
20
- '.edit-site-document-actions__secondary-item'
21
- );
22
-
23
- return secondaryTitleElement.evaluate( ( el ) => el.textContent );
24
- }
25
-
26
- describe( 'Document Settings', () => {
27
- beforeAll( async () => {
28
- await activateTheme( 'emptytheme' );
29
- await deleteAllTemplates( 'wp_template' );
30
- await deleteAllTemplates( 'wp_template_part' );
31
- } );
32
- afterAll( async () => {
33
- await activateTheme( 'twentytwentyone' );
34
- } );
35
-
36
- beforeEach( async () => {
37
- await visitSiteEditor();
38
- } );
39
-
40
- describe( 'when a template is selected from the navigation sidebar', () => {
41
- it( 'should display the selected templates name in the document header', async () => {
42
- // Navigate to a template.
43
- await visitSiteEditor( {
44
- postId: 'emptytheme//index',
45
- postType: 'wp_template',
46
- } );
47
-
48
- // Evaluate the document settings title.
49
- const actual = await getDocumentSettingsTitle();
50
-
51
- expect( actual ).toEqual( 'Editing template: Index' );
52
- } );
53
-
54
- describe( 'and a template part is clicked in the template', () => {
55
- it.skip( "should display the selected template part's name in the document header", async () => {
56
- // Select the header template part via list view.
57
- await page.click(
58
- '.edit-post-header-toolbar__list-view-toggle'
59
- );
60
- const headerTemplatePartListViewButton = await page.waitForXPath(
61
- '//a[contains(@class, "block-editor-list-view-block-select-button")][contains(., "Header")]'
62
- );
63
- headerTemplatePartListViewButton.click();
64
- await page.click(
65
- 'button[aria-label="Close List View Sidebar"]'
66
- );
67
-
68
- // Evaluate the document settings secondary title.
69
- const actual = await getDocumentSettingsSecondaryTitle();
70
-
71
- expect( actual ).toEqual( 'Editing template part: header' );
72
- } );
73
- } );
74
- } );
75
-
76
- describe( 'when a template part is selected from the navigation sidebar', () => {
77
- it( "should display the selected template part's name in the document header", async () => {
78
- // Navigate to a template part.
79
- await visitSiteEditor( {
80
- postId: 'emptytheme//header',
81
- postType: 'wp_template_part',
82
- } );
83
-
84
- // Evaluate the document settings title.
85
- const actual = await getDocumentSettingsTitle();
86
-
87
- expect( actual ).toEqual( 'Editing template part: header' );
88
- } );
89
- } );
90
- } );