-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
block-deletion.test.js
133 lines (106 loc) · 5.18 KB
/
block-deletion.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
/**
* WordPress dependencies
*/
import {
clickBlockAppender,
getEditedPostContent,
createNewPost,
isInDefaultBlock,
pressKeyWithModifier,
} from '@wordpress/e2e-test-utils';
const addThreeParagraphsToNewPost = async () => {
await createNewPost();
// Add demo content
await clickBlockAppender();
await page.keyboard.type( 'First paragraph' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Second paragraph' );
await page.keyboard.press( 'Enter' );
};
const clickOnBlockSettingsMenuItem = async ( buttonLabel ) => {
await expect( page ).toClick( '.block-editor-block-settings-menu__toggle' );
const itemButton = ( await page.$x( `//*[contains(@class, "block-editor-block-settings-menu__popover")]//button[contains(text(), '${ buttonLabel }')]` ) )[ 0 ];
await itemButton.click();
};
describe( 'block deletion -', () => {
beforeEach( addThreeParagraphsToNewPost );
describe( 'deleting the third block using the Remove Block menu item', () => {
it( 'results in two remaining blocks and positions the caret at the end of the second block', async () => {
// The blocks can't be empty to trigger the toolbar
await page.keyboard.type( 'Paragraph to remove' );
// Move the mouse to show the block toolbar
await page.mouse.move( 200, 300, { steps: 10 } );
await clickOnBlockSettingsMenuItem( 'Remove Block' );
expect( await getEditedPostContent() ).toMatchSnapshot();
// Type additional text and assert that caret position is correct by comparing to snapshot.
await page.keyboard.type( ' - caret was here' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );
describe( 'deleting the third block using the Remove Block shortcut', () => {
it( 'results in two remaining blocks and positions the caret at the end of the second block', async () => {
// Type some text to assert that the shortcut also deletes block content.
await page.keyboard.type( 'this is block 2' );
await pressKeyWithModifier( 'access', 'z' );
expect( await getEditedPostContent() ).toMatchSnapshot();
// Type additional text and assert that caret position is correct by comparing to snapshot.
await page.keyboard.type( ' - caret was here' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );
describe( 'deleting the third block using backspace in an empty block', () => {
it( 'results in two remaining blocks and positions the caret at the end of the second block', async () => {
await page.keyboard.press( 'Backspace' );
expect( await getEditedPostContent() ).toMatchSnapshot();
// Type additional text and assert that caret position is correct by comparing to snapshot.
await page.keyboard.type( ' - caret was here' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );
describe( 'deleting the third block using backspace with block wrapper selection', () => {
it( 'results in three remaining blocks and positions the caret at the end of the third block', async () => {
// Add an image block since it's easier to click the wrapper on non-textual blocks.
await page.keyboard.type( '/image' );
await page.keyboard.press( 'Enter' );
// Click on something that's not a block.
await page.click( '.editor-post-title' );
// Click on the third (image) block so that its wrapper is selected and backspace to delete it.
await page.click( '.block-editor-block-list__block:nth-child(3) .components-placeholder__label' );
await page.keyboard.press( 'Backspace' );
expect( await getEditedPostContent() ).toMatchSnapshot();
// Type additional text and assert that caret position is correct by comparing to snapshot.
await page.keyboard.type( ' - caret was here' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );
describe( 'deleting the third and fourth blocks using backspace with multi-block selection', () => {
it( 'results in two remaining blocks and positions the caret at the end of the second block', async () => {
// Add a third paragraph for this test.
await page.keyboard.type( 'Third paragraph' );
await page.keyboard.press( 'Enter' );
// Press the up arrow once to select the third and fourth blocks.
await pressKeyWithModifier( 'shift', 'ArrowUp' );
// Now that the block wrapper is selected, press backspace to delete it.
await page.keyboard.press( 'Backspace' );
expect( await getEditedPostContent() ).toMatchSnapshot();
// Type additional text and assert that caret position is correct by comparing to snapshot.
await page.keyboard.type( ' - caret was here' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );
} );
describe( 'deleting all blocks', () => {
it( 'results in the default block getting selected', async () => {
await createNewPost();
await clickBlockAppender();
await page.keyboard.type( 'Paragraph' );
await page.keyboard.press( 'Escape' );
await clickOnBlockSettingsMenuItem( 'Remove Block' );
// There is a default block:
expect( await page.$$( '.block-editor-block-list__block' ) ).toHaveLength( 1 );
// But the effective saved content is still empty:
expect( await getEditedPostContent() ).toBe( '' );
// And focus is retained:
expect( await isInDefaultBlock() ).toBe( true );
} );
} );