/
query.test.js
110 lines (108 loc) · 3.57 KB
/
query.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
/**
* WordPress dependencies
*/
import {
activatePlugin,
deactivatePlugin,
createNewPost,
insertBlock,
publishPost,
trashAllPosts,
} from '@wordpress/e2e-test-utils';
const createDemoPosts = async () => {
await createNewPost( { postType: 'post', title: `Post 1` } );
await publishPost();
};
describe( 'Query block', () => {
beforeAll( async () => {
await activatePlugin( 'gutenberg-test-query-block' );
await createDemoPosts();
} );
afterAll( async () => {
await trashAllPosts();
await deactivatePlugin( 'gutenberg-test-query-block' );
} );
beforeEach( async () => {
await createNewPost( { postType: 'page', title: `Query Page` } );
} );
afterEach( async () => {
await trashAllPosts( 'page' );
} );
describe( 'Query block insertion', () => {
it( 'Carousel', async () => {
await insertBlock( 'Query' );
// Wait for the choose pattern button
const choosePatternButton = await page.waitForSelector(
'div[data-type="core/query"] button.is-primary'
);
await choosePatternButton.click();
// Wait for pattern blocks to be loaded.
await page.waitForSelector(
'.block-editor-block-pattern-setup__container iframe[title="Editor canvas"]'
);
/**
* Ensure that carousel is working by checking slider css classes
* and navigating to the next pattern.
*/
await page.waitForSelector(
'li.pattern-slide.active-slide[aria-label="Query Test 1"]'
);
const nextPatternButton = await page.waitForSelector(
'.block-editor-block-pattern-setup__navigation button[aria-label="Next pattern"]'
);
await nextPatternButton.click();
await page.waitForSelector(
'li.pattern-slide.active-slide[aria-label="Query Test 2"]'
);
// Choose the selected pattern.
const chooseButton = await page.waitForXPath(
'//div[contains(@class, "block-editor-block-pattern-setup__actions")]//button[text()="Choose"]'
);
chooseButton.click();
// Wait for pattern setup to go away.
await page.waitForSelector( '.block-editor-block-pattern-setup', {
hidden: true,
} );
/**
* We can't use `getEditedPostContent` easily for now because
* `query` makes used of `instanceId` so it's not very reliable.
* This should be revisited.
*/
await page.waitForSelector( '.wp-block-post-date' );
await page.waitForSelector( '.wp-block-post-title' );
} );
it( 'Grid view', async () => {
await insertBlock( 'Query' );
// Wait for the choose pattern button
const choosePatternButton = await page.waitForSelector(
'div[data-type="core/query"] button.is-primary'
);
await choosePatternButton.click();
// Wait for patterns setup to be loaded.
await page.waitForSelector(
'.block-editor-block-pattern-setup__display-controls'
);
// Click the Grid view button.
const gridViewButton = await page.waitForSelector(
'.block-editor-block-pattern-setup__display-controls button[aria-label="Grid view"]'
);
await gridViewButton.click();
// Wait for patterns to be loaded and click the wanted pattern.
const gridPattern = await page.waitForSelector(
'.block-editor-block-pattern-setup-list__list-item[aria-label="Query Test 2"]'
);
await gridPattern.click();
// Wait for pattern setup to go away.
await page.waitForSelector( '.block-editor-block-pattern-setup', {
hidden: true,
} );
/**
* We can't use `getEditedPostContent` easily for now because
* `query` makes used of `instanceId` so it's not very reliable.
* This should be revisited.
*/
await page.waitForSelector( '.wp-block-post-date' );
await page.waitForSelector( '.wp-block-post-title' );
} );
} );
} );