-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathmanage-reusable-blocks.test.js
60 lines (47 loc) · 1.47 KB
/
manage-reusable-blocks.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
/**
* External dependencies
*/
import path from 'path';
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
test.describe( 'Managing reusable blocks', () => {
test.beforeEach( async ( { admin } ) => {
await admin.visitAdminPage( 'edit.php', 'post_type=wp_block' );
} );
test( 'Should import reusable blocks', async ( { admin, page } ) => {
async function getNumberOfEntries() {
return page.evaluate(
() => document.querySelectorAll( '.hentry' ).length
);
}
const originalEntries = await getNumberOfEntries();
// Import Reusable block.
await page.click( 'role=button[name="Import from JSON"i]' );
// Select the file to upload.
const testReusableBlockFile = path.join(
__dirname,
'..',
'..',
'..',
'assets',
'greeting-reusable-block.json'
);
await page.setInputFiles( 'input[type="file"]', testReusableBlockFile );
// Submit the form.
await page.click( 'role=button[name="Import"i]' );
// Wait for the success notice.
await expect(
page.locator(
"div[class='notice notice-success is-dismissible'] p"
)
).toHaveText( 'Reusable block imported successfully!' );
await page.waitForTimeout( 2000 );
// Refresh the page.
await admin.visitAdminPage( 'edit.php', 'post_type=wp_block' );
const expectedEntries = originalEntries + 1;
const actualEntries = await page.locator( '.hentry' ).count();
expect( actualEntries ).toBe( expectedEntries );
} );
} );