@wordpress/e2e-tests 7.22.2 → 7.23.0

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.
Files changed (27) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/package.json +9 -9
  3. package/plugins/interactive-blocks/directive-bind/render.php +1 -1
  4. package/plugins/interactive-blocks/directive-context/view.js +1 -1
  5. package/plugins/interactive-blocks/directive-each/render.php +2 -2
  6. package/plugins/interactive-blocks/directive-each/view.js +1 -1
  7. package/plugins/interactive-blocks/directive-init/render.php +1 -1
  8. package/plugins/interactive-blocks/directive-key/render.php +1 -1
  9. package/plugins/interactive-blocks/directive-key/view.js +1 -1
  10. package/plugins/interactive-blocks/directive-on/render.php +1 -1
  11. package/plugins/interactive-blocks/directive-on-document/render.php +2 -2
  12. package/plugins/interactive-blocks/directive-on-window/render.php +1 -1
  13. package/plugins/interactive-blocks/directive-priorities/render.php +2 -2
  14. package/plugins/interactive-blocks/directive-run/render.php +2 -2
  15. package/plugins/interactive-blocks/directive-run/view.js +1 -1
  16. package/plugins/interactive-blocks/directive-style/render.php +1 -1
  17. package/plugins/interactive-blocks/directive-text/render.php +1 -1
  18. package/plugins/interactive-blocks/directive-watch/render.php +1 -1
  19. package/plugins/interactive-blocks/negation-operator/render.php +1 -1
  20. package/plugins/interactive-blocks/store/block.json +15 -0
  21. package/plugins/interactive-blocks/store/render.php +17 -0
  22. package/plugins/interactive-blocks/store/view.js +20 -0
  23. package/plugins/interactive-blocks/store-tag/render.php +1 -1
  24. package/plugins/interactive-blocks/tovdom/render.php +1 -1
  25. package/plugins/interactive-blocks/tovdom-islands/render.php +8 -8
  26. package/plugins/interactive-blocks/with-scope/render.php +1 -1
  27. package/specs/editor/various/change-detection.test.js +0 -417
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 7.23.0 (2024-02-21)
6
+
5
7
  ## 7.22.0 (2024-02-09)
6
8
 
7
9
  ## 7.21.0 (2024-01-24)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/e2e-tests",
3
- "version": "7.22.2",
3
+ "version": "7.23.0",
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,13 +23,13 @@
23
23
  "node": ">=14"
24
24
  },
25
25
  "dependencies": {
26
- "@wordpress/e2e-test-utils": "^10.22.1",
27
- "@wordpress/interactivity": "^5.0.1",
28
- "@wordpress/interactivity-router": "^1.1.1",
29
- "@wordpress/jest-console": "^7.22.1",
30
- "@wordpress/jest-puppeteer-axe": "^6.22.1",
31
- "@wordpress/scripts": "^27.2.2",
32
- "@wordpress/url": "^3.52.1",
26
+ "@wordpress/e2e-test-utils": "^10.23.0",
27
+ "@wordpress/interactivity": "^5.1.0",
28
+ "@wordpress/interactivity-router": "^1.2.0",
29
+ "@wordpress/jest-console": "^7.23.0",
30
+ "@wordpress/jest-puppeteer-axe": "^6.23.0",
31
+ "@wordpress/scripts": "^27.3.0",
32
+ "@wordpress/url": "^3.53.0",
33
33
  "chalk": "^4.0.0",
34
34
  "expect-puppeteer": "^4.4.0",
35
35
  "filenamify": "^4.2.0",
@@ -46,5 +46,5 @@
46
46
  "publishConfig": {
47
47
  "access": "public"
48
48
  },
49
- "gitHead": "b12d75c5c5256fda2a0509bb432e20ddd3354d5e"
49
+ "gitHead": "c139588f4c668b38bafbc5431f2f4e3903dbe683"
50
50
  }
@@ -8,7 +8,7 @@
8
8
  wp_enqueue_script_module( 'directive-bind-view' );
9
9
  ?>
10
10
 
11
- <div data-wp-interactive='{ "namespace": "directive-bind" }'>
11
+ <div data-wp-interactive="directive-bind">
12
12
  <a
13
13
  data-wp-bind--href="state.url"
14
14
  data-testid="add missing href at hydration"
@@ -27,7 +27,7 @@ store( 'directive-context', {
27
27
 
28
28
  const html = `
29
29
  <div
30
- data-wp-interactive='{ "namespace": "directive-context-navigate" }'
30
+ data-wp-interactive="directive-context-navigate"
31
31
  data-wp-router-region="navigation"
32
32
  data-wp-context='{ "text": "second page" }'
33
33
  >
@@ -8,7 +8,7 @@
8
8
  wp_enqueue_script_module( 'directive-each-view' );
9
9
  ?>
10
10
 
11
- <div data-wp-interactive='{ "namespace": "directive-each" }'>
11
+ <div data-wp-interactive="directive-each">
12
12
  <div data-testid="letters">
13
13
  <template data-wp-each="state.letters">
14
14
  <p data-wp-text="context.item" data-testid="item"></p>
@@ -220,7 +220,7 @@ wp_enqueue_script_module( 'directive-each-view' );
220
220
  <hr>
221
221
 
222
222
  <div
223
- data-wp-interactive='{ "namespace": "directive-each" }'
223
+ data-wp-interactive="directive-each"
224
224
  data-wp-router-region="navigation-updated list"
225
225
  data-wp-context='{ "list": [ "beta", "gamma", "delta" ] }'
226
226
  data-testid="navigation-updated list"
@@ -157,7 +157,7 @@ store( 'directive-each', {
157
157
 
158
158
  const html = `
159
159
  <div
160
- data-wp-interactive='{ "namespace": "directive-each" }'
160
+ data-wp-interactive="directive-each"
161
161
  data-wp-router-region="navigation-updated list"
162
162
  data-wp-context='{ "list": [ "alpha", "beta", "gamma", "delta" ] }'
163
163
  data-testid="navigation-updated list"
@@ -8,7 +8,7 @@
8
8
  wp_enqueue_script_module( 'directive-init-view' );
9
9
  ?>
10
10
 
11
- <div data-wp-interactive='{ "namespace": "directive-init" }'>
11
+ <div data-wp-interactive="directive-init">
12
12
  <div
13
13
  data-testid="single init"
14
14
  data-wp-context='{"isReady":[false],"calls":[0]}'
@@ -9,7 +9,7 @@ wp_enqueue_script_module( 'directive-key-view' );
9
9
  ?>
10
10
 
11
11
  <div
12
- data-wp-interactive='{ "namespace": "directive-key" }'
12
+ data-wp-interactive="directive-key"
13
13
  data-wp-router-region="some-id"
14
14
  >
15
15
  <ul>
@@ -5,7 +5,7 @@ import { store } from '@wordpress/interactivity';
5
5
 
6
6
  const html = `
7
7
  <div
8
- data-wp-interactive='{ "namespace": "directive-key" }'
8
+ data-wp-interactive="directive-key"
9
9
  data-wp-router-region="some-id"
10
10
  >
11
11
  <ul>
@@ -8,7 +8,7 @@
8
8
  wp_enqueue_script_module( 'directive-on-view' );
9
9
  ?>
10
10
 
11
- <div data-wp-interactive='{ "namespace": "directive-on" }'>
11
+ <div data-wp-interactive="directive-on">
12
12
  <div>
13
13
  <p data-wp-text="state.counter" data-testid="counter">0</p>
14
14
  <button
@@ -8,8 +8,8 @@
8
8
  wp_enqueue_script_module( 'directive-on-document-view' );
9
9
  ?>
10
10
 
11
- <div data-wp-interactive='{ "namespace": "directive-on-document" }'>
12
- <button
11
+ <div data-wp-interactive="directive-on-document">
12
+ <button
13
13
  data-testid="visibility"
14
14
  data-wp-on--click="actions.visibilityHandler"
15
15
  >
@@ -8,7 +8,7 @@
8
8
  wp_enqueue_script_module( 'directive-on-window-view' );
9
9
  ?>
10
10
 
11
- <div data-wp-interactive='{ "namespace": "directive-on-window" }'>
11
+ <div data-wp-interactive="directive-on-window">
12
12
  <button
13
13
  data-wp-on--click="actions.visibilityHandler"
14
14
  data-testid="visibility">
@@ -8,7 +8,7 @@
8
8
  wp_enqueue_script_module( 'directive-priorities-view' );
9
9
  ?>
10
10
 
11
- <div data-wp-interactive='{ "namespace": "directive-priorities" }'>
11
+ <div data-wp-interactive="directive-priorities">
12
12
  <pre data-testid="execution order"></pre>
13
13
 
14
14
  <!-- Element with test directives -->
@@ -25,5 +25,5 @@ wp_enqueue_script_module( 'directive-priorities-view' );
25
25
  <!-- WARNING: the `div` with `data-wp-non-existent-directive` should remain
26
26
  inline (i.e., without new line or blank characters in between) to
27
27
  ensure it is the only child node. Otherwise, tests could fail. -->
28
- <div data-wp-interactive='{ "namespace": "directive-priorities" }'><div data-wp-non-existent-directive></div></div>
28
+ <div data-wp-interactive="directive-priorities"><div data-wp-non-existent-directive></div></div>
29
29
  </div>
@@ -9,7 +9,7 @@ wp_enqueue_script_module( 'directive-run-view' );
9
9
  ?>
10
10
 
11
11
  <div
12
- data-wp-interactive='{ "namespace": "directive-run" }'
12
+ data-wp-interactive="directive-run"
13
13
  data-wp-router-region='test-directive-run'
14
14
  >
15
15
  <div data-testid="hydrated" data-wp-text="state.isHydrated"></div>
@@ -24,7 +24,7 @@ wp_enqueue_script_module( 'directive-run-view' );
24
24
  ></div>
25
25
  </div>
26
26
 
27
- <div data-wp-interactive='{ "namespace": "directive-run" }' >
27
+ <div data-wp-interactive="directive-run" >
28
28
  <button data-testid="toggle" data-wp-on--click="actions.toggle">
29
29
  Toggle
30
30
  </button>
@@ -29,7 +29,7 @@ directive(
29
29
 
30
30
  const html = `
31
31
  <div
32
- data-wp-interactive='{ "namespace": "directive-run" }'
32
+ data-wp-interactive="directive-run"
33
33
  data-wp-router-region='test-directive-run'
34
34
  >
35
35
  <div data-testid="hydrated" data-wp-text="state.isHydrated"></div>
@@ -8,7 +8,7 @@
8
8
  wp_enqueue_script_module( 'directive-style-view' );
9
9
  ?>
10
10
 
11
- <div data-wp-interactive='{ "namespace": "directive-style" }'>
11
+ <div data-wp-interactive="directive-style">
12
12
  <button
13
13
  data-wp-on--click="actions.toggleColor"
14
14
  data-testid="toggle color"
@@ -8,7 +8,7 @@
8
8
  wp_enqueue_script_module( 'directive-text-view' );
9
9
  ?>
10
10
 
11
- <div data-wp-interactive='{ "namespace": "directive-context" }'>
11
+ <div data-wp-interactive="directive-context">
12
12
  <div>
13
13
  <span
14
14
  data-wp-text="state.text"
@@ -8,7 +8,7 @@
8
8
  wp_enqueue_script_module( 'directive-watch-view' );
9
9
  ?>
10
10
 
11
- <div data-wp-interactive='{ "namespace": "directive-watch" }'>
11
+ <div data-wp-interactive="directive-watch">
12
12
  <div data-wp-show-mock="state.isOpen">
13
13
  <input
14
14
  data-testid="input"
@@ -8,7 +8,7 @@
8
8
  wp_enqueue_script_module( 'negation-operator-view' );
9
9
  ?>
10
10
 
11
- <div data-wp-interactive='{ "namespace": "negation-operator" }'>
11
+ <div data-wp-interactive="negation-operator">
12
12
  <button
13
13
  data-wp-on--click="actions.toggle"
14
14
  data-testid="toggle active value"
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 2,
4
+ "name": "test/store",
5
+ "title": "E2E Interactivity tests - store definition",
6
+ "category": "text",
7
+ "icon": "heart",
8
+ "description": "",
9
+ "supports": {
10
+ "interactivity": true
11
+ },
12
+ "textdomain": "e2e-interactivity",
13
+ "viewScript": "store-view",
14
+ "render": "file:./render.php"
15
+ }
@@ -0,0 +1,17 @@
1
+ <?php
2
+ /**
3
+ * HTML for testing the directive `data-wp-bind`.
4
+ *
5
+ * @package gutenberg-test-interactive-blocks
6
+ */
7
+
8
+ wp_enqueue_script_module( 'store-view' );
9
+ ?>
10
+
11
+ <div data-wp-interactive="test/store">
12
+ <div
13
+ data-testid="non-plain object"
14
+ data-wp-text="state.isNotProxified"
15
+ data-wp-init="callbacks.init"
16
+ ></div>
17
+ </div>
@@ -0,0 +1,20 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { store, getElement } from '@wordpress/interactivity';
5
+
6
+
7
+ const { state } = store( 'test/store', {
8
+ state: {
9
+ get isNotProxified() {
10
+ const { ref } = getElement();
11
+ return state.elementRef === ref;
12
+ }
13
+ },
14
+ callbacks: {
15
+ init() {
16
+ const { ref } = getElement();
17
+ state.elementRef = ref; // HTMLElement
18
+ }
19
+ }
20
+ } )
@@ -14,7 +14,7 @@ $test_store_tag_counter = 'ok' === $attributes['condition'] ? 3 : 0;
14
14
  $test_store_tag_double = $test_store_tag_counter * 2;
15
15
  ?>
16
16
 
17
- <div data-wp-interactive='{ "namespace": "store-tag" }'>
17
+ <div data-wp-interactive="store-tag">
18
18
  <div>
19
19
  Counter:
20
20
  <span
@@ -12,7 +12,7 @@ $src_cdata = $plugin_url . 'tovdom/cdata.js';
12
12
  wp_enqueue_script_module( 'tovdom-view' );
13
13
  ?>
14
14
 
15
- <div data-wp-interactive='{ "namespace": "tovdom" }'>
15
+ <div data-wp-interactive="tovdom">
16
16
  <div data-testid="it should delete comments">
17
17
  <!-- ##1## -->
18
18
  <div data-testid="it should keep this node between comments">
@@ -15,7 +15,7 @@ wp_enqueue_script_module( 'tovdom-islands-view' );
15
15
  </span>
16
16
  </div>
17
17
 
18
- <div data-wp-interactive='{ "namespace": "tovdom-islands" }'>
18
+ <div data-wp-interactive="tovdom-islands">
19
19
  <div data-wp-show-mock="state.falseValue">
20
20
  <span data-testid="inside an island with json object">
21
21
  This should not be shown because it is inside an island.
@@ -31,7 +31,7 @@ wp_enqueue_script_module( 'tovdom-islands-view' );
31
31
  </div>
32
32
  </div>
33
33
 
34
- <div data-wp-interactive='{ "namespace": "tovdom-islands" }'>
34
+ <div data-wp-interactive="tovdom-islands">
35
35
  <div data-wp-ignore>
36
36
  <div data-wp-show-mock="state.falseValue">
37
37
  <span
@@ -44,8 +44,8 @@ wp_enqueue_script_module( 'tovdom-islands-view' );
44
44
  </div>
45
45
  </div>
46
46
 
47
- <div data-wp-interactive='{ "namespace": "tovdom-islands" }'>
48
- <div data-wp-interactive='{ "namespace": "tovdom-islands" }'>
47
+ <div data-wp-interactive="tovdom-islands">
48
+ <div data-wp-interactive="tovdom-islands">
49
49
  <div
50
50
  data-wp-show-mock="state.falseValue"
51
51
  data-testid="island inside another island"
@@ -58,10 +58,10 @@ wp_enqueue_script_module( 'tovdom-islands-view' );
58
58
  </div>
59
59
  </div>
60
60
 
61
- <div data-wp-interactive='{ "namespace": "tovdom-islands" }'>
61
+ <div data-wp-interactive="tovdom-islands">
62
62
  <div>
63
63
  <div
64
- data-wp-interactive='{ "namespace": "tovdom-islands" }'
64
+ data-wp-interactive="tovdom-islands"
65
65
  data-wp-ignore
66
66
  >
67
67
  <div data-wp-show-mock="state.falseValue">
@@ -77,8 +77,8 @@ wp_enqueue_script_module( 'tovdom-islands-view' );
77
77
  </div>
78
78
  </div>
79
79
 
80
- <div data-wp-interactive='{ "namespace": "tovdom-islands" }'>
81
- <div data-wp-interactive='{ "namespace": "something-new" }'></div>
80
+ <div data-wp-interactive="tovdom-islands">
81
+ <div data-wp-interactive="something-new"></div>
82
82
  <div data-wp-show-mock="state.falseValue">
83
83
  <span data-testid="directive after different namespace">
84
84
  The directive above should keep the `tovdom-island` namespace,
@@ -8,7 +8,7 @@
8
8
  wp_enqueue_script_module( 'with-scope-view' );
9
9
  ?>
10
10
 
11
- <div data-wp-interactive='{ "namespace": "with-scope" }' data-wp-context='{"asyncCounter": 0, "syncCounter": 0}' data-wp-init--a='callbacks.asyncInit' data-wp-init--b='callbacks.syncInit'>
11
+ <div data-wp-interactive="with-scope" data-wp-context='{"asyncCounter": 0, "syncCounter": 0}' data-wp-init--a='callbacks.asyncInit' data-wp-init--b='callbacks.syncInit'>
12
12
  <p data-wp-text="context.asyncCounter" data-testid="asyncCounter">0</p>
13
13
  <p data-wp-text="context.syncCounter" data-testid="syncCounter">0</p>
14
14
  </div>
@@ -1,417 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import {
5
- clickBlockAppender,
6
- createNewPost,
7
- pressKeyWithModifier,
8
- ensureSidebarOpened,
9
- publishPost,
10
- saveDraft,
11
- openDocumentSettingsSidebar,
12
- isCurrentURL,
13
- openTypographyToolsPanelMenu,
14
- canvas,
15
- } from '@wordpress/e2e-test-utils';
16
-
17
- describe( 'Change detection', () => {
18
- let handleInterceptedRequest, hadInterceptedSave;
19
-
20
- beforeEach( async () => {
21
- hadInterceptedSave = false;
22
-
23
- await createNewPost();
24
- } );
25
-
26
- afterEach( async () => {
27
- if ( handleInterceptedRequest ) {
28
- await releaseSaveIntercept();
29
- }
30
- } );
31
-
32
- async function assertIsDirty( isDirty ) {
33
- let hadDialog = false;
34
-
35
- function handleOnDialog() {
36
- hadDialog = true;
37
- }
38
-
39
- try {
40
- page.on( 'dialog', handleOnDialog );
41
- await page.reload();
42
-
43
- // Ensure whether it was expected that dialog was encountered.
44
- expect( hadDialog ).toBe( isDirty );
45
- } catch ( error ) {
46
- throw error;
47
- } finally {
48
- page.removeListener( 'dialog', handleOnDialog );
49
- }
50
- }
51
-
52
- async function interceptSave() {
53
- await page.setRequestInterception( true );
54
-
55
- handleInterceptedRequest = ( interceptedRequest ) => {
56
- if ( interceptedRequest.url().includes( '/wp/v2/posts' ) ) {
57
- hadInterceptedSave = true;
58
- } else {
59
- interceptedRequest.continue();
60
- }
61
- };
62
- page.on( 'request', handleInterceptedRequest );
63
- }
64
-
65
- async function releaseSaveIntercept() {
66
- page.removeListener( 'request', handleInterceptedRequest );
67
- await page.setRequestInterception( false );
68
- hadInterceptedSave = false;
69
- handleInterceptedRequest = null;
70
- }
71
-
72
- it( 'Should not save on new unsaved post', async () => {
73
- await interceptSave();
74
-
75
- // Keyboard shortcut Ctrl+S save.
76
- await pressKeyWithModifier( 'primary', 'S' );
77
-
78
- expect( hadInterceptedSave ).toBe( false );
79
- } );
80
-
81
- it( 'Should autosave post', async () => {
82
- await canvas().type( '.editor-post-title__input', 'Hello World' );
83
-
84
- // Force autosave to occur immediately.
85
- await Promise.all( [
86
- page.evaluate( () =>
87
- window.wp.data.dispatch( 'core/editor' ).autosave()
88
- ),
89
- page.waitForSelector( '.editor-post-saved-state.is-autosaving' ),
90
- page.waitForSelector( '.editor-post-saved-state.is-saved' ),
91
- ] );
92
-
93
- // Autosave draft as same user should do full save, i.e. not dirty.
94
- await assertIsDirty( false );
95
- } );
96
-
97
- it( 'Should prompt to confirm unsaved changes for autosaved draft for non-content fields', async () => {
98
- await canvas().type( '.editor-post-title__input', 'Hello World' );
99
-
100
- // Toggle post as needing review (not persisted for autosave).
101
- await ensureSidebarOpened();
102
-
103
- const postPendingReviewButton = (
104
- await page.$x( "//label[contains(text(), 'Pending review')]" )
105
- )[ 0 ];
106
- await postPendingReviewButton.click( 'button' );
107
-
108
- // Force autosave to occur immediately.
109
- await Promise.all( [
110
- page.evaluate( () =>
111
- window.wp.data.dispatch( 'core/editor' ).autosave()
112
- ),
113
- page.waitForSelector( '.editor-post-saved-state.is-autosaving' ),
114
- page.waitForSelector( '.editor-post-saved-state.is-saved' ),
115
- ] );
116
-
117
- await assertIsDirty( true );
118
- } );
119
-
120
- it( 'Should prompt to confirm unsaved changes for autosaved published post', async () => {
121
- await canvas().type( '.editor-post-title__input', 'Hello World' );
122
-
123
- await publishPost();
124
-
125
- // Close publish panel.
126
- await Promise.all( [
127
- page.waitForFunction(
128
- () => ! document.querySelector( '.editor-post-publish-panel' )
129
- ),
130
- page.click( '.editor-post-publish-panel__header button' ),
131
- ] );
132
-
133
- // Should be dirty after autosave change of published post.
134
- await canvas().type( '.editor-post-title__input', '!' );
135
-
136
- await Promise.all( [
137
- page.waitForSelector(
138
- '.editor-post-publish-button[aria-disabled="true"]'
139
- ),
140
- page.waitForSelector(
141
- '.editor-post-publish-button[aria-disabled="false"]'
142
- ),
143
- page.evaluate( () =>
144
- window.wp.data.dispatch( 'core/editor' ).autosave()
145
- ),
146
- ] );
147
-
148
- await assertIsDirty( true );
149
- } );
150
-
151
- it( 'Should not prompt to confirm unsaved changes for new post', async () => {
152
- await assertIsDirty( false );
153
- } );
154
-
155
- it( 'Should prompt to confirm unsaved changes for new post with initial edits', async () => {
156
- await createNewPost( {
157
- title: 'My New Post',
158
- content: 'My content',
159
- excerpt: 'My excerpt',
160
- } );
161
-
162
- await assertIsDirty( true );
163
- } );
164
-
165
- it( 'Should prompt if property changed without save', async () => {
166
- await canvas().type( '.editor-post-title__input', 'Hello World' );
167
-
168
- await assertIsDirty( true );
169
- } );
170
-
171
- it( 'Should prompt if content added without save', async () => {
172
- await clickBlockAppender();
173
- await page.keyboard.type( 'Paragraph' );
174
-
175
- await assertIsDirty( true );
176
- } );
177
-
178
- it( 'Should not prompt if changes saved', async () => {
179
- await canvas().type( '.editor-post-title__input', 'Hello World' );
180
-
181
- await saveDraft();
182
-
183
- await assertIsDirty( false );
184
- } );
185
-
186
- it( 'Should not prompt if changes saved right after typing', async () => {
187
- await clickBlockAppender();
188
- await page.keyboard.type( 'Hello World' );
189
-
190
- await saveDraft();
191
-
192
- await assertIsDirty( false );
193
- } );
194
-
195
- it( 'Should not save if all changes saved', async () => {
196
- await canvas().type( '.editor-post-title__input', 'Hello World' );
197
-
198
- await saveDraft();
199
-
200
- await interceptSave();
201
-
202
- // Keyboard shortcut Ctrl+S save.
203
- await pressKeyWithModifier( 'primary', 'S' );
204
-
205
- expect( hadInterceptedSave ).toBe( false );
206
- } );
207
-
208
- it( 'Should prompt if save failed', async () => {
209
- await canvas().type( '.editor-post-title__input', 'Hello World' );
210
-
211
- await page.setOfflineMode( true );
212
-
213
- await Promise.all( [
214
- // Keyboard shortcut Ctrl+S save.
215
- pressKeyWithModifier( 'primary', 'S' ),
216
-
217
- // Ensure save update fails and presents button.
218
- page.waitForXPath(
219
- '//*[contains(@class, "components-notice") and contains(@class, "is-error")]/*[text()="Updating failed. You are probably offline."]'
220
- ),
221
- page.waitForSelector( '.editor-post-save-draft' ),
222
- ] );
223
-
224
- // Need to disable offline to allow reload.
225
- await page.setOfflineMode( false );
226
-
227
- await assertIsDirty( true );
228
-
229
- expect( console ).toHaveErroredWith(
230
- 'Failed to load resource: net::ERR_INTERNET_DISCONNECTED'
231
- );
232
- } );
233
-
234
- it( 'Should prompt if changes and save is in-flight', async () => {
235
- await canvas().type( '.editor-post-title__input', 'Hello World' );
236
-
237
- // Hold the posts request so we don't deal with race conditions of the
238
- // save completing early. Other requests should be allowed to continue,
239
- // for example the page reload test.
240
- await interceptSave();
241
-
242
- // Keyboard shortcut Ctrl+S save.
243
- await pressKeyWithModifier( 'primary', 'S' );
244
-
245
- await assertIsDirty( true );
246
-
247
- await releaseSaveIntercept();
248
- } );
249
-
250
- it( 'Should prompt if changes made while save is in-flight', async () => {
251
- await canvas().type( '.editor-post-title__input', 'Hello World' );
252
-
253
- // Hold the posts request so we don't deal with race conditions of the
254
- // save completing early. Other requests should be allowed to continue,
255
- // for example the page reload test.
256
- await interceptSave();
257
-
258
- // Keyboard shortcut Ctrl+S save.
259
- await pressKeyWithModifier( 'primary', 'S' );
260
-
261
- await canvas().type( '.editor-post-title__input', '!' );
262
- await page.waitForSelector( '.editor-post-save-draft' );
263
-
264
- await releaseSaveIntercept();
265
-
266
- await assertIsDirty( true );
267
- } );
268
-
269
- it( 'Should prompt if property changes made while save is in-flight, and save completes', async () => {
270
- await canvas().type( '.editor-post-title__input', 'Hello World' );
271
-
272
- // Hold the posts request so we don't deal with race conditions of the
273
- // save completing early.
274
- await interceptSave();
275
-
276
- // Keyboard shortcut Ctrl+S save.
277
- await pressKeyWithModifier( 'primary', 'S' );
278
-
279
- // Start this check immediately after save since dirtying the post will
280
- // remove the "Saved" with the Save button.
281
- const savedPromise = page.waitForSelector(
282
- '.editor-post-saved-state.is-saved'
283
- );
284
-
285
- // Dirty post while save is in-flight.
286
- await canvas().type( '.editor-post-title__input', '!' );
287
-
288
- // Allow save to complete. Disabling interception flushes pending.
289
- await Promise.all( [ savedPromise, releaseSaveIntercept() ] );
290
-
291
- await assertIsDirty( true );
292
- } );
293
-
294
- it( 'Should prompt if block revision is made while save is in-flight, and save completes', async () => {
295
- await canvas().type( '.editor-post-title__input', 'Hello World' );
296
-
297
- // Hold the posts request so we don't deal with race conditions of the
298
- // save completing early.
299
- await interceptSave();
300
-
301
- // Keyboard shortcut Ctrl+S save.
302
- await pressKeyWithModifier( 'primary', 'S' );
303
-
304
- // Start this check immediately after save since dirtying the post will
305
- // remove the "Saved" with the Save button.
306
- const savedPromise = page.waitForSelector(
307
- '.editor-post-saved-state.is-saved'
308
- );
309
-
310
- await clickBlockAppender();
311
- await page.keyboard.type( 'Paragraph' );
312
-
313
- // Allow save to complete. Disabling interception flushes pending.
314
- await Promise.all( [ savedPromise, releaseSaveIntercept() ] );
315
-
316
- await assertIsDirty( true );
317
- } );
318
-
319
- it( 'should save posts without titles and persist and overwrite the auto draft title', async () => {
320
- // Enter content.
321
- await clickBlockAppender();
322
- await page.keyboard.type( 'Paragraph' );
323
-
324
- // Save.
325
- await saveDraft();
326
-
327
- // Verify that the title is empty.
328
- const title = await canvas().$eval(
329
- '.editor-post-title__input',
330
- // Trim padding non-breaking space.
331
- ( element ) => element.textContent.trim()
332
- );
333
- expect( title ).toBe( '' );
334
-
335
- // Verify that the post is not dirty.
336
- await assertIsDirty( false );
337
- } );
338
-
339
- it( 'should not prompt to confirm unsaved changes when trashing an existing post', async () => {
340
- // Enter title.
341
- await canvas().type( '.editor-post-title__input', 'Hello World' );
342
-
343
- // Save.
344
- await saveDraft();
345
- const postId = await page.evaluate( () =>
346
- window.wp.data.select( 'core/editor' ).getCurrentPostId()
347
- );
348
-
349
- // Trash post.
350
- await openDocumentSettingsSidebar();
351
- await page.click( '.editor-post-trash.components-button' );
352
- await page.click( '.components-confirm-dialog .is-primary' );
353
-
354
- await Promise.all( [
355
- // Wait for "Saved" to confirm save complete.
356
- await page.waitForSelector( '.editor-post-saved-state.is-saved' ),
357
-
358
- // Make sure redirection happens.
359
- await page.waitForNavigation(),
360
- ] );
361
-
362
- expect(
363
- isCurrentURL(
364
- '/wp-admin/edit.php',
365
- `post_type=post&ids=${ postId }`
366
- )
367
- ).toBe( true );
368
- } );
369
-
370
- it( 'consecutive edits to the same attribute should mark the post as dirty after a save', async () => {
371
- // Open the sidebar block settings.
372
- await openDocumentSettingsSidebar();
373
-
374
- const blockInspectorTab = await page.waitForXPath(
375
- '//button[@role="tab"][contains(text(), "Block")]'
376
- );
377
- await blockInspectorTab.click();
378
-
379
- // Insert a paragraph.
380
- await clickBlockAppender();
381
- await page.keyboard.type( 'Hello, World!' );
382
-
383
- // Save and wait till the post is clean.
384
- await Promise.all( [
385
- page.waitForSelector( '.editor-post-saved-state.is-saved' ),
386
- pressKeyWithModifier( 'primary', 'S' ),
387
- ] );
388
-
389
- // Change the paragraph's `drop cap`.
390
- await canvas().click( '[data-type="core/paragraph"]' );
391
-
392
- await openTypographyToolsPanelMenu();
393
- await page.click( 'button[aria-label="Show Drop cap"]' );
394
-
395
- const [ dropCapToggle ] = await page.$x(
396
- "//label[contains(text(), 'Drop cap')]"
397
- );
398
- await dropCapToggle.click();
399
- await canvas().click( '[data-type="core/paragraph"]' );
400
-
401
- // Check that the post is dirty.
402
- await page.waitForSelector( '.editor-post-save-draft' );
403
-
404
- // Save and wait till the post is clean.
405
- await Promise.all( [
406
- page.waitForSelector( '.editor-post-saved-state.is-saved' ),
407
- pressKeyWithModifier( 'primary', 'S' ),
408
- ] );
409
-
410
- // Change the paragraph's `drop cap` again.
411
- await canvas().click( '[data-type="core/paragraph"]' );
412
- await dropCapToggle.click();
413
-
414
- // Check that the post is dirty.
415
- await page.waitForSelector( '.editor-post-save-draft' );
416
- } );
417
- } );