@wordpress/e2e-tests 7.20.0 → 7.21.1

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 (52) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/package.json +9 -8
  3. package/plugins/interactive-blocks/directive-bind/render.php +1 -1
  4. package/plugins/interactive-blocks/directive-body/render.php +1 -1
  5. package/plugins/interactive-blocks/directive-class/render.php +1 -1
  6. package/plugins/interactive-blocks/directive-context/render.php +2 -2
  7. package/plugins/interactive-blocks/directive-context/view.js +10 -6
  8. package/plugins/interactive-blocks/{directive-slots → directive-each}/block.json +3 -3
  9. package/plugins/interactive-blocks/directive-each/render.php +226 -0
  10. package/plugins/interactive-blocks/directive-each/view.js +192 -0
  11. package/plugins/interactive-blocks/directive-init/render.php +1 -1
  12. package/plugins/interactive-blocks/directive-key/render.php +2 -2
  13. package/plugins/interactive-blocks/directive-key/view.js +7 -4
  14. package/plugins/interactive-blocks/directive-on/render.php +1 -1
  15. package/plugins/interactive-blocks/directive-on-document/block.json +15 -0
  16. package/plugins/interactive-blocks/directive-on-document/render.php +29 -0
  17. package/plugins/interactive-blocks/directive-on-document/view.js +39 -0
  18. package/plugins/interactive-blocks/directive-on-window/block.json +15 -0
  19. package/plugins/interactive-blocks/directive-on-window/render.php +26 -0
  20. package/plugins/interactive-blocks/directive-on-window/view.js +39 -0
  21. package/plugins/interactive-blocks/directive-priorities/render.php +1 -1
  22. package/plugins/interactive-blocks/directive-run/block.json +15 -0
  23. package/plugins/interactive-blocks/directive-run/render.php +54 -0
  24. package/plugins/interactive-blocks/directive-run/view.js +110 -0
  25. package/plugins/interactive-blocks/directive-style/render.php +1 -1
  26. package/plugins/interactive-blocks/directive-text/render.php +15 -1
  27. package/plugins/interactive-blocks/directive-text/view.js +4 -1
  28. package/plugins/interactive-blocks/directive-watch/render.php +1 -1
  29. package/plugins/interactive-blocks/negation-operator/render.php +1 -1
  30. package/plugins/interactive-blocks/router-navigate/render.php +2 -2
  31. package/plugins/interactive-blocks/router-navigate/view.js +5 -2
  32. package/plugins/interactive-blocks/router-regions/render.php +4 -4
  33. package/plugins/interactive-blocks/router-regions/view.js +5 -2
  34. package/plugins/interactive-blocks/store-tag/render.php +3 -3
  35. package/plugins/interactive-blocks/tovdom/render.php +1 -1
  36. package/plugins/interactive-blocks/tovdom-islands/render.php +1 -1
  37. package/plugins/interactive-blocks/with-scope/block.json +15 -0
  38. package/plugins/interactive-blocks/with-scope/render.php +14 -0
  39. package/plugins/interactive-blocks/with-scope/view.js +20 -0
  40. package/plugins/interactive-blocks.php +19 -10
  41. package/specs/editor/various/__snapshots__/pattern-blocks.test.js.snap +0 -6
  42. package/specs/editor/various/pattern-blocks.test.js +8 -117
  43. package/plugins/dataviews.php +0 -25
  44. package/plugins/interactive-blocks/directive-slots/render.php +0 -69
  45. package/plugins/interactive-blocks/directive-slots/view.js +0 -20
  46. package/specs/editor/fixtures/menu-items-request-fixture.json +0 -84
  47. package/specs/editor/fixtures/menu-items-response-fixture.json +0 -1261
  48. package/specs/editor/various/__snapshots__/block-grouping.test.js.snap +0 -115
  49. package/specs/editor/various/__snapshots__/embedding.test.js.snap +0 -67
  50. package/specs/editor/various/block-grouping.test.js +0 -283
  51. package/specs/editor/various/embedding.test.js +0 -303
  52. package/specs/editor/various/typewriter.test.js +0 -260
@@ -1,303 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import {
5
- clickBlockAppender,
6
- createEmbeddingMatcher,
7
- createJSONResponse,
8
- createNewPost,
9
- createURLMatcher,
10
- getEditedPostContent,
11
- insertBlock,
12
- publishPost,
13
- setUpResponseMocking,
14
- canvas,
15
- } from '@wordpress/e2e-test-utils';
16
-
17
- const MOCK_EMBED_WORDPRESS_SUCCESS_RESPONSE = {
18
- url: 'https://wordpress.org/gutenberg/handbook/block-api/attributes/',
19
- html: '<div class="wp-embedded-content" data-secret="shhhh it is a secret"></div>',
20
- type: 'rich',
21
- provider_name: 'WordPress',
22
- provider_url: 'https://wordpress.org',
23
- version: '1.0',
24
- };
25
-
26
- const MOCK_EMBED_RICH_SUCCESS_RESPONSE = {
27
- url: 'https://twitter.com/notnownikki',
28
- html: '<p>Mock success response.</p>',
29
- type: 'rich',
30
- provider_name: 'Twitter',
31
- provider_url: 'https://twitter.com',
32
- version: '1.0',
33
- };
34
-
35
- const MOCK_EMBED_PHOTO_SUCCESS_RESPONSE = {
36
- url: 'https://cloudup.com/cQFlxqtY4ob',
37
- html: '<p>Mock success response.</p>',
38
- type: 'photo',
39
- provider_name: 'Cloudup',
40
- provider_url: 'https://cloudup.com',
41
- version: '1.0',
42
- };
43
-
44
- const MOCK_EMBED_VIDEO_SUCCESS_RESPONSE = {
45
- url: 'https://www.youtube.com/watch?v=lXMskKTw3Bc',
46
- html: '<iframe width="16" height="9"></iframe>',
47
- type: 'video',
48
- provider_name: 'YouTube',
49
- provider_url: 'https://youtube.com',
50
- version: '1.0',
51
- };
52
-
53
- const MOCK_EMBED_AUDIO_SUCCESS_RESPONSE = {
54
- url: 'https://soundcloud.com/a-boogie-wit-da-hoodie/swervin',
55
- html: '<iframe width="16" height="9"></iframe>',
56
- type: 'audio',
57
- provider_name: 'SoundCloud',
58
- provider_url: 'https://soundcloud.com',
59
- version: '1.0',
60
- };
61
-
62
- const MOCK_EMBED_IMAGE_SUCCESS_RESPONSE = {
63
- url: 'https://www.instagram.com/p/Bvl97o2AK6x/',
64
- html: '<iframe width="16" height="9"></iframe>',
65
- type: 'video',
66
- provider_name: 'Instagram',
67
- provider_url: 'https://www.instagram.com',
68
- version: '1.0',
69
- };
70
-
71
- const MOCK_BAD_EMBED_PROVIDER_RESPONSE = {
72
- url: 'https://twitter.com/thatbunty',
73
- html: false,
74
- provider_name: 'Embed Provider',
75
- version: '1.0',
76
- };
77
-
78
- const MOCK_CANT_EMBED_RESPONSE = {
79
- provider_name: 'Embed Handler',
80
- html: '<a href="https://twitter.com/wooyaygutenberg123454312">https://twitter.com/wooyaygutenberg123454312</a>',
81
- };
82
-
83
- const MOCK_BAD_WORDPRESS_RESPONSE = {
84
- code: 'oembed_invalid_url',
85
- message: 'Not Found',
86
- data: {
87
- status: 404,
88
- },
89
- html: false,
90
- };
91
-
92
- const MOCK_RESPONSES = [
93
- {
94
- match: createEmbeddingMatcher(
95
- 'https://wordpress.org/gutenberg/handbook'
96
- ),
97
- onRequestMatch: createJSONResponse( MOCK_BAD_WORDPRESS_RESPONSE ),
98
- },
99
- {
100
- match: createEmbeddingMatcher(
101
- 'https://wordpress.org/gutenberg/handbook/'
102
- ),
103
- onRequestMatch: createJSONResponse( MOCK_BAD_WORDPRESS_RESPONSE ),
104
- },
105
- {
106
- match: createEmbeddingMatcher(
107
- 'https://wordpress.org/gutenberg/handbook/block-api/attributes/'
108
- ),
109
- onRequestMatch: createJSONResponse(
110
- MOCK_EMBED_WORDPRESS_SUCCESS_RESPONSE
111
- ),
112
- },
113
- {
114
- match: createEmbeddingMatcher(
115
- 'https://www.youtube.com/watch?v=lXMskKTw3Bc'
116
- ),
117
- onRequestMatch: createJSONResponse( MOCK_EMBED_VIDEO_SUCCESS_RESPONSE ),
118
- },
119
- {
120
- match: createEmbeddingMatcher(
121
- 'https://soundcloud.com/a-boogie-wit-da-hoodie/swervin'
122
- ),
123
- onRequestMatch: createJSONResponse( MOCK_EMBED_AUDIO_SUCCESS_RESPONSE ),
124
- },
125
- {
126
- match: createEmbeddingMatcher(
127
- 'https://www.instagram.com/p/Bvl97o2AK6x/'
128
- ),
129
- onRequestMatch: createJSONResponse( MOCK_EMBED_IMAGE_SUCCESS_RESPONSE ),
130
- },
131
- {
132
- match: createEmbeddingMatcher( 'https://cloudup.com/cQFlxqtY4ob' ),
133
- onRequestMatch: createJSONResponse( MOCK_EMBED_PHOTO_SUCCESS_RESPONSE ),
134
- },
135
- {
136
- match: createEmbeddingMatcher( 'https://twitter.com/notnownikki' ),
137
- onRequestMatch: createJSONResponse( MOCK_EMBED_RICH_SUCCESS_RESPONSE ),
138
- },
139
- {
140
- match: createEmbeddingMatcher( 'https://twitter.com/notnownikki/' ),
141
- onRequestMatch: createJSONResponse( MOCK_CANT_EMBED_RESPONSE ),
142
- },
143
- {
144
- match: createEmbeddingMatcher( 'https://twitter.com/thatbunty' ),
145
- onRequestMatch: createJSONResponse( MOCK_BAD_EMBED_PROVIDER_RESPONSE ),
146
- },
147
- {
148
- match: createEmbeddingMatcher(
149
- 'https://twitter.com/wooyaygutenberg123454312'
150
- ),
151
- onRequestMatch: createJSONResponse( MOCK_CANT_EMBED_RESPONSE ),
152
- },
153
- // Respond to the instagram URL with a non-image response, doesn't matter what it is,
154
- // just make sure the image errors.
155
- {
156
- match: createURLMatcher( 'https://www.instagram.com/p/Bvl97o2AK6x/' ),
157
- onRequestMatch: createJSONResponse( MOCK_CANT_EMBED_RESPONSE ),
158
- },
159
- ];
160
-
161
- async function insertEmbed( URL ) {
162
- await clickBlockAppender();
163
- await page.keyboard.type( '/embed' );
164
- await page.waitForXPath(
165
- `//*[contains(@class, "components-autocomplete__result") and contains(@class, "is-selected") and contains(text(), 'Embed')]`
166
- );
167
- await page.keyboard.press( 'Enter' );
168
- await page.keyboard.type( URL );
169
- await page.keyboard.press( 'Enter' );
170
- }
171
-
172
- describe( 'Embedding content', () => {
173
- beforeEach( async () => {
174
- await setUpResponseMocking( MOCK_RESPONSES );
175
- await createNewPost();
176
- } );
177
-
178
- it( 'should render embeds in the correct state', async () => {
179
- // Valid embed. Should render valid figure element.
180
- await insertEmbed( 'https://twitter.com/notnownikki' );
181
- await canvas().waitForSelector( 'figure.wp-block-embed' );
182
-
183
- // Valid provider; invalid content. Should render failed, edit state.
184
- await insertEmbed( 'https://twitter.com/wooyaygutenberg123454312' );
185
- await canvas().waitForSelector(
186
- 'input[value="https://twitter.com/wooyaygutenberg123454312"]'
187
- );
188
-
189
- // WordPress invalid content. Should render failed, edit state.
190
- await insertEmbed( 'https://wordpress.org/gutenberg/handbook/' );
191
- await canvas().waitForSelector(
192
- 'input[value="https://wordpress.org/gutenberg/handbook/"]'
193
- );
194
-
195
- // Provider whose oembed API has gone wrong. Should render failed, edit
196
- // state.
197
- await insertEmbed( 'https://twitter.com/thatbunty' );
198
- await canvas().waitForSelector(
199
- 'input[value="https://twitter.com/thatbunty"]'
200
- );
201
-
202
- // WordPress content that can be embedded. Should render valid figure
203
- // element.
204
- await insertEmbed(
205
- 'https://wordpress.org/gutenberg/handbook/block-api/attributes/'
206
- );
207
- await canvas().waitForSelector( 'figure.wp-block-embed' );
208
-
209
- // Video content. Should render valid figure element, and include the
210
- // aspect ratio class.
211
- await insertEmbed( 'https://www.youtube.com/watch?v=lXMskKTw3Bc' );
212
- await canvas().waitForSelector(
213
- 'figure.wp-block-embed.is-type-video.wp-embed-aspect-16-9'
214
- );
215
-
216
- // Photo content. Should render valid figure element.
217
- await insertEmbed( 'https://cloudup.com/cQFlxqtY4ob' );
218
- await canvas().waitForSelector(
219
- 'iframe[title="Embedded content from cloudup"'
220
- );
221
-
222
- expect( await getEditedPostContent() ).toMatchSnapshot();
223
- } );
224
-
225
- it( 'should allow the user to convert unembeddable URLs to a paragraph with a link in it', async () => {
226
- // URL that can't be embedded.
227
- await insertEmbed( 'https://twitter.com/wooyaygutenberg123454312' );
228
-
229
- // Wait for the request to fail and present an error. Since placeholder
230
- // has styles applied which depend on resize observer, wait for the
231
- // expected size class to settle before clicking, since otherwise a race
232
- // condition could occur on the placeholder layout vs. click intent.
233
- await canvas().waitForSelector(
234
- '.components-placeholder.is-large .components-placeholder__error'
235
- );
236
-
237
- const button = await canvas().waitForXPath(
238
- `//button[contains(text(), 'Convert to link')]`
239
- );
240
- await button.click();
241
- expect( await getEditedPostContent() ).toMatchSnapshot();
242
- } );
243
-
244
- it( 'should retry embeds that could not be embedded with trailing slashes, without the trailing slashes', async () => {
245
- await insertEmbed( 'https://twitter.com/notnownikki/' );
246
- // The twitter block should appear correctly.
247
- await canvas().waitForSelector( 'figure.wp-block-embed' );
248
- expect( await getEditedPostContent() ).toMatchSnapshot();
249
- } );
250
-
251
- it( 'should allow the user to try embedding a failed URL again', async () => {
252
- // URL that can't be embedded.
253
- await insertEmbed( 'https://twitter.com/wooyaygutenberg123454312' );
254
-
255
- // Wait for the request to fail and present an error. Since placeholder
256
- // has styles applied which depend on resize observer, wait for the
257
- // expected size class to settle before clicking, since otherwise a race
258
- // condition could occur on the placeholder layout vs. click intent.
259
- await canvas().waitForSelector(
260
- '.components-placeholder.is-large .components-placeholder__error'
261
- );
262
-
263
- // Set up a different mock to make sure that try again actually does make the request again.
264
- await setUpResponseMocking( [
265
- {
266
- match: createEmbeddingMatcher(
267
- 'https://twitter.com/wooyaygutenberg123454312'
268
- ),
269
- onRequestMatch: createJSONResponse(
270
- MOCK_EMBED_RICH_SUCCESS_RESPONSE
271
- ),
272
- },
273
- ] );
274
- const button = await canvas().waitForXPath(
275
- `//button[contains(text(), 'Try again')]`
276
- );
277
- await button.click();
278
- await canvas().waitForSelector( 'figure.wp-block-embed' );
279
- expect( await getEditedPostContent() ).toMatchSnapshot();
280
- } );
281
-
282
- it( 'should switch to the WordPress block correctly', async () => {
283
- // This test is to make sure that WordPress embeds are detected correctly,
284
- // because the HTML can vary, and the block is detected by looking for
285
- // classes in the HTML, so we need to flag up if the HTML changes.
286
-
287
- // Publish a post to embed.
288
- await insertBlock( 'Paragraph' );
289
- await page.keyboard.type( 'Hello there!' );
290
- await publishPost();
291
- const postUrl = await page.$eval(
292
- '.editor-post-publish-panel [id^=inspector-text-control-]',
293
- ( el ) => el.value
294
- );
295
-
296
- // Start a new post, embed the previous post.
297
- await createNewPost();
298
- await insertEmbed( postUrl );
299
-
300
- // Check the block has become a WordPress block.
301
- await canvas().waitForSelector( 'figure.wp-block-embed' );
302
- } );
303
- } );
@@ -1,260 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { createNewPost } from '@wordpress/e2e-test-utils';
5
-
6
- describe( 'TypeWriter', () => {
7
- beforeEach( async () => {
8
- await createNewPost();
9
- } );
10
-
11
- const getCaretPosition = async () =>
12
- await page.evaluate(
13
- () =>
14
- wp.dom.computeCaretRect(
15
- document.activeElement?.contentWindow ?? window
16
- ).y
17
- );
18
-
19
- // Allow the scroll position to be 1px off.
20
- const BUFFER = 1;
21
-
22
- const getDiff = async ( caretPosition ) =>
23
- Math.abs( ( await getCaretPosition() ) - caretPosition );
24
-
25
- it( 'should maintain caret position', async () => {
26
- // Create first block.
27
- await page.keyboard.press( 'Enter' );
28
-
29
- // Create second block.
30
- await page.keyboard.press( 'Enter' );
31
-
32
- const initialPosition = await getCaretPosition();
33
-
34
- // The page shouldn't be scrolled when it's being filled.
35
- await page.keyboard.press( 'Enter' );
36
-
37
- expect( await getCaretPosition() ).toBeGreaterThan( initialPosition );
38
-
39
- // Create blocks until the typewriter effect kicks in.
40
- while (
41
- await page.evaluate( () => {
42
- const { activeElement } =
43
- document.activeElement?.contentDocument ?? document;
44
- return (
45
- wp.dom.getScrollContainer( activeElement ).scrollTop === 0
46
- );
47
- } )
48
- ) {
49
- await page.keyboard.press( 'Enter' );
50
- }
51
-
52
- const newPosition = await getCaretPosition();
53
-
54
- // Now the scroll position should be maintained.
55
- await page.keyboard.press( 'Enter' );
56
-
57
- expect( await getDiff( newPosition ) ).toBeLessThanOrEqual( BUFFER );
58
-
59
- // Type until the text wraps.
60
- while (
61
- await page.evaluate( () => {
62
- const { activeElement } =
63
- document.activeElement?.contentDocument ?? document;
64
- return (
65
- activeElement.clientHeight <=
66
- parseInt( getComputedStyle( activeElement ).lineHeight, 10 )
67
- );
68
- } )
69
- ) {
70
- await page.keyboard.type( 'a' );
71
- }
72
-
73
- expect( await getDiff( newPosition ) ).toBeLessThanOrEqual( BUFFER );
74
-
75
- // Pressing backspace will reposition the caret to the previous line.
76
- // Scroll position should be adjusted again.
77
- await page.keyboard.press( 'Backspace' );
78
-
79
- expect( await getDiff( newPosition ) ).toBeLessThanOrEqual( BUFFER );
80
-
81
- // Should reset scroll position to maintain.
82
- await page.keyboard.press( 'ArrowUp' );
83
-
84
- const positionAfterArrowUp = await getCaretPosition();
85
-
86
- expect( positionAfterArrowUp ).toBeLessThanOrEqual( newPosition );
87
-
88
- // Should be scrolled to new position.
89
- await page.keyboard.press( 'Enter' );
90
-
91
- expect( await getDiff( positionAfterArrowUp ) ).toBeLessThanOrEqual(
92
- BUFFER
93
- );
94
- } );
95
-
96
- it( 'should maintain caret position after scroll', async () => {
97
- // Create first block.
98
- await page.keyboard.press( 'Enter' );
99
-
100
- // Create zero or more blocks until there is a scrollable container.
101
- // No blocks should be created if there's already a scrollbar.
102
- while (
103
- await page.evaluate( () => {
104
- const { activeElement } =
105
- document.activeElement?.contentDocument ?? document;
106
- const scrollContainer =
107
- wp.dom.getScrollContainer( activeElement );
108
- return (
109
- scrollContainer.scrollHeight ===
110
- scrollContainer.clientHeight
111
- );
112
- } )
113
- ) {
114
- await page.keyboard.press( 'Enter' );
115
- }
116
-
117
- const scrollPosition = await page.evaluate( () => {
118
- const { activeElement } =
119
- document.activeElement?.contentDocument ?? document;
120
- return wp.dom.getScrollContainer( activeElement ).scrollTop;
121
- } );
122
- // Expect scrollbar to be at the top.
123
- expect( scrollPosition ).toBe( 0 );
124
-
125
- // Move the mouse to the scroll container, and scroll down
126
- // a small amount to trigger the typewriter mode.
127
- await page.evaluate( () => {
128
- const { activeElement } =
129
- document.activeElement?.contentDocument ?? document;
130
- wp.dom.getScrollContainer( activeElement ).scrollTop += 2;
131
- } );
132
- // Wait for the caret rectangle to be recalculated.
133
- await page.evaluate(
134
- () => new Promise( window.requestAnimationFrame )
135
- );
136
-
137
- // After hitting Enter to create a new block, the caret screen
138
- // coordinates should be the same.
139
- const initialPosition = await getCaretPosition();
140
- await page.keyboard.press( 'Enter' );
141
- await page.waitForFunction( () => {
142
- const { activeElement } =
143
- document.activeElement?.contentDocument ?? document;
144
- // Wait for the Typewriter to scroll down past the initial position.
145
- return wp.dom.getScrollContainer( activeElement ).scrollTop > 2;
146
- } );
147
- expect( await getDiff( initialPosition ) ).toBe( 0 );
148
- } );
149
-
150
- it( 'should maintain caret position after leaving last editable', async () => {
151
- // Create first block.
152
- await page.keyboard.press( 'Enter' );
153
- // Create second block.
154
- await page.keyboard.press( 'Enter' );
155
- // Create third block.
156
- await page.keyboard.press( 'Enter' );
157
- // Move to first block.
158
- await page.keyboard.press( 'ArrowUp' );
159
- await page.keyboard.press( 'ArrowUp' );
160
-
161
- const initialPosition = await getCaretPosition();
162
-
163
- // Should maintain scroll position.
164
- await page.keyboard.press( 'Enter' );
165
-
166
- expect( await getDiff( initialPosition ) ).toBeLessThanOrEqual(
167
- BUFFER
168
- );
169
- } );
170
-
171
- it( 'should scroll caret into view from the top', async () => {
172
- // Create first block.
173
- await page.keyboard.press( 'Enter' );
174
-
175
- // Create blocks until there is a scrollable container.
176
- while (
177
- await page.evaluate( () => {
178
- const { activeElement } =
179
- document.activeElement?.contentDocument ?? document;
180
- return ! wp.dom.getScrollContainer( activeElement );
181
- } )
182
- ) {
183
- await page.keyboard.press( 'Enter' );
184
- }
185
-
186
- let count = 0;
187
-
188
- // Create blocks until the typewriter effect kicks in, create at
189
- // least 10 blocks to properly test the .
190
- while (
191
- ( await page.evaluate( () => {
192
- const { activeElement } =
193
- document.activeElement?.contentDocument ?? document;
194
- return (
195
- wp.dom.getScrollContainer( activeElement ).scrollTop === 0
196
- );
197
- } ) ) ||
198
- count < 10
199
- ) {
200
- await page.keyboard.press( 'Enter' );
201
- count++;
202
- }
203
-
204
- // Scroll the active element to the very bottom of the scroll container,
205
- // then scroll up, so the caret is partially hidden.
206
- await page.evaluate( () => {
207
- const { activeElement } =
208
- document.activeElement?.contentDocument ?? document;
209
- activeElement.scrollIntoView( false );
210
- wp.dom.getScrollContainer( activeElement ).scrollTop -=
211
- activeElement.offsetHeight + 10;
212
- } );
213
-
214
- const bottomPostition = await getCaretPosition();
215
-
216
- // Should scroll the caret back into view (preserve browser behaviour).
217
- await page.keyboard.type( 'a' );
218
-
219
- const newBottomPosition = await getCaretPosition();
220
-
221
- expect( newBottomPosition ).toBeLessThanOrEqual( bottomPostition );
222
-
223
- // Should maintain new caret position.
224
- await page.keyboard.press( 'Enter' );
225
-
226
- expect( await getDiff( newBottomPosition ) ).toBeLessThanOrEqual(
227
- BUFFER
228
- );
229
-
230
- await page.keyboard.press( 'Backspace' );
231
-
232
- while ( count-- ) {
233
- await page.keyboard.press( 'ArrowUp' );
234
- }
235
-
236
- // Scroll the active element to the very top of the scroll container,
237
- // then scroll down, so the caret is partially hidden.
238
- await page.evaluate( () => {
239
- const { activeElement } =
240
- document.activeElement?.contentDocument ?? document;
241
- activeElement.scrollIntoView();
242
- wp.dom.getScrollContainer( activeElement ).scrollTop +=
243
- activeElement.offsetHeight + 10;
244
- } );
245
-
246
- const topPostition = await getCaretPosition();
247
-
248
- // Should scroll the caret back into view (preserve browser behaviour).
249
- await page.keyboard.type( 'a' );
250
-
251
- const newTopPosition = await getCaretPosition();
252
-
253
- expect( newTopPosition ).toBeGreaterThan( topPostition );
254
-
255
- // Should maintain new caret position.
256
- await page.keyboard.press( 'Enter' );
257
-
258
- expect( await getDiff( newTopPosition ) ).toBeLessThanOrEqual( BUFFER );
259
- } );
260
- } );