@wordpress/e2e-tests 7.17.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/package.json +8 -7
  3. package/plugins/block-icons/index.js +1 -1
  4. package/plugins/dataviews.php +25 -0
  5. package/plugins/interactive-blocks/directive-bind/render.php +3 -1
  6. package/plugins/interactive-blocks/directive-bind/view.js +32 -29
  7. package/plugins/interactive-blocks/directive-body/render.php +3 -1
  8. package/plugins/interactive-blocks/directive-body/view.js +11 -9
  9. package/plugins/interactive-blocks/directive-class/render.php +3 -1
  10. package/plugins/interactive-blocks/directive-class/view.js +20 -18
  11. package/plugins/interactive-blocks/directive-context/render.php +6 -4
  12. package/plugins/interactive-blocks/directive-context/view.js +49 -40
  13. package/plugins/interactive-blocks/directive-init/render.php +8 -6
  14. package/plugins/interactive-blocks/directive-init/view.js +59 -60
  15. package/plugins/interactive-blocks/directive-key/render.php +5 -1
  16. package/plugins/interactive-blocks/directive-key/view.js +18 -14
  17. package/plugins/interactive-blocks/directive-on/render.php +3 -1
  18. package/plugins/interactive-blocks/directive-on/view.js +27 -24
  19. package/plugins/interactive-blocks/directive-priorities/render.php +7 -2
  20. package/plugins/interactive-blocks/directive-priorities/view.js +107 -111
  21. package/plugins/interactive-blocks/directive-slots/render.php +3 -1
  22. package/plugins/interactive-blocks/directive-slots/view.js +17 -15
  23. package/plugins/interactive-blocks/directive-style/render.php +2 -1
  24. package/plugins/interactive-blocks/directive-style/view.js +21 -19
  25. package/plugins/interactive-blocks/directive-text/render.php +3 -1
  26. package/plugins/interactive-blocks/directive-text/view.js +16 -14
  27. package/plugins/interactive-blocks/{store-afterload → directive-watch}/block.json +3 -3
  28. package/plugins/interactive-blocks/{directive-effect → directive-watch}/render.php +8 -6
  29. package/plugins/interactive-blocks/directive-watch/view.js +53 -0
  30. package/plugins/interactive-blocks/negation-operator/render.php +4 -2
  31. package/plugins/interactive-blocks/negation-operator/view.js +15 -19
  32. package/plugins/interactive-blocks/router-navigate/render.php +11 -8
  33. package/plugins/interactive-blocks/router-navigate/view.js +27 -34
  34. package/plugins/interactive-blocks/router-regions/render.php +13 -3
  35. package/plugins/interactive-blocks/router-regions/view.js +37 -35
  36. package/plugins/interactive-blocks/store-tag/render.php +7 -4
  37. package/plugins/interactive-blocks/store-tag/view.js +19 -19
  38. package/plugins/interactive-blocks/tovdom/render.php +3 -1
  39. package/plugins/interactive-blocks/tovdom/view.js +5 -4
  40. package/plugins/interactive-blocks/tovdom-islands/render.php +11 -6
  41. package/plugins/interactive-blocks/tovdom-islands/view.js +24 -23
  42. package/plugins/interactive-blocks.php +2 -2
  43. package/specs/editor/various/datepicker.test.js +8 -8
  44. package/specs/editor/various/pattern-blocks.test.js +4 -4
  45. package/specs/editor/various/scheduling.test.js +1 -1
  46. package/plugins/interactive-blocks/directive-effect/block.json +0 -14
  47. package/plugins/interactive-blocks/directive-effect/view.js +0 -59
  48. package/plugins/interactive-blocks/store-afterload/render.php +0 -41
  49. package/plugins/interactive-blocks/store-afterload/view.js +0 -60
  50. package/specs/editor/plugins/__snapshots__/align-hook.test.js.snap +0 -43
  51. package/specs/editor/plugins/__snapshots__/block-directory-add.test.js.snap +0 -3
  52. package/specs/editor/plugins/align-hook.test.js +0 -234
  53. package/specs/editor/plugins/block-directory-add.test.js +0 -205
  54. package/specs/editor/plugins/block-icons.test.js +0 -170
  55. package/specs/editor/plugins/custom-taxonomies.test.js +0 -61
  56. package/specs/editor/various/is-typing.test.js +0 -101
  57. package/specs/editor/various/sidebar-permalink.test.js +0 -53
@@ -1,41 +0,0 @@
1
- <?php
2
- /**
3
- * HTML for testing `afterLoad` callbacks added to the store.
4
- *
5
- * @package gutenberg-test-interactive-blocks
6
- */
7
-
8
- ?>
9
- <div data-wp-interactive>
10
- <h3>Store statuses</h3>
11
- <p data-store-status data-wp-text="state.status1">waiting</p>
12
- <p data-store-status data-wp-text="state.status2">waiting</p>
13
- <p data-store-status data-wp-text="state.status3">waiting</p>
14
- <p data-store-status data-wp-text="state.status4">waiting</p>
15
-
16
- <h3><code>afterLoad</code> executions</h3>
17
- <p>All stores ready:&#20;
18
- <span
19
- data-testid="all-stores-ready"
20
- data-wp-text="state.allStoresReady">
21
- >waiting</span>
22
- </p>
23
- <p>vDOM ready:&#20;
24
- <span
25
- data-testid="vdom-ready"
26
- data-wp-text="state.vdomReady">
27
- >waiting</span>
28
- </p>
29
- <p><code>afterLoad</code> exec times:&#20;
30
- <span
31
- data-testid="after-load-exec-times"
32
- data-wp-text="state.execTimes.afterLoad">
33
- >0</span>
34
- </p>
35
- <p><code>sharedAfterLoad</code> exec times:&#20;
36
- <span
37
- data-testid="shared-after-load-exec-times"
38
- data-wp-text="state.execTimes.sharedAfterLoad">
39
- >0</span>
40
- </p>
41
- </div>
@@ -1,60 +0,0 @@
1
- ( ( { wp } ) => {
2
- /**
3
- * WordPress dependencies
4
- */
5
- const { store } = wp.interactivity;
6
-
7
- const afterLoad = ({ state }) => {
8
- // Check the state is correctly initialized.
9
- const { status1, status2, status3, status4 } = state;
10
- state.allStoresReady =
11
- [ status1, status2, status3, status4 ]
12
- .every( ( t ) => t === 'ready' )
13
- .toString();
14
-
15
- // Check the HTML has been processed as well.
16
- const selector = '[data-store-status]';
17
- state.vdomReady =
18
- document.querySelector( selector ) &&
19
- Array.from(
20
- document.querySelectorAll( selector )
21
- ).every( ( el ) => el.textContent === 'ready' ).toString();
22
-
23
- // Increment exec times everytime this function runs.
24
- state.execTimes.afterLoad += 1;
25
- }
26
-
27
- const sharedAfterLoad = ({ state }) => {
28
- // Increment exec times everytime this function runs.
29
- state.execTimes.sharedAfterLoad += 1;
30
- }
31
-
32
- // Case 1: without afterload callback
33
- store( {
34
- state: { status1: 'ready' },
35
- } );
36
-
37
- // Case 2: non-shared afterload callback
38
- store( {
39
- state: {
40
- status2: 'ready',
41
- allStoresReady: false,
42
- vdomReady: false,
43
- execTimes: { afterLoad: 0 },
44
- },
45
- }, { afterLoad } );
46
-
47
- // Case 3: shared afterload callback
48
- store( {
49
- state: {
50
- status3: 'ready',
51
- execTimes: { sharedAfterLoad: 0 },
52
- },
53
- }, { afterLoad: sharedAfterLoad } );
54
- store( {
55
- state: {
56
- status4: 'ready',
57
- execTimes: { sharedAfterLoad: 0 },
58
- },
59
- }, { afterLoad: sharedAfterLoad } );
60
- } )( window );
@@ -1,43 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`Align Hook Works As Expected Block with align array Correctly applies the selected alignment and correctly removes the alignment 1`] = `
4
- "<!-- wp:test/test-align-array {"align":"center"} -->
5
- <div style="outline:1px solid gray;padding:5px" class="wp-block-test-test-align-array aligncenter">Test Align Hook</div>
6
- <!-- /wp:test/test-align-array -->"
7
- `;
8
-
9
- exports[`Align Hook Works As Expected Block with align array Correctly applies the selected alignment and correctly removes the alignment 2`] = `
10
- "<!-- wp:test/test-align-array -->
11
- <div style="outline:1px solid gray;padding:5px" class="wp-block-test-test-align-array">Test Align Hook</div>
12
- <!-- /wp:test/test-align-array -->"
13
- `;
14
-
15
- exports[`Align Hook Works As Expected Block with align true Correctly applies the selected alignment and correctly removes the alignment 1`] = `
16
- "<!-- wp:test/test-align-true {"align":"right"} -->
17
- <div style="outline:1px solid gray;padding:5px" class="wp-block-test-test-align-true alignright">Test Align Hook</div>
18
- <!-- /wp:test/test-align-true -->"
19
- `;
20
-
21
- exports[`Align Hook Works As Expected Block with align true Correctly applies the selected alignment and correctly removes the alignment 2`] = `
22
- "<!-- wp:test/test-align-true -->
23
- <div style="outline:1px solid gray;padding:5px" class="wp-block-test-test-align-true">Test Align Hook</div>
24
- <!-- /wp:test/test-align-true -->"
25
- `;
26
-
27
- exports[`Align Hook Works As Expected Block with default align Correctly applies the selected alignment and correctly removes the alignment 1`] = `
28
- "<!-- wp:test/test-default-align {"align":"center"} -->
29
- <div style="outline:1px solid gray;padding:5px" class="wp-block-test-test-default-align aligncenter">Test Align Hook</div>
30
- <!-- /wp:test/test-default-align -->"
31
- `;
32
-
33
- exports[`Align Hook Works As Expected Block with default align Correctly applies the selected alignment and correctly removes the alignment 2`] = `
34
- "<!-- wp:test/test-default-align {"align":""} -->
35
- <div style="outline:1px solid gray;padding:5px" class="wp-block-test-test-default-align">Test Align Hook</div>
36
- <!-- /wp:test/test-default-align -->"
37
- `;
38
-
39
- exports[`Align Hook Works As Expected Block with no alignment set Does not save any alignment related attribute or class 1`] = `
40
- "<!-- wp:test/test-no-alignment-set -->
41
- <div style="outline:1px solid gray;padding:5px" class="wp-block-test-test-no-alignment-set">Test Align Hook</div>
42
- <!-- /wp:test/test-no-alignment-set -->"
43
- `;
@@ -1,3 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`adding blocks from block directory Should be able to add (the first) block. 1`] = `"<!-- wp:block-directory-test-block/main-block /-->"`;
@@ -1,234 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import {
5
- activatePlugin,
6
- createNewPost,
7
- deactivatePlugin,
8
- getAllBlocks,
9
- getEditedPostContent,
10
- insertBlock,
11
- selectBlockByClientId,
12
- setPostContent,
13
- clickBlockToolbarButton,
14
- } from '@wordpress/e2e-test-utils';
15
-
16
- const alignLabels = {
17
- none: 'None',
18
- left: 'Align left',
19
- center: 'Align center',
20
- right: 'Align right',
21
- wide: 'Wide width',
22
- full: 'Full width',
23
- };
24
-
25
- /**
26
- * Helper function to get the `labels` of align control. It actually evaluates the
27
- * basic label of the button without the `info` text node if exists.
28
- *
29
- * @param {Object} options Options for the util function
30
- * @param {boolean} [options.getActiveButtonLabels=false] Flag for returning the active buttons labels only.
31
- * @return {string[]} The matched labels.
32
- */
33
- const getAlignmentToolbarLabels = async ( {
34
- getActiveButtonLabels = false,
35
- } = {} ) => {
36
- const selector = `.components-dropdown-menu__menu button${
37
- getActiveButtonLabels ? '.is-active' : ''
38
- } .components-menu-item__item`;
39
- return page.evaluate( ( _selector ) => {
40
- return (
41
- Array.from( document.querySelectorAll( _selector ) )
42
- /**
43
- * We neede this for now because conditionally there could be two nodes
44
- * with the same class(). This should be removed when the following
45
- * issue is resolved.
46
- *
47
- * @see https://github.com/WordPress/gutenberg/issues/34838
48
- */
49
- .filter( ( contentNode ) => ! contentNode.childElementCount )
50
- .map( ( contentNode ) => {
51
- return contentNode.innerText;
52
- } )
53
- );
54
- }, selector );
55
- };
56
-
57
- const expectActiveButtonLabelToBe = async ( expected ) => {
58
- await clickBlockToolbarButton( 'Align' );
59
- const activeButtonLabels = await getAlignmentToolbarLabels( {
60
- getActiveButtonLabels: true,
61
- } );
62
- expect( activeButtonLabels ).toHaveLength( 1 );
63
- expect( activeButtonLabels[ 0 ] ).toEqual( expected );
64
- };
65
-
66
- const createShowsTheExpectedButtonsTest = ( blockName, buttonLabels ) => {
67
- it( 'Shows the expected buttons on the alignment toolbar', async () => {
68
- await insertBlock( blockName );
69
- await clickBlockToolbarButton( 'Align' );
70
- expect( await getAlignmentToolbarLabels() ).toEqual(
71
- expect.arrayContaining( buttonLabels )
72
- );
73
- } );
74
- };
75
-
76
- const createAppliesNoneAlignmentByDefaultTest = ( blockName ) => {
77
- it( 'applies none alignment by default', async () => {
78
- await insertBlock( blockName );
79
- await expectActiveButtonLabelToBe( alignLabels.none );
80
- } );
81
- };
82
-
83
- const verifyMarkupIsValid = async ( htmlMarkup ) => {
84
- await setPostContent( htmlMarkup );
85
- const blocks = await getAllBlocks();
86
- expect( blocks ).toHaveLength( 1 );
87
- expect( blocks[ 0 ].isValid ).toBeTruthy();
88
- };
89
-
90
- const createCorrectlyAppliesAndRemovesAlignmentTest = (
91
- blockName,
92
- alignment
93
- ) => {
94
- it( 'Correctly applies the selected alignment and correctly removes the alignment', async () => {
95
- const BUTTON_XPATH = `//button[contains(@class,'components-dropdown-menu__menu-item')]//span[contains(text(), '${ alignLabels[ alignment ] }')]`;
96
-
97
- // Set the specified alignment.
98
- await insertBlock( blockName );
99
- await clickBlockToolbarButton( 'Align' );
100
- await ( await page.$x( BUTTON_XPATH ) )[ 0 ].click();
101
-
102
- // Verify the button of the specified alignment is pressed.
103
- await expectActiveButtonLabelToBe( alignLabels[ alignment ] );
104
-
105
- let htmlMarkup = await getEditedPostContent();
106
-
107
- // Verify the markup of the selected alignment was generated.
108
- expect( htmlMarkup ).toMatchSnapshot();
109
-
110
- // Verify the markup can be correctly parsed.
111
- await verifyMarkupIsValid( htmlMarkup );
112
-
113
- await selectBlockByClientId( ( await getAllBlocks() )[ 0 ].clientId );
114
-
115
- // Remove the alignment.
116
- await clickBlockToolbarButton( 'Align' );
117
- await ( await page.$x( BUTTON_XPATH ) )[ 0 ].click();
118
-
119
- // Verify 'none' alignment button is in pressed state.
120
- await expectActiveButtonLabelToBe( alignLabels.none );
121
-
122
- // Verify alignment markup was removed from the block.
123
- htmlMarkup = await getEditedPostContent();
124
- expect( htmlMarkup ).toMatchSnapshot();
125
-
126
- // verify the markup when no alignment is set is valid
127
- await verifyMarkupIsValid( htmlMarkup );
128
-
129
- await selectBlockByClientId( ( await getAllBlocks() )[ 0 ].clientId );
130
-
131
- // Verify alignment `none` button is in pressed state after parsing the block.
132
- await expectActiveButtonLabelToBe( alignLabels.none );
133
- } );
134
- };
135
-
136
- describe( 'Align Hook Works As Expected', () => {
137
- beforeAll( async () => {
138
- await activatePlugin( 'gutenberg-test-align-hook' );
139
- } );
140
-
141
- beforeEach( async () => {
142
- await createNewPost();
143
- } );
144
-
145
- afterAll( async () => {
146
- await deactivatePlugin( 'gutenberg-test-align-hook' );
147
- } );
148
-
149
- describe( 'Block with no alignment set', () => {
150
- const BLOCK_NAME = 'Test No Alignment Set';
151
- it( 'Shows no alignment buttons on the alignment toolbar', async () => {
152
- await insertBlock( BLOCK_NAME );
153
- const CHANGE_ALIGNMENT_BUTTON_SELECTOR =
154
- '.block-editor-block-toolbar .components-dropdown-menu__toggle[aria-label="Align"]';
155
- const changeAlignmentButton = await page.$(
156
- CHANGE_ALIGNMENT_BUTTON_SELECTOR
157
- );
158
- expect( changeAlignmentButton ).toBe( null );
159
- } );
160
-
161
- it( 'Does not save any alignment related attribute or class', async () => {
162
- await insertBlock( BLOCK_NAME );
163
- expect( await getEditedPostContent() ).toMatchSnapshot();
164
- } );
165
- } );
166
-
167
- describe( 'Block with align true', () => {
168
- const BLOCK_NAME = 'Test Align True';
169
-
170
- createShowsTheExpectedButtonsTest(
171
- BLOCK_NAME,
172
- Object.values( alignLabels )
173
- );
174
-
175
- createAppliesNoneAlignmentByDefaultTest( BLOCK_NAME );
176
-
177
- createCorrectlyAppliesAndRemovesAlignmentTest( BLOCK_NAME, 'right' );
178
- } );
179
-
180
- describe( 'Block with align array', () => {
181
- const BLOCK_NAME = 'Test Align Array';
182
-
183
- createShowsTheExpectedButtonsTest( BLOCK_NAME, [
184
- alignLabels.none,
185
- alignLabels.left,
186
- alignLabels.center,
187
- ] );
188
-
189
- createAppliesNoneAlignmentByDefaultTest( BLOCK_NAME );
190
-
191
- createCorrectlyAppliesAndRemovesAlignmentTest( BLOCK_NAME, 'center' );
192
- } );
193
-
194
- describe( 'Block with default align', () => {
195
- const BLOCK_NAME = 'Test Default Align';
196
- const SELECTED_ALIGNMENT_CONTROL_SELECTOR =
197
- '//div[contains(@class, "components-dropdown-menu__menu")]//button[contains(@class, "is-active")]/span[text()="Align right"]';
198
- createShowsTheExpectedButtonsTest(
199
- BLOCK_NAME,
200
- Object.values( alignLabels )
201
- );
202
-
203
- it( 'Applies the selected alignment by default', async () => {
204
- await insertBlock( BLOCK_NAME );
205
- // Verify the correct alignment button is pressed.
206
- await clickBlockToolbarButton( 'Align' );
207
- const selectedAlignmentControls = await page.$x(
208
- SELECTED_ALIGNMENT_CONTROL_SELECTOR
209
- );
210
- expect( selectedAlignmentControls ).toHaveLength( 1 );
211
- } );
212
-
213
- it( 'The default markup does not contain the alignment attribute but contains the alignment class', async () => {
214
- await insertBlock( BLOCK_NAME );
215
- const markup = await getEditedPostContent();
216
- expect( markup ).not.toContain( '"align":"right"' );
217
- expect( markup ).toContain( 'alignright' );
218
- } );
219
-
220
- it( 'Can remove the default alignment and the align attribute equals none but alignnone class is not applied', async () => {
221
- await insertBlock( BLOCK_NAME );
222
- // Remove the alignment.
223
- await clickBlockToolbarButton( 'Align' );
224
- const [ selectedAlignmentControl ] = await page.$x(
225
- SELECTED_ALIGNMENT_CONTROL_SELECTOR
226
- );
227
- await selectedAlignmentControl.click();
228
- const markup = await getEditedPostContent();
229
- expect( markup ).toContain( '"align":""' );
230
- } );
231
-
232
- createCorrectlyAppliesAndRemovesAlignmentTest( BLOCK_NAME, 'center' );
233
- } );
234
- } );
@@ -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
- } );