-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
draggable-block.test.js
127 lines (104 loc) · 3.91 KB
/
draggable-block.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
/**
* WordPress dependencies
*/
import {
getEditedPostContent,
createNewPost,
deactivatePlugin,
activatePlugin,
showBlockToolbar,
setBrowserViewport,
waitForWindowDimensions,
} from '@wordpress/e2e-test-utils';
describe( 'Draggable block', () => {
// Tests don't seem to pass if beforeAll and afterAll are used.
// Unsure why.
beforeEach( async () => {
await deactivatePlugin(
'gutenberg-test-plugin-disables-the-css-animations'
);
// Set the viewport at a larger size than normal to ensure scrolling doesn't occur.
// Scrolling can interfere with the drag coordinates.
await page.setViewport( { width: 960, height: 1024 } );
await waitForWindowDimensions( 960, 1024 );
await createNewPost();
await page.setDragInterception( true );
} );
afterEach( async () => {
await page.setDragInterception( false );
// Reset the viewport to normal large size.
await setBrowserViewport( 'large' );
await activatePlugin(
'gutenberg-test-plugin-disables-the-css-animations'
);
} );
it( 'can drag and drop to the top of a block list', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '2' );
// Confirm correct setup.
expect( await getEditedPostContent() ).toMatchSnapshot();
await showBlockToolbar();
const dragHandle = await page.waitForSelector(
'.block-editor-block-mover__drag-handle'
);
const dragHandlePoint = await dragHandle.clickablePoint();
const firstParagraph = await page.$( '[data-type="core/paragraph"]' );
const targetPoint = await firstParagraph.clickablePoint();
const targetRect = await firstParagraph.boundingBox();
const target = {
x: targetPoint.x,
// Drag to the top half.
y: targetPoint.y - targetRect.height * 0.25,
};
const dragData = await page.mouse.drag( dragHandlePoint, target );
await page.mouse.dragEnter( target, dragData );
await page.mouse.dragOver( target, dragData );
// Wait for the insertion point to be visible.
const insertionPoint = await page.waitForSelector(
'.block-editor-block-list__insertion-point'
);
// Expect the insertion point to be visible above the first paragraph.
const insertionPointBoundingBox = await insertionPoint.boundingBox();
expect( insertionPointBoundingBox.y ).toBeLessThan( target.y );
await page.mouse.drop( target, dragData );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'can drag and drop to the bottom of a block list', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '2' );
await page.keyboard.press( 'ArrowUp' );
// Confirm correct setup.
expect( await getEditedPostContent() ).toMatchSnapshot();
const [ , secondParagraph ] = await page.$$(
'[data-type="core/paragraph"]'
);
await showBlockToolbar();
const dragHandle = await page.waitForSelector(
'.block-editor-block-mover__drag-handle'
);
const dragHandlePoint = await dragHandle.clickablePoint();
const targetPoint = await secondParagraph.clickablePoint();
const targetRect = await secondParagraph.boundingBox();
const target = {
x: targetPoint.x,
// Drag to the bottom half.
y: targetPoint.y + targetRect.height * 0.25,
};
const dragData = await page.mouse.drag( dragHandlePoint, target );
await page.mouse.dragEnter( target, dragData );
await page.mouse.dragOver( target, dragData );
// Wait for the insertion point to be visible.
const insertionPoint = await page.waitForSelector(
'.block-editor-block-list__insertion-point'
);
// Expect the insertion point to be visible below the first paragraph.
const insertionPointBoundingBox = await insertionPoint.boundingBox();
expect( insertionPointBoundingBox.y ).toBeGreaterThan( target.y );
await page.mouse.drop( target, dragData );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );