-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
quote.test.js
197 lines (161 loc) · 6.01 KB
/
quote.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/**
* WordPress dependencies
*/
import {
clickBlockAppender,
getEditedPostContent,
createNewPost,
pressKeyTimes,
transformBlockTo,
insertBlock,
} from '@wordpress/e2e-test-utils';
describe( 'Quote', () => {
beforeEach( async () => {
await createNewPost();
} );
it( 'can be created by using > at the start of a paragraph block', async () => {
// Create a block with some text that will trigger a list creation.
await clickBlockAppender();
await page.keyboard.type( '> A quote' );
// Create a second list item.
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Another paragraph' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'can be created by typing > in front of text of a paragraph block', async () => {
// Create a list with the slash block shortcut.
await clickBlockAppender();
await page.keyboard.type( 'test' );
await pressKeyTimes( 'ArrowLeft', 4 );
await page.keyboard.type( '> ' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'can be created by typing "/quote"', async () => {
// Create a list with the slash block shortcut.
await clickBlockAppender();
await page.keyboard.type( '/quote' );
await page.waitForXPath(
`//*[contains(@class, "components-autocomplete__result") and contains(@class, "is-selected") and contains(text(), 'Quote')]`
);
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'I’m a quote' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'can be created by converting a paragraph', async () => {
await clickBlockAppender();
await page.keyboard.type( 'test' );
await transformBlockTo( 'Quote' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'can be created by converting multiple paragraphs', async () => {
await clickBlockAppender();
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'two' );
await page.keyboard.down( 'Shift' );
await page.click( '[data-type="core/paragraph"]' );
await page.keyboard.up( 'Shift' );
await transformBlockTo( 'Quote' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
describe( 'can be converted to paragraphs', () => {
it( 'and renders one paragraph block per <p> within quote', async () => {
await insertBlock( 'Quote' );
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'two' );
// Navigate to the citation to select the block.
await page.keyboard.press( 'ArrowRight' );
await transformBlockTo( 'Unwrap' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'and renders a paragraph for the cite, if it exists', async () => {
await insertBlock( 'Quote' );
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'two' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( 'cite' );
await transformBlockTo( 'Unwrap' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'and renders only one paragraph for the cite, if the quote is void', async () => {
await insertBlock( 'Quote' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( 'cite' );
await transformBlockTo( 'Unwrap' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'and renders a void paragraph if both the cite and quote are void', async () => {
await insertBlock( 'Quote' );
await page.keyboard.press( 'ArrowRight' ); // Select the quote
await transformBlockTo( 'Unwrap' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );
it( 'can be created by converting a heading', async () => {
await insertBlock( 'Heading' );
await page.keyboard.type( 'test' );
await transformBlockTo( 'Quote' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'can be converted to a pullquote', async () => {
await insertBlock( 'Quote' );
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'two' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( 'cite' );
await transformBlockTo( 'Pullquote' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'can be split at the end', async () => {
await insertBlock( 'Quote' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'Enter' );
// Expect empty paragraph outside quote block.
expect( await getEditedPostContent() ).toMatchSnapshot();
await page.keyboard.press( 'Backspace' );
await page.keyboard.type( '2' );
// Expect the paragraph to be merged into the quote block.
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'can be unwrapped on Backspace', async () => {
await insertBlock( 'Quote' );
expect( await getEditedPostContent() ).toMatchInlineSnapshot( `
"<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->"
` );
await page.keyboard.press( 'Backspace' );
expect( await getEditedPostContent() ).toMatchInlineSnapshot( `""` );
} );
it( 'can be unwrapped with content on Backspace', async () => {
await insertBlock( 'Quote' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( '2' );
expect( await getEditedPostContent() ).toMatchInlineSnapshot( `
"<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><!-- wp:paragraph -->
<p>1</p>
<!-- /wp:paragraph --><cite>2</cite></blockquote>
<!-- /wp:quote -->"
` );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'ArrowUp' );
await page.keyboard.press( 'ArrowUp' );
await page.keyboard.press( 'Backspace' );
expect( await getEditedPostContent() ).toMatchInlineSnapshot( `
"<!-- wp:paragraph -->
<p>1</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>2</p>
<!-- /wp:paragraph -->"
` );
} );
} );