Skip to content

Commit 81a1b7d

Browse files
committed
Writing Flow: Add E2E test for inline boundary traversal
1 parent 48da235 commit 81a1b7d

File tree

3 files changed

+105
-4
lines changed

3 files changed

+105
-4
lines changed

test/e2e/specs/__snapshots__/writing-flow.test.js.snap

+14
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,17 @@ exports[`adding blocks Should navigate inner blocks with arrow keys 1`] = `
2121
<p>Second paragraph</p>
2222
<!-- /wp:paragraph -->"
2323
`;
24+
25+
exports[`adding blocks should navigate around inline boundaries 1`] = `
26+
"<!-- wp:paragraph -->
27+
<p>FirstAfter</p>
28+
<!-- /wp:paragraph -->
29+
30+
<!-- wp:paragraph -->
31+
<p>Before<strong>InsideSecondInside</strong>After</p>
32+
<!-- /wp:paragraph -->
33+
34+
<!-- wp:paragraph -->
35+
<p>BeforeThird</p>
36+
<!-- /wp:paragraph -->"
37+
`;

test/e2e/specs/writing-flow.test.js

+59-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import {
66
newPost,
77
newDesktopBrowserPage,
88
getHTMLFromCodeEditor,
9+
pressWithModifier,
10+
pressTimes,
911
} from '../support/utils';
1012

1113
describe( 'adding blocks', () => {
12-
beforeAll( async () => {
13-
await newDesktopBrowserPage();
14-
} );
15-
1614
beforeEach( async () => {
15+
await newDesktopBrowserPage();
1716
await newPost();
1817
} );
1918

@@ -64,4 +63,60 @@ describe( 'adding blocks', () => {
6463

6564
expect( await getHTMLFromCodeEditor() ).toMatchSnapshot();
6665
} );
66+
67+
it( 'should navigate around inline boundaries', async () => {
68+
// Add demo content
69+
await page.click( '.editor-default-block-appender__content' );
70+
await page.keyboard.type( 'First' );
71+
await page.keyboard.press( 'Enter' );
72+
await page.keyboard.type( 'Second' );
73+
await page.keyboard.press( 'Enter' );
74+
await page.keyboard.type( 'Third' );
75+
76+
// Navigate to second paragraph
77+
await pressTimes( 'ArrowLeft', 6 );
78+
79+
// Bold second paragraph text
80+
await page.keyboard.down( 'Shift' );
81+
await pressTimes( 'ArrowLeft', 6 );
82+
await page.keyboard.up( 'Shift' );
83+
await pressWithModifier( 'mod', 'b' );
84+
85+
// Arrow left from selected bold should traverse into first.
86+
await page.keyboard.press( 'ArrowLeft' );
87+
await page.keyboard.type( 'After' );
88+
89+
// Arrow right from end of first should traverse to second, *BEFORE*
90+
// the bolded text. Another press should move within inline boundary.
91+
await pressTimes( 'ArrowRight', 2 );
92+
await page.keyboard.type( 'Inside' );
93+
94+
// Arrow left from end of beginning of inline boundary should move to
95+
// the outside of the inline boundary.
96+
await pressTimes( 'ArrowLeft', 6 );
97+
await page.keyboard.press( 'ArrowLeft' ); // Separate for emphasis.
98+
await page.keyboard.type( 'Before' );
99+
100+
// Likewise, test at the end of the inline boundary for same effect.
101+
await page.keyboard.press( 'ArrowRight' ); // Move inside
102+
await pressTimes( 'ArrowRight', 12 );
103+
await page.keyboard.type( 'Inside' );
104+
await page.keyboard.press( 'ArrowRight' );
105+
106+
// Edge case: Verify that workaround to test for ZWSP at beginning of
107+
// focus node does not take effect when on the right edge of inline
108+
// boundary (thus preventing traversing to the next block by arrow).
109+
await page.keyboard.press( 'ArrowRight' );
110+
await page.keyboard.press( 'ArrowLeft' );
111+
112+
// Should be after the inline boundary again.
113+
await page.keyboard.type( 'After' );
114+
115+
// Finally, ensure that ArrowRight from end of unbolded text moves to
116+
// the last paragraph
117+
await page.keyboard.press( 'ArrowRight' );
118+
await page.keyboard.type( 'Before' );
119+
120+
expect( await getHTMLFromCodeEditor() ).toMatchSnapshot();
121+
} );
67122
} );

test/e2e/support/utils.js

+32
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import { join } from 'path';
55
import { URL } from 'url';
66

7+
/**
8+
* External dependencies
9+
*/
10+
import { times } from 'lodash';
11+
712
const {
813
WP_BASE_URL = 'http://localhost:8888',
914
WP_USERNAME = 'admin',
@@ -26,6 +31,21 @@ const MOD_KEY = process.platform === 'darwin' ? 'Meta' : 'Control';
2631
*/
2732
const REGEXP_ZWSP = /[\u200B\u200C\u200D\uFEFF]/;
2833

34+
/**
35+
* Given an array of functions, each returning a promise, performs all
36+
* promises in sequence (waterfall) order.
37+
*
38+
* @param {Function[]} sequence Array of promise creators.
39+
*
40+
* @return {Promise} Promise resolving once all in the sequence complete.
41+
*/
42+
async function promiseSequence( sequence ) {
43+
return sequence.reduce(
44+
( current, next ) => current.then( next ),
45+
Promise.resolve()
46+
);
47+
}
48+
2949
export function getUrl( WPPath, query = '' ) {
3050
const url = new URL( WP_BASE_URL );
3151

@@ -232,6 +252,18 @@ export async function openDocumentSettingsSidebar() {
232252
}
233253
}
234254

255+
/**
256+
* Presses the given keyboard key a number of times in sequence.
257+
*
258+
* @param {string} key Key to press.
259+
* @param {number} count Number of times to press.
260+
*
261+
* @return {Promise} Promise resolving when key presses complete.
262+
*/
263+
export async function pressTimes( key, count ) {
264+
return promiseSequence( times( count, () => () => page.keyboard.press( key ) ) );
265+
}
266+
235267
export async function clearLocalStorage() {
236268
await page.evaluate( () => window.localStorage.clear() );
237269
}

0 commit comments

Comments
 (0)