@wordpress/e2e-tests 8.8.4 → 8.8.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/e2e-tests",
3
- "version": "8.8.4",
3
+ "version": "8.8.6",
4
4
  "description": "End-To-End (E2E) tests for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -25,8 +25,8 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@wordpress/e2e-test-utils": "^11.8.2",
28
- "@wordpress/interactivity": "^6.8.2",
29
- "@wordpress/interactivity-router": "^2.8.3",
28
+ "@wordpress/interactivity": "^6.8.3",
29
+ "@wordpress/interactivity-router": "^2.8.4",
30
30
  "@wordpress/jest-console": "^8.8.1",
31
31
  "@wordpress/jest-puppeteer-axe": "^7.8.1",
32
32
  "@wordpress/scripts": "^30.0.4",
@@ -47,5 +47,5 @@
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  },
50
- "gitHead": "6187079697e13c3292eb098d6338523a6676c6e8"
50
+ "gitHead": "21b3c2e9abda74edab42455041edc6e82fccc388"
51
51
  }
@@ -0,0 +1,49 @@
1
+ const { registerBlockBindingsSource } = wp.blocks;
2
+ const { fieldsList } = window.testingBindings || {};
3
+
4
+ const getValues = ( { bindings } ) => {
5
+ const newValues = {};
6
+ for ( const [ attributeName, source ] of Object.entries( bindings ) ) {
7
+ newValues[ attributeName ] = fieldsList[ source.args.key ]?.value;
8
+ }
9
+ return newValues;
10
+ };
11
+ const setValues = ( { dispatch, bindings } ) => {
12
+ Object.values( bindings ).forEach( ( { args, newValue } ) => {
13
+ // Example of what could be done.
14
+ dispatch( 'core' ).editEntityRecord( 'postType', 'post', 1, {
15
+ meta: { [ args?.key ]: newValue },
16
+ } );
17
+ } );
18
+ };
19
+
20
+ registerBlockBindingsSource( {
21
+ name: 'testing/complete-source',
22
+ label: 'Complete Source',
23
+ getValues,
24
+ setValues,
25
+ canUserEditValue: () => true,
26
+ getFieldsList: () => fieldsList,
27
+ } );
28
+
29
+ registerBlockBindingsSource( {
30
+ name: 'testing/can-user-edit-false',
31
+ label: 'Can User Edit: False',
32
+ getValues,
33
+ setValues,
34
+ canUserEditValue: () => false,
35
+ } );
36
+
37
+ registerBlockBindingsSource( {
38
+ name: 'testing/can-user-edit-undefined',
39
+ label: 'Can User Edit: Undefined',
40
+ getValues,
41
+ setValues,
42
+ } );
43
+
44
+ registerBlockBindingsSource( {
45
+ name: 'testing/set-values-undefined',
46
+ label: 'Set Values: Undefined',
47
+ getValues,
48
+ canUserEditValue: () => true,
49
+ } );
@@ -8,67 +8,158 @@
8
8
  */
9
9
 
10
10
  /**
11
- * Register custom fields and custom block bindings sources.
12
- */
11
+ * Code necessary for testing block bindings:
12
+ * - Enqueues a custom script to register sources in the client.
13
+ * - Registers sources in the server.
14
+ * - Registers a custom post type and custom fields.
15
+ */
13
16
  function gutenberg_test_block_bindings_registration() {
17
+ // Define fields list.
18
+ $upload_dir = wp_upload_dir();
19
+ $testing_url = $upload_dir['url'] . '/1024x768_e2e_test_image_size.jpeg';
20
+ $fields_list = array(
21
+ 'text_field' => array(
22
+ 'label' => 'Text Field Label',
23
+ 'value' => 'Text Field Value',
24
+ ),
25
+ 'url_field' => array(
26
+ 'label' => 'URL Field Label',
27
+ 'value' => $testing_url,
28
+ ),
29
+ 'empty_field' => array(
30
+ 'label' => 'Empty Field Label',
31
+ 'value' => '',
32
+ ),
33
+ );
34
+
35
+ // Enqueue a custom script for the plugin.
36
+ wp_enqueue_script(
37
+ 'gutenberg-test-block-bindings',
38
+ plugins_url( 'block-bindings/index.js', __FILE__ ),
39
+ array(
40
+ 'wp-blocks',
41
+ 'wp-private-apis',
42
+ ),
43
+ filemtime( plugin_dir_path( __FILE__ ) . 'block-bindings/index.js' ),
44
+ true
45
+ );
46
+
47
+ // Pass data to the script.
48
+ wp_localize_script(
49
+ 'gutenberg-test-block-bindings',
50
+ 'testingBindings',
51
+ array(
52
+ 'fieldsList' => $fields_list,
53
+ )
54
+ );
55
+
14
56
  // Register custom block bindings sources.
15
57
  register_block_bindings_source(
16
- 'core/server-source',
58
+ 'testing/complete-source',
59
+ array(
60
+ 'label' => 'Complete Source',
61
+ 'get_value_callback' => function ( $source_args ) use ( $fields_list ) {
62
+ if ( ! isset( $source_args['key'] ) || ! isset( $fields_list[ $source_args['key'] ] ) ) {
63
+ return null;
64
+ }
65
+ return $fields_list[ $source_args['key'] ]['value']; },
66
+ )
67
+ );
68
+ register_block_bindings_source(
69
+ 'testing/server-only-source',
17
70
  array(
18
71
  'label' => 'Server Source',
19
72
  'get_value_callback' => function () {},
20
73
  )
21
74
  );
22
75
 
23
- // Register custom fields.
76
+ // Register "movie" custom post type.
77
+ register_post_type(
78
+ 'movie',
79
+ array(
80
+ 'label' => 'Movie',
81
+ 'public' => true,
82
+ 'supports' => array( 'title', 'editor', 'comments', 'revisions', 'trackbacks', 'author', 'excerpt', 'page-attributes', 'thumbnail', 'custom-fields', 'post-formats' ),
83
+ 'has_archive' => true,
84
+ 'show_in_rest' => true,
85
+ )
86
+ );
87
+
88
+ // Register global custom fields.
24
89
  register_meta(
25
90
  'post',
26
91
  'text_custom_field',
27
92
  array(
93
+ 'default' => 'Value of the text custom field',
28
94
  'show_in_rest' => true,
29
- 'type' => 'string',
30
95
  'single' => true,
31
- 'default' => 'Value of the text custom field',
96
+ 'type' => 'string',
32
97
  )
33
98
  );
34
99
  register_meta(
35
100
  'post',
36
101
  'url_custom_field',
37
102
  array(
103
+ 'default' => '#url-custom-field',
38
104
  'show_in_rest' => true,
39
- 'type' => 'string',
40
105
  'single' => true,
41
- 'default' => '#url-custom-field',
106
+ 'type' => 'string',
42
107
  )
43
108
  );
109
+ // Register CPT custom fields.
44
110
  register_meta(
45
111
  'post',
46
- 'empty_field',
112
+ 'movie_field',
47
113
  array(
48
- 'show_in_rest' => true,
49
- 'type' => 'string',
50
- 'single' => true,
51
- 'default' => '',
114
+ 'label' => 'Movie field label',
115
+ 'default' => 'Movie field default value',
116
+ 'object_subtype' => 'movie',
117
+ 'show_in_rest' => true,
118
+ 'single' => true,
119
+ 'type' => 'string',
120
+ )
121
+ );
122
+ register_meta(
123
+ 'post',
124
+ 'field_with_only_label',
125
+ array(
126
+ 'label' => 'Field with only label',
127
+ 'object_subtype' => 'movie',
128
+ 'show_in_rest' => true,
129
+ 'single' => true,
130
+ 'type' => 'string',
131
+ )
132
+ );
133
+ register_meta(
134
+ 'post',
135
+ 'field_without_label_or_default',
136
+ array(
137
+ 'object_subtype' => 'movie',
138
+ 'show_in_rest' => true,
139
+ 'single' => true,
140
+ 'type' => 'string',
52
141
  )
53
142
  );
54
143
  register_meta(
55
144
  'post',
56
145
  '_protected_field',
57
146
  array(
58
- 'type' => 'string',
59
- 'show_in_rest' => true,
60
- 'single' => true,
61
- 'default' => 'protected field value',
147
+ 'default' => 'Protected field value',
148
+ 'object_subtype' => 'movie',
149
+ 'show_in_rest' => true,
150
+ 'single' => true,
151
+ 'type' => 'string',
62
152
  )
63
153
  );
64
154
  register_meta(
65
155
  'post',
66
156
  'show_in_rest_false_field',
67
157
  array(
68
- 'show_in_rest' => false,
69
- 'type' => 'string',
70
- 'single' => true,
71
- 'default' => 'show_in_rest false field value',
158
+ 'default' => 'show_in_rest false field value',
159
+ 'object_subtype' => 'movie',
160
+ 'show_in_rest' => false,
161
+ 'single' => true,
162
+ 'type' => 'string',
72
163
  )
73
164
  );
74
165
  }