@wordpress/e2e-tests 7.16.0 → 7.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/package.json +8 -7
- package/plugins/block-icons/index.js +1 -1
- package/plugins/dataviews.php +25 -0
- package/plugins/interactive-blocks/directive-bind/render.php +3 -1
- package/plugins/interactive-blocks/directive-bind/view.js +32 -29
- package/plugins/interactive-blocks/directive-body/render.php +3 -1
- package/plugins/interactive-blocks/directive-body/view.js +11 -9
- package/plugins/interactive-blocks/directive-class/render.php +3 -1
- package/plugins/interactive-blocks/directive-class/view.js +20 -18
- package/plugins/interactive-blocks/directive-context/render.php +6 -4
- package/plugins/interactive-blocks/directive-context/view.js +49 -40
- package/plugins/interactive-blocks/directive-init/render.php +8 -6
- package/plugins/interactive-blocks/directive-init/view.js +59 -60
- package/plugins/interactive-blocks/directive-key/render.php +5 -1
- package/plugins/interactive-blocks/directive-key/view.js +18 -14
- package/plugins/interactive-blocks/directive-on/render.php +3 -1
- package/plugins/interactive-blocks/directive-on/view.js +27 -24
- package/plugins/interactive-blocks/directive-priorities/render.php +7 -2
- package/plugins/interactive-blocks/directive-priorities/view.js +107 -111
- package/plugins/interactive-blocks/directive-slots/render.php +3 -1
- package/plugins/interactive-blocks/directive-slots/view.js +17 -15
- package/plugins/interactive-blocks/directive-style/render.php +2 -1
- package/plugins/interactive-blocks/directive-style/view.js +21 -19
- package/plugins/interactive-blocks/directive-text/render.php +3 -1
- package/plugins/interactive-blocks/directive-text/view.js +16 -14
- package/plugins/interactive-blocks/{store-afterload → directive-watch}/block.json +3 -3
- package/plugins/interactive-blocks/{directive-effect → directive-watch}/render.php +8 -6
- package/plugins/interactive-blocks/directive-watch/view.js +53 -0
- package/plugins/interactive-blocks/negation-operator/render.php +4 -2
- package/plugins/interactive-blocks/negation-operator/view.js +15 -19
- package/plugins/interactive-blocks/router-navigate/render.php +11 -8
- package/plugins/interactive-blocks/router-navigate/view.js +27 -34
- package/plugins/interactive-blocks/router-regions/render.php +13 -3
- package/plugins/interactive-blocks/router-regions/view.js +37 -35
- package/plugins/interactive-blocks/store-tag/render.php +7 -4
- package/plugins/interactive-blocks/store-tag/view.js +19 -19
- package/plugins/interactive-blocks/tovdom/render.php +3 -1
- package/plugins/interactive-blocks/tovdom/view.js +5 -4
- package/plugins/interactive-blocks/tovdom-islands/render.php +11 -6
- package/plugins/interactive-blocks/tovdom-islands/view.js +24 -23
- package/plugins/interactive-blocks.php +4 -4
- package/specs/editor/various/datepicker.test.js +8 -8
- package/specs/editor/various/pattern-blocks.test.js +4 -4
- package/specs/editor/various/scheduling.test.js +1 -1
- package/plugins/interactive-blocks/directive-effect/block.json +0 -14
- package/plugins/interactive-blocks/directive-effect/view.js +0 -59
- package/plugins/interactive-blocks/store-afterload/render.php +0 -41
- package/plugins/interactive-blocks/store-afterload/view.js +0 -60
- package/specs/editor/plugins/__snapshots__/align-hook.test.js.snap +0 -43
- package/specs/editor/plugins/__snapshots__/block-directory-add.test.js.snap +0 -3
- package/specs/editor/plugins/__snapshots__/container-blocks.test.js.snap +0 -58
- package/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap +0 -147
- package/specs/editor/plugins/__snapshots__/inner-blocks-render-appender.test.js.snap +0 -25
- package/specs/editor/plugins/__snapshots__/meta-attribute-block.test.js.snap +0 -9
- package/specs/editor/plugins/__snapshots__/plugins-api.test.js.snap +0 -7
- package/specs/editor/plugins/align-hook.test.js +0 -234
- package/specs/editor/plugins/annotations.test.js +0 -189
- package/specs/editor/plugins/block-directory-add.test.js +0 -205
- package/specs/editor/plugins/block-icons.test.js +0 -170
- package/specs/editor/plugins/child-blocks.test.js +0 -66
- package/specs/editor/plugins/container-blocks.test.js +0 -130
- package/specs/editor/plugins/cpt-locking.test.js +0 -251
- package/specs/editor/plugins/custom-taxonomies.test.js +0 -61
- package/specs/editor/plugins/inner-blocks-prioritized-inserter-blocks.test.js +0 -132
- package/specs/editor/plugins/inner-blocks-render-appender.test.js +0 -126
- package/specs/editor/plugins/meta-attribute-block.test.js +0 -100
- package/specs/editor/plugins/meta-boxes.test.js +0 -137
- package/specs/editor/plugins/plugins-api.test.js +0 -189
- package/specs/editor/various/is-typing.test.js +0 -101
- package/specs/editor/various/publish-button.test.js +0 -46
- package/specs/editor/various/sidebar-permalink.test.js +0 -53
@@ -1,189 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* WordPress dependencies
|
3
|
-
*/
|
4
|
-
import {
|
5
|
-
activatePlugin,
|
6
|
-
clickBlockToolbarButton,
|
7
|
-
clickMenuItem,
|
8
|
-
clickOnMoreMenuItem,
|
9
|
-
createNewPost,
|
10
|
-
deactivatePlugin,
|
11
|
-
canvas,
|
12
|
-
} from '@wordpress/e2e-test-utils';
|
13
|
-
|
14
|
-
const clickOnBlockSettingsMenuItem = async ( buttonLabel ) => {
|
15
|
-
await clickBlockToolbarButton( 'Options' );
|
16
|
-
await clickMenuItem( buttonLabel );
|
17
|
-
};
|
18
|
-
|
19
|
-
const ANNOTATIONS_SELECTOR = '.annotation-text-e2e-tests';
|
20
|
-
|
21
|
-
describe( 'Annotations', () => {
|
22
|
-
beforeAll( async () => {
|
23
|
-
await activatePlugin( 'gutenberg-test-plugin-plugins-api' );
|
24
|
-
} );
|
25
|
-
|
26
|
-
afterAll( async () => {
|
27
|
-
await deactivatePlugin( 'gutenberg-test-plugin-plugins-api' );
|
28
|
-
} );
|
29
|
-
|
30
|
-
beforeEach( async () => {
|
31
|
-
await createNewPost();
|
32
|
-
} );
|
33
|
-
|
34
|
-
/**
|
35
|
-
* Annotates the text in the first block from start to end.
|
36
|
-
*
|
37
|
-
* @param {number} start Position to start the annotation.
|
38
|
-
* @param {number} end Position to end the annotation.
|
39
|
-
*
|
40
|
-
* @return {void}
|
41
|
-
*/
|
42
|
-
async function annotateFirstBlock( start, end ) {
|
43
|
-
await page.focus( '#annotations-tests-range-start' );
|
44
|
-
await page.keyboard.press( 'Backspace' );
|
45
|
-
await page.keyboard.type( start + '' );
|
46
|
-
await page.focus( '#annotations-tests-range-end' );
|
47
|
-
await page.keyboard.press( 'Backspace' );
|
48
|
-
await page.keyboard.type( end + '' );
|
49
|
-
|
50
|
-
// Click add annotation button.
|
51
|
-
const addAnnotationButton = (
|
52
|
-
await page.$x( "//button[contains(text(), 'Add annotation')]" )
|
53
|
-
)[ 0 ];
|
54
|
-
await addAnnotationButton.click();
|
55
|
-
await canvas().evaluate( () =>
|
56
|
-
document.querySelector( '.wp-block-paragraph' ).focus()
|
57
|
-
);
|
58
|
-
}
|
59
|
-
|
60
|
-
/**
|
61
|
-
* Presses the button that removes all annotations.
|
62
|
-
*
|
63
|
-
* @return {void}
|
64
|
-
*/
|
65
|
-
async function removeAnnotations() {
|
66
|
-
// Click remove annotations button.
|
67
|
-
const addAnnotationButton = (
|
68
|
-
await page.$x( "//button[contains(text(), 'Remove annotations')]" )
|
69
|
-
)[ 0 ];
|
70
|
-
await addAnnotationButton.click();
|
71
|
-
await canvas().evaluate( () =>
|
72
|
-
document.querySelector( '[contenteditable]' ).focus()
|
73
|
-
);
|
74
|
-
}
|
75
|
-
|
76
|
-
/**
|
77
|
-
* Returns the inner text of the first text annotation on the page.
|
78
|
-
*
|
79
|
-
* @return {Promise<string>} The annotated text.
|
80
|
-
*/
|
81
|
-
async function getAnnotatedText() {
|
82
|
-
const annotations = await canvas().$$( ANNOTATIONS_SELECTOR );
|
83
|
-
|
84
|
-
const annotation = annotations[ 0 ];
|
85
|
-
|
86
|
-
return await canvas().evaluate( ( el ) => el.innerText, annotation );
|
87
|
-
}
|
88
|
-
|
89
|
-
/**
|
90
|
-
* Returns the inner HTML of the first RichText in the page.
|
91
|
-
*
|
92
|
-
* @return {Promise<string>} Inner HTML.
|
93
|
-
*/
|
94
|
-
async function getRichTextInnerHTML() {
|
95
|
-
const htmlContent = await canvas().$$( '.wp-block-paragraph' );
|
96
|
-
return await canvas().evaluate( ( el ) => {
|
97
|
-
return el.innerHTML;
|
98
|
-
}, htmlContent[ 0 ] );
|
99
|
-
}
|
100
|
-
|
101
|
-
it( 'allows a block to be annotated', async () => {
|
102
|
-
await page.keyboard.type( 'Title' + '\n' + 'Paragraph to annotate' );
|
103
|
-
|
104
|
-
await clickOnMoreMenuItem( 'Annotations' );
|
105
|
-
|
106
|
-
let annotations = await canvas().$$( ANNOTATIONS_SELECTOR );
|
107
|
-
expect( annotations ).toHaveLength( 0 );
|
108
|
-
|
109
|
-
await annotateFirstBlock( 9, 13 );
|
110
|
-
|
111
|
-
annotations = await canvas().$$( ANNOTATIONS_SELECTOR );
|
112
|
-
expect( annotations ).toHaveLength( 1 );
|
113
|
-
|
114
|
-
const text = await getAnnotatedText();
|
115
|
-
expect( text ).toBe( ' to ' );
|
116
|
-
|
117
|
-
await clickOnBlockSettingsMenuItem( 'Edit as HTML' );
|
118
|
-
|
119
|
-
const htmlContent = await canvas().$$(
|
120
|
-
'.block-editor-block-list__block-html-textarea'
|
121
|
-
);
|
122
|
-
const html = await canvas().evaluate( ( el ) => {
|
123
|
-
return el.innerHTML;
|
124
|
-
}, htmlContent[ 0 ] );
|
125
|
-
|
126
|
-
// There should be no <mark> tags in the raw content.
|
127
|
-
expect( html ).toBe( '<p>Paragraph to annotate</p>' );
|
128
|
-
} );
|
129
|
-
|
130
|
-
it( 'keeps the cursor in the same location when applying annotation', async () => {
|
131
|
-
await page.keyboard.type( 'Title' + '\n' + 'ABC' );
|
132
|
-
await clickOnMoreMenuItem( 'Annotations' );
|
133
|
-
|
134
|
-
await annotateFirstBlock( 1, 2 );
|
135
|
-
|
136
|
-
// The selection should still be at the end, so test that by typing:
|
137
|
-
await page.keyboard.type( 'D' );
|
138
|
-
|
139
|
-
await removeAnnotations();
|
140
|
-
const htmlContent = await canvas().$$( '.wp-block-paragraph' );
|
141
|
-
const html = await canvas().evaluate( ( el ) => {
|
142
|
-
return el.innerHTML;
|
143
|
-
}, htmlContent[ 0 ] );
|
144
|
-
|
145
|
-
expect( html ).toBe( 'ABCD' );
|
146
|
-
} );
|
147
|
-
|
148
|
-
it( 'moves when typing before it', async () => {
|
149
|
-
await page.keyboard.type( 'Title' + '\n' + 'ABC' );
|
150
|
-
await clickOnMoreMenuItem( 'Annotations' );
|
151
|
-
|
152
|
-
await annotateFirstBlock( 1, 2 );
|
153
|
-
|
154
|
-
await page.keyboard.press( 'ArrowLeft' );
|
155
|
-
await page.keyboard.press( 'ArrowLeft' );
|
156
|
-
await page.keyboard.press( 'ArrowLeft' );
|
157
|
-
await page.keyboard.press( 'ArrowLeft' );
|
158
|
-
|
159
|
-
// Put an 1 after the A, it should not be annotated.
|
160
|
-
await page.keyboard.type( '1' );
|
161
|
-
|
162
|
-
const annotatedText = await getAnnotatedText();
|
163
|
-
expect( annotatedText ).toBe( 'B' );
|
164
|
-
|
165
|
-
await removeAnnotations();
|
166
|
-
const blockText = await getRichTextInnerHTML();
|
167
|
-
expect( blockText ).toBe( 'A1BC' );
|
168
|
-
} );
|
169
|
-
|
170
|
-
it( 'grows when typing inside it', async () => {
|
171
|
-
await page.keyboard.type( 'Title' + '\n' + 'ABC' );
|
172
|
-
await clickOnMoreMenuItem( 'Annotations' );
|
173
|
-
|
174
|
-
await annotateFirstBlock( 1, 2 );
|
175
|
-
|
176
|
-
await page.keyboard.press( 'ArrowLeft' );
|
177
|
-
await page.keyboard.press( 'ArrowLeft' );
|
178
|
-
|
179
|
-
// Put an 1 after the A, it should not be annotated.
|
180
|
-
await page.keyboard.type( '2' );
|
181
|
-
|
182
|
-
const annotatedText = await getAnnotatedText();
|
183
|
-
expect( annotatedText ).toBe( 'B2' );
|
184
|
-
|
185
|
-
await removeAnnotations();
|
186
|
-
const blockText = await getRichTextInnerHTML();
|
187
|
-
expect( blockText ).toBe( 'AB2C' );
|
188
|
-
} );
|
189
|
-
} );
|
@@ -1,205 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* WordPress dependencies
|
3
|
-
*/
|
4
|
-
import {
|
5
|
-
createNewPost,
|
6
|
-
searchForBlock,
|
7
|
-
insertBlockDirectoryBlock,
|
8
|
-
setUpResponseMocking,
|
9
|
-
getEditedPostContent,
|
10
|
-
createJSONResponse,
|
11
|
-
} from '@wordpress/e2e-test-utils';
|
12
|
-
|
13
|
-
const BLOCK1_NAME = 'block-directory-test-block/main-block';
|
14
|
-
|
15
|
-
// Urls to mock.
|
16
|
-
const SEARCH_URLS = [
|
17
|
-
'/wp/v2/block-directory/search',
|
18
|
-
`rest_route=${ encodeURIComponent( '/wp/v2/block-directory/search' ) }`,
|
19
|
-
];
|
20
|
-
|
21
|
-
const BLOCK_TYPE_URLS = [
|
22
|
-
`/wp/v2/block-types/${ BLOCK1_NAME }`,
|
23
|
-
`rest_route=${ encodeURIComponent(
|
24
|
-
`/wp/v2/block-types/${ BLOCK1_NAME }`
|
25
|
-
) }`,
|
26
|
-
];
|
27
|
-
|
28
|
-
const INSTALL_URLS = [
|
29
|
-
'/wp/v2/plugins',
|
30
|
-
`rest_route=${ encodeURIComponent( '/wp/v2/plugins' ) }`,
|
31
|
-
];
|
32
|
-
|
33
|
-
// Example Blocks.
|
34
|
-
const MOCK_BLOCK1 = {
|
35
|
-
name: BLOCK1_NAME,
|
36
|
-
title: 'Block Directory Test Block',
|
37
|
-
description: 'This plugin is useful for the block.',
|
38
|
-
id: 'block-directory-test-block',
|
39
|
-
rating: 0,
|
40
|
-
rating_count: 0,
|
41
|
-
active_installs: 0,
|
42
|
-
author_block_rating: 0,
|
43
|
-
author_block_count: 1,
|
44
|
-
author: 'No Author',
|
45
|
-
icon: 'block-default',
|
46
|
-
assets: [
|
47
|
-
'https://fake_url.com/block.js', // We will mock this.
|
48
|
-
],
|
49
|
-
humanized_updated: '5 months ago',
|
50
|
-
links: {},
|
51
|
-
};
|
52
|
-
|
53
|
-
const MOCK_INSTALLED_BLOCK_PLUGIN_DETAILS = {
|
54
|
-
plugin: 'block-directory-test-block',
|
55
|
-
status: 'active',
|
56
|
-
name: 'Block Directory',
|
57
|
-
plugin_uri: '',
|
58
|
-
author: 'No Author',
|
59
|
-
author_uri: '',
|
60
|
-
description: {
|
61
|
-
raw: 'This plugin is useful for the block.',
|
62
|
-
rendered: 'This plugin is useful for the block.',
|
63
|
-
},
|
64
|
-
version: '1.0',
|
65
|
-
network_only: false,
|
66
|
-
requires_wp: '',
|
67
|
-
requires_php: '',
|
68
|
-
text_domain: 'block-directory-test-block',
|
69
|
-
_links: {
|
70
|
-
self: [
|
71
|
-
{
|
72
|
-
href: '',
|
73
|
-
},
|
74
|
-
],
|
75
|
-
},
|
76
|
-
};
|
77
|
-
|
78
|
-
const MOCK_BLOCK2 = {
|
79
|
-
...MOCK_BLOCK1,
|
80
|
-
name: 'block-directory-test-block/secondary-block',
|
81
|
-
title: 'Block Directory Test Block - Pt Deux',
|
82
|
-
id: 'block-directory-test-secondary-block',
|
83
|
-
};
|
84
|
-
|
85
|
-
// Block that will be registered.
|
86
|
-
const block = `( function() {
|
87
|
-
var registerBlockType = wp.blocks.registerBlockType;
|
88
|
-
var el = wp.element.createElement;
|
89
|
-
|
90
|
-
registerBlockType( '${ MOCK_BLOCK1.name }', {
|
91
|
-
title: 'Test Block for Block Directory',
|
92
|
-
icon: 'hammer',
|
93
|
-
category: 'text',
|
94
|
-
attributes: {},
|
95
|
-
edit: function( props ) {
|
96
|
-
return el( 'p', null, 'Test Copy' );
|
97
|
-
},
|
98
|
-
save: function() {
|
99
|
-
return null;
|
100
|
-
},
|
101
|
-
} );
|
102
|
-
} )();`;
|
103
|
-
|
104
|
-
const MOCK_EMPTY_RESPONSES = [
|
105
|
-
{
|
106
|
-
match: ( request ) =>
|
107
|
-
matchUrl( request.url(), SEARCH_URLS ) &&
|
108
|
-
request.method() === 'GET',
|
109
|
-
onRequestMatch: createJSONResponse( [] ),
|
110
|
-
},
|
111
|
-
];
|
112
|
-
|
113
|
-
const MOCK_BLOCKS_RESPONSES = [
|
114
|
-
{
|
115
|
-
// Mock response for search with the block.
|
116
|
-
match: ( request ) =>
|
117
|
-
matchUrl( request.url(), SEARCH_URLS ) &&
|
118
|
-
request.method() === 'GET',
|
119
|
-
onRequestMatch: createJSONResponse( [ MOCK_BLOCK1, MOCK_BLOCK2 ] ),
|
120
|
-
},
|
121
|
-
{
|
122
|
-
// Mock response for block type.
|
123
|
-
match: ( request ) => matchUrl( request.url(), BLOCK_TYPE_URLS ),
|
124
|
-
onRequestMatch: createJSONResponse( {} ),
|
125
|
-
},
|
126
|
-
{
|
127
|
-
// Mock response for install.
|
128
|
-
match: ( request ) => matchUrl( request.url(), INSTALL_URLS ),
|
129
|
-
onRequestMatch: createJSONResponse(
|
130
|
-
MOCK_INSTALLED_BLOCK_PLUGIN_DETAILS
|
131
|
-
),
|
132
|
-
},
|
133
|
-
{
|
134
|
-
// Mock the response for the js asset once it gets injected.
|
135
|
-
match: ( request ) => request.url().includes( MOCK_BLOCK1.assets[ 0 ] ),
|
136
|
-
onRequestMatch: createResponse(
|
137
|
-
Buffer.from( block, 'utf8' ),
|
138
|
-
'application/javascript; charset=utf-8'
|
139
|
-
),
|
140
|
-
},
|
141
|
-
{
|
142
|
-
// Mock the post-new page as requested via apiFetch for determining new CSS/JS assets.
|
143
|
-
match: ( request ) => request.url().includes( '/post-new.php' ),
|
144
|
-
onRequestMatch: createResponse(
|
145
|
-
`<html><head><script id="mock-block-js" src="${ MOCK_BLOCK1.assets[ 0 ] }"></script></head><body/></html>`,
|
146
|
-
'text/html; charset=UTF-8'
|
147
|
-
),
|
148
|
-
},
|
149
|
-
];
|
150
|
-
|
151
|
-
function getResponseObject( obj, contentType ) {
|
152
|
-
return {
|
153
|
-
status: 200,
|
154
|
-
contentType,
|
155
|
-
body: obj,
|
156
|
-
};
|
157
|
-
}
|
158
|
-
|
159
|
-
function createResponse( mockResponse, contentType ) {
|
160
|
-
return async ( request ) =>
|
161
|
-
request.respond( getResponseObject( mockResponse, contentType ) );
|
162
|
-
}
|
163
|
-
|
164
|
-
const matchUrl = ( reqUrl, urls ) => {
|
165
|
-
return urls.some( ( el ) => reqUrl.indexOf( el ) >= 0 );
|
166
|
-
};
|
167
|
-
|
168
|
-
describe( 'adding blocks from block directory', () => {
|
169
|
-
beforeAll( async () => {
|
170
|
-
await createNewPost();
|
171
|
-
} );
|
172
|
-
|
173
|
-
it( 'Should show an empty state when no plugin is found.', async () => {
|
174
|
-
// Be super weird so there won't be a matching block installed.
|
175
|
-
const impossibleBlockName = '@#$@@Dsdsdfw2#$@';
|
176
|
-
|
177
|
-
// Return an empty list of plugins.
|
178
|
-
await setUpResponseMocking( MOCK_EMPTY_RESPONSES );
|
179
|
-
|
180
|
-
// Search for the block via the inserter.
|
181
|
-
await searchForBlock( impossibleBlockName );
|
182
|
-
|
183
|
-
const selectorContent = await page.evaluate(
|
184
|
-
() =>
|
185
|
-
document.querySelector( '.block-editor-inserter__main-area' )
|
186
|
-
.innerHTML
|
187
|
-
);
|
188
|
-
expect( selectorContent ).toContain(
|
189
|
-
'block-editor-inserter__no-results'
|
190
|
-
);
|
191
|
-
} );
|
192
|
-
|
193
|
-
it( 'Should be able to add (the first) block.', async () => {
|
194
|
-
// Setup our mocks.
|
195
|
-
await setUpResponseMocking( MOCK_BLOCKS_RESPONSES );
|
196
|
-
|
197
|
-
// Search for the block via the inserter.
|
198
|
-
await insertBlockDirectoryBlock( MOCK_BLOCK1.title );
|
199
|
-
|
200
|
-
await page.waitForSelector( `div[data-type="${ MOCK_BLOCK1.name }"]` );
|
201
|
-
|
202
|
-
// The block will auto select and get added, make sure we see it in the content.
|
203
|
-
expect( await getEditedPostContent() ).toMatchSnapshot();
|
204
|
-
} );
|
205
|
-
} );
|
@@ -1,170 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* WordPress dependencies
|
3
|
-
*/
|
4
|
-
import {
|
5
|
-
activatePlugin,
|
6
|
-
createNewPost,
|
7
|
-
deactivatePlugin,
|
8
|
-
insertBlock,
|
9
|
-
pressKeyWithModifier,
|
10
|
-
searchForBlock,
|
11
|
-
openDocumentSettingsSidebar,
|
12
|
-
} from '@wordpress/e2e-test-utils';
|
13
|
-
|
14
|
-
const INSERTER_BUTTON_SELECTOR =
|
15
|
-
'.block-editor-inserter__main-area .block-editor-block-types-list__item';
|
16
|
-
const INSERTER_ICON_WRAPPER_SELECTOR = `${ INSERTER_BUTTON_SELECTOR } .block-editor-block-types-list__item-icon`;
|
17
|
-
const INSERTER_ICON_SELECTOR = `${ INSERTER_BUTTON_SELECTOR } .block-editor-block-icon`;
|
18
|
-
const INSPECTOR_ICON_SELECTOR = '.edit-post-sidebar .block-editor-block-icon';
|
19
|
-
|
20
|
-
async function getInnerHTML( selector ) {
|
21
|
-
return await page.$eval( selector, ( element ) => element.innerHTML );
|
22
|
-
}
|
23
|
-
|
24
|
-
async function getBackgroundColor( selector ) {
|
25
|
-
return await page.$eval( selector, ( element ) => {
|
26
|
-
return window.getComputedStyle( element ).backgroundColor;
|
27
|
-
} );
|
28
|
-
}
|
29
|
-
|
30
|
-
async function getColor( selector ) {
|
31
|
-
return await page.$eval( selector, ( element ) => {
|
32
|
-
return window.getComputedStyle( element ).color;
|
33
|
-
} );
|
34
|
-
}
|
35
|
-
|
36
|
-
async function getFirstInserterIcon() {
|
37
|
-
return await getInnerHTML( INSERTER_ICON_SELECTOR );
|
38
|
-
}
|
39
|
-
|
40
|
-
async function selectFirstBlock() {
|
41
|
-
await pressKeyWithModifier( 'access', 'o' );
|
42
|
-
const navButtons = await page.$$(
|
43
|
-
'.block-editor-list-view-block-select-button'
|
44
|
-
);
|
45
|
-
await navButtons[ 0 ].click();
|
46
|
-
}
|
47
|
-
|
48
|
-
describe( 'Correctly Renders Block Icons on Inserter and Inspector', () => {
|
49
|
-
const dashIconRegex = /<span.*?class=".*?dashicons-cart.*?">.*?<\/span>/;
|
50
|
-
const circleString =
|
51
|
-
'<circle cx="10" cy="10" r="10" fill="red" stroke="blue" stroke-width="10"></circle>';
|
52
|
-
const svgIcon = new RegExp(
|
53
|
-
`<svg.*?viewBox="0 0 20 20".*?>${ circleString }</svg>`
|
54
|
-
);
|
55
|
-
|
56
|
-
const validateSvgIcon = ( iconHtml ) => {
|
57
|
-
expect( iconHtml ).toMatch( svgIcon );
|
58
|
-
};
|
59
|
-
|
60
|
-
const validateDashIcon = ( iconHtml ) => {
|
61
|
-
expect( iconHtml ).toMatch( dashIconRegex );
|
62
|
-
};
|
63
|
-
|
64
|
-
beforeAll( async () => {
|
65
|
-
await activatePlugin( 'gutenberg-test-block-icons' );
|
66
|
-
} );
|
67
|
-
|
68
|
-
beforeEach( async () => {
|
69
|
-
await createNewPost();
|
70
|
-
} );
|
71
|
-
|
72
|
-
afterAll( async () => {
|
73
|
-
await deactivatePlugin( 'gutenberg-test-block-icons' );
|
74
|
-
} );
|
75
|
-
|
76
|
-
function testIconsOfBlock( blockName, blockTitle, validateIcon ) {
|
77
|
-
it( 'Renders correctly the icon in the inserter', async () => {
|
78
|
-
await searchForBlock( blockTitle );
|
79
|
-
validateIcon( await getFirstInserterIcon() );
|
80
|
-
} );
|
81
|
-
|
82
|
-
it( 'Can insert the block', async () => {
|
83
|
-
await insertBlock( blockTitle );
|
84
|
-
expect(
|
85
|
-
await getInnerHTML(
|
86
|
-
`[data-type="${ blockName }"] [data-type="core/paragraph"]`
|
87
|
-
)
|
88
|
-
).toEqual( blockTitle );
|
89
|
-
} );
|
90
|
-
|
91
|
-
it( 'Renders correctly the icon on the inspector', async () => {
|
92
|
-
await insertBlock( blockTitle );
|
93
|
-
await openDocumentSettingsSidebar();
|
94
|
-
await selectFirstBlock();
|
95
|
-
validateIcon( await getInnerHTML( INSPECTOR_ICON_SELECTOR ) );
|
96
|
-
} );
|
97
|
-
}
|
98
|
-
|
99
|
-
describe( 'Block with svg icon', () => {
|
100
|
-
const blockName = 'test/test-single-svg-icon';
|
101
|
-
const blockTitle = 'TestSimpleSvgIcon';
|
102
|
-
testIconsOfBlock( blockName, blockTitle, validateSvgIcon );
|
103
|
-
} );
|
104
|
-
|
105
|
-
describe( 'Block with dash icon', () => {
|
106
|
-
const blockName = 'test/test-dash-icon';
|
107
|
-
const blockTitle = 'TestDashIcon';
|
108
|
-
testIconsOfBlock( blockName, blockTitle, validateDashIcon );
|
109
|
-
} );
|
110
|
-
|
111
|
-
describe( 'Block with function icon', () => {
|
112
|
-
const blockName = 'test/test-function-icon';
|
113
|
-
const blockTitle = 'TestFunctionIcon';
|
114
|
-
testIconsOfBlock( blockName, blockTitle, validateSvgIcon );
|
115
|
-
} );
|
116
|
-
|
117
|
-
describe( 'Block with dash icon and background and foreground colors', () => {
|
118
|
-
const blockTitle = 'TestDashIconColors';
|
119
|
-
it( 'Renders the icon in the inserter with the correct colors', async () => {
|
120
|
-
await searchForBlock( blockTitle );
|
121
|
-
validateDashIcon( await getFirstInserterIcon() );
|
122
|
-
expect(
|
123
|
-
await getBackgroundColor( INSERTER_ICON_WRAPPER_SELECTOR )
|
124
|
-
).toEqual( 'rgb(1, 0, 0)' );
|
125
|
-
expect( await getColor( INSERTER_ICON_WRAPPER_SELECTOR ) ).toEqual(
|
126
|
-
'rgb(254, 0, 0)'
|
127
|
-
);
|
128
|
-
} );
|
129
|
-
|
130
|
-
it( 'Renders the icon in the inspector with the correct colors', async () => {
|
131
|
-
await insertBlock( blockTitle );
|
132
|
-
await openDocumentSettingsSidebar();
|
133
|
-
await selectFirstBlock();
|
134
|
-
validateDashIcon( await getInnerHTML( INSPECTOR_ICON_SELECTOR ) );
|
135
|
-
expect(
|
136
|
-
await getBackgroundColor( INSPECTOR_ICON_SELECTOR )
|
137
|
-
).toEqual( 'rgb(1, 0, 0)' );
|
138
|
-
expect( await getColor( INSPECTOR_ICON_SELECTOR ) ).toEqual(
|
139
|
-
'rgb(254, 0, 0)'
|
140
|
-
);
|
141
|
-
} );
|
142
|
-
} );
|
143
|
-
|
144
|
-
describe( 'Block with svg icon and background color', () => {
|
145
|
-
const blockTitle = 'TestSvgIconBackground';
|
146
|
-
it( 'Renders the icon in the inserter with the correct background color and an automatically compute readable foreground color', async () => {
|
147
|
-
await searchForBlock( blockTitle );
|
148
|
-
validateSvgIcon( await getFirstInserterIcon() );
|
149
|
-
expect(
|
150
|
-
await getBackgroundColor( INSERTER_ICON_WRAPPER_SELECTOR )
|
151
|
-
).toEqual( 'rgb(1, 0, 0)' );
|
152
|
-
expect( await getColor( INSERTER_ICON_WRAPPER_SELECTOR ) ).toEqual(
|
153
|
-
'rgb(248, 249, 249)'
|
154
|
-
);
|
155
|
-
} );
|
156
|
-
|
157
|
-
it( 'Renders correctly the icon on the inspector', async () => {
|
158
|
-
await insertBlock( blockTitle );
|
159
|
-
await openDocumentSettingsSidebar();
|
160
|
-
await selectFirstBlock();
|
161
|
-
validateSvgIcon( await getInnerHTML( INSPECTOR_ICON_SELECTOR ) );
|
162
|
-
expect(
|
163
|
-
await getBackgroundColor( INSPECTOR_ICON_SELECTOR )
|
164
|
-
).toEqual( 'rgb(1, 0, 0)' );
|
165
|
-
expect( await getColor( INSPECTOR_ICON_SELECTOR ) ).toEqual(
|
166
|
-
'rgb(248, 249, 249)'
|
167
|
-
);
|
168
|
-
} );
|
169
|
-
} );
|
170
|
-
} );
|
@@ -1,66 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* WordPress dependencies
|
3
|
-
*/
|
4
|
-
import {
|
5
|
-
activatePlugin,
|
6
|
-
closeGlobalBlockInserter,
|
7
|
-
createNewPost,
|
8
|
-
deactivatePlugin,
|
9
|
-
getAllBlockInserterItemTitles,
|
10
|
-
insertBlock,
|
11
|
-
openGlobalBlockInserter,
|
12
|
-
} from '@wordpress/e2e-test-utils';
|
13
|
-
|
14
|
-
describe( 'Child Blocks', () => {
|
15
|
-
beforeAll( async () => {
|
16
|
-
await activatePlugin( 'gutenberg-test-child-blocks' );
|
17
|
-
} );
|
18
|
-
|
19
|
-
beforeEach( async () => {
|
20
|
-
await createNewPost();
|
21
|
-
} );
|
22
|
-
|
23
|
-
afterAll( async () => {
|
24
|
-
await deactivatePlugin( 'gutenberg-test-child-blocks' );
|
25
|
-
} );
|
26
|
-
|
27
|
-
it( 'are hidden from the global block inserter', async () => {
|
28
|
-
await openGlobalBlockInserter();
|
29
|
-
await expect( await getAllBlockInserterItemTitles() ).not.toContain(
|
30
|
-
'Child Blocks Child'
|
31
|
-
);
|
32
|
-
} );
|
33
|
-
|
34
|
-
it( 'shows up in a parent block', async () => {
|
35
|
-
await insertBlock( 'Child Blocks Unrestricted Parent' );
|
36
|
-
await closeGlobalBlockInserter();
|
37
|
-
await page.waitForSelector(
|
38
|
-
'[data-type="test/child-blocks-unrestricted-parent"] .block-editor-default-block-appender'
|
39
|
-
);
|
40
|
-
await page.click(
|
41
|
-
'[data-type="test/child-blocks-unrestricted-parent"] .block-editor-default-block-appender'
|
42
|
-
);
|
43
|
-
await openGlobalBlockInserter();
|
44
|
-
const inserterItemTitles = await getAllBlockInserterItemTitles();
|
45
|
-
expect( inserterItemTitles ).toContain( 'Child Blocks Child' );
|
46
|
-
expect( inserterItemTitles.length ).toBeGreaterThan( 20 );
|
47
|
-
} );
|
48
|
-
|
49
|
-
it( 'display in a parent block with allowedItems', async () => {
|
50
|
-
await insertBlock( 'Child Blocks Restricted Parent' );
|
51
|
-
await closeGlobalBlockInserter();
|
52
|
-
await page.waitForSelector(
|
53
|
-
'[data-type="test/child-blocks-restricted-parent"] .block-editor-default-block-appender'
|
54
|
-
);
|
55
|
-
await page.click(
|
56
|
-
'[data-type="test/child-blocks-restricted-parent"] .block-editor-default-block-appender'
|
57
|
-
);
|
58
|
-
await openGlobalBlockInserter();
|
59
|
-
const allowedBlocks = await getAllBlockInserterItemTitles();
|
60
|
-
expect( allowedBlocks.sort() ).toEqual( [
|
61
|
-
'Child Blocks Child',
|
62
|
-
'Image',
|
63
|
-
'Paragraph',
|
64
|
-
] );
|
65
|
-
} );
|
66
|
-
} );
|