-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathrtl.test.js
123 lines (98 loc) · 3.79 KB
/
rtl.test.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
/**
* WordPress dependencies
*/
import {
createNewPost,
getEditedPostContent,
pressKeyWithModifier,
} from '@wordpress/e2e-test-utils';
// Avoid using three, as it looks too much like two with some fonts.
const ARABIC_ZERO = '٠';
const ARABIC_ONE = '١';
const ARABIC_TWO = '٢';
describe( 'RTL', () => {
beforeEach( async () => {
await createNewPost();
await page.evaluate( () => {
document.querySelector( '.is-root-container' ).dir = 'rtl';
wp.i18n.isRTL = () => true;
} );
} );
it( 'should arrow navigate', async () => {
await page.keyboard.press( 'Enter' );
// We need at least three characters as arrow navigation *from* the
// edges might be handled differently.
await page.keyboard.type( ARABIC_ONE );
await page.keyboard.type( ARABIC_TWO );
await page.keyboard.press( 'ArrowRight' );
// This is the important key press: arrow nav *from* the middle.
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( ARABIC_ZERO );
// Expect: ARABIC_ZERO + ARABIC_ONE + ARABIC_TWO (<p>٠١٢</p>).
// N.b.: HTML is LTR, so direction will be reversed!
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should split', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( ARABIC_ZERO );
await page.keyboard.type( ARABIC_ONE );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.press( 'Enter' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should merge backward', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( ARABIC_ZERO );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( ARABIC_ONE );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.press( 'Backspace' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should merge forward', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( ARABIC_ZERO );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( ARABIC_ONE );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.press( 'Delete' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should arrow navigate between blocks', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( ARABIC_ZERO );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( ARABIC_ONE );
await pressKeyWithModifier( 'shift', 'Enter' );
await page.keyboard.type( ARABIC_TWO );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.press( 'ArrowRight' );
// Move to the previous block with two lines in the current block.
await page.keyboard.press( 'ArrowRight' );
await pressKeyWithModifier( 'shift', 'Enter' );
await page.keyboard.type( ARABIC_ONE );
// Move to the next block with two lines in the current block.
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.type( ARABIC_ZERO );
await pressKeyWithModifier( 'shift', 'Enter' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should navigate inline boundaries', async () => {
await page.keyboard.press( 'Enter' );
// Wait for rich text editor to load.
await page.waitForSelector( '.block-editor-rich-text__editable' );
await pressKeyWithModifier( 'primary', 'b' );
await page.keyboard.type( ARABIC_ONE );
await pressKeyWithModifier( 'primary', 'b' );
await page.keyboard.type( ARABIC_TWO );
// Insert a character at each boundary position.
for ( let i = 4; i > 0; i-- ) {
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( ARABIC_ZERO );
expect( await getEditedPostContent() ).toMatchSnapshot();
await page.keyboard.press( 'Backspace' );
}
} );
} );