@wordpress/editor 14.35.1-next.16d95556a.0 → 14.36.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 +6 -0
- package/build/bindings/post-data.js +15 -15
- package/build/bindings/post-data.js.map +2 -2
- package/build/bindings/term-data.js +97 -95
- package/build/bindings/term-data.js.map +2 -2
- package/build/components/collab-sidebar/comments.js +69 -18
- package/build/components/collab-sidebar/comments.js.map +2 -2
- package/build/components/collab-sidebar/hooks.js +9 -1
- package/build/components/collab-sidebar/hooks.js.map +2 -2
- package/build/components/global-styles/index.js +8 -8
- package/build/components/global-styles/index.js.map +2 -2
- package/build/components/post-featured-image/index.js +1 -32
- package/build/components/post-featured-image/index.js.map +3 -3
- package/build/components/post-schedule/panel.js +1 -7
- package/build/components/post-schedule/panel.js.map +2 -2
- package/build/components/post-status/index.js +1 -7
- package/build/components/post-status/index.js.map +2 -2
- package/build/components/post-template/block-theme.js +1 -1
- package/build/components/post-template/block-theme.js.map +2 -2
- package/build/components/post-template/hooks.js +1 -1
- package/build/components/post-template/hooks.js.map +2 -2
- package/build/components/provider/index.js +3 -1
- package/build/components/provider/index.js.map +2 -2
- package/build/components/provider/use-block-editor-settings.js +9 -1
- package/build/components/provider/use-block-editor-settings.js.map +2 -2
- package/build/components/visual-editor/index.js +1 -7
- package/build/components/visual-editor/index.js.map +2 -2
- package/build/components/visual-editor/use-edit-content-only-section-exit.js +5 -6
- package/build/components/visual-editor/use-edit-content-only-section-exit.js.map +2 -2
- package/build/dataviews/store/private-actions.js +5 -1
- package/build/dataviews/store/private-actions.js.map +2 -2
- package/build/hooks/media-upload.js +89 -6
- package/build/hooks/media-upload.js.map +3 -3
- package/build/hooks/template-part-navigation-edit-button.js +8 -11
- package/build/hooks/template-part-navigation-edit-button.js.map +3 -3
- package/build/store/actions.js +1 -1
- package/build/store/actions.js.map +2 -2
- package/build/store/constants.js +8 -0
- package/build/store/constants.js.map +2 -2
- package/build-module/bindings/post-data.js +15 -15
- package/build-module/bindings/post-data.js.map +2 -2
- package/build-module/bindings/term-data.js +93 -95
- package/build-module/bindings/term-data.js.map +2 -2
- package/build-module/components/collab-sidebar/comments.js +69 -18
- package/build-module/components/collab-sidebar/comments.js.map +2 -2
- package/build-module/components/collab-sidebar/hooks.js +9 -1
- package/build-module/components/collab-sidebar/hooks.js.map +2 -2
- package/build-module/components/global-styles/index.js +8 -8
- package/build-module/components/global-styles/index.js.map +2 -2
- package/build-module/components/post-featured-image/index.js +3 -35
- package/build-module/components/post-featured-image/index.js.map +2 -2
- package/build-module/components/post-schedule/panel.js +1 -12
- package/build-module/components/post-schedule/panel.js.map +2 -2
- package/build-module/components/post-status/index.js +1 -12
- package/build-module/components/post-status/index.js.map +2 -2
- package/build-module/components/post-template/block-theme.js +1 -1
- package/build-module/components/post-template/block-theme.js.map +2 -2
- package/build-module/components/post-template/hooks.js +1 -1
- package/build-module/components/post-template/hooks.js.map +2 -2
- package/build-module/components/provider/index.js +3 -1
- package/build-module/components/provider/index.js.map +2 -2
- package/build-module/components/provider/use-block-editor-settings.js +9 -1
- package/build-module/components/provider/use-block-editor-settings.js.map +2 -2
- package/build-module/components/visual-editor/index.js +2 -7
- package/build-module/components/visual-editor/index.js.map +2 -2
- package/build-module/components/visual-editor/use-edit-content-only-section-exit.js +5 -6
- package/build-module/components/visual-editor/use-edit-content-only-section-exit.js.map +2 -2
- package/build-module/dataviews/store/private-actions.js +5 -1
- package/build-module/dataviews/store/private-actions.js.map +2 -2
- package/build-module/hooks/media-upload.js +67 -6
- package/build-module/hooks/media-upload.js.map +2 -2
- package/build-module/hooks/template-part-navigation-edit-button.js +10 -17
- package/build-module/hooks/template-part-navigation-edit-button.js.map +2 -2
- package/build-module/store/actions.js +1 -1
- package/build-module/store/actions.js.map +2 -2
- package/build-module/store/constants.js +7 -0
- package/build-module/store/constants.js.map +2 -2
- package/build-style/style-rtl.css +309 -40
- package/build-style/style.css +309 -40
- package/build-types/bindings/post-data.d.ts +2 -1
- package/build-types/bindings/term-data.d.ts +86 -8
- package/build-types/bindings/term-data.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/comments.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/hooks.d.ts.map +1 -1
- package/build-types/components/global-styles/index.d.ts.map +1 -1
- package/build-types/components/post-schedule/panel.d.ts.map +1 -1
- package/build-types/components/post-status/index.d.ts.map +1 -1
- package/build-types/components/post-template/block-theme.d.ts.map +1 -1
- package/build-types/components/provider/index.d.ts.map +1 -1
- package/build-types/components/provider/use-block-editor-settings.d.ts.map +1 -1
- package/build-types/components/visual-editor/index.d.ts.map +1 -1
- package/build-types/components/visual-editor/use-edit-content-only-section-exit.d.ts.map +1 -1
- package/build-types/dataviews/store/private-actions.d.ts +5 -0
- package/build-types/dataviews/store/private-actions.d.ts.map +1 -1
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/store/constants.d.ts +1 -0
- package/build-types/store/constants.d.ts.map +1 -1
- package/package.json +40 -40
- package/src/bindings/post-data.js +21 -20
- package/src/bindings/term-data.js +124 -151
- package/src/bindings/test/post-data.js +210 -0
- package/src/bindings/test/term-data.js +406 -0
- package/src/components/collab-sidebar/comments.js +90 -24
- package/src/components/collab-sidebar/hooks.js +12 -1
- package/src/components/global-styles/index.js +8 -9
- package/src/components/global-styles-sidebar/style.scss +7 -0
- package/src/components/post-featured-image/index.js +1 -44
- package/src/components/post-schedule/panel.js +1 -13
- package/src/components/post-status/index.js +1 -13
- package/src/components/post-template/block-theme.js +4 -1
- package/src/components/post-template/hooks.js +1 -1
- package/src/components/provider/index.js +7 -2
- package/src/components/provider/use-block-editor-settings.js +8 -0
- package/src/components/visual-editor/index.js +1 -6
- package/src/components/visual-editor/use-edit-content-only-section-exit.js +9 -10
- package/src/dataviews/store/private-actions.ts +17 -1
- package/src/hooks/media-upload.js +75 -7
- package/src/hooks/template-part-navigation-edit-button.js +4 -15
- package/src/store/actions.js +2 -0
- package/src/store/constants.ts +6 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import postDataBindings from '../post-data';
|
|
10
|
+
|
|
11
|
+
describe( 'post-data bindings', () => {
|
|
12
|
+
describe( 'getValues', () => {
|
|
13
|
+
describe( 'for regular blocks using block context', () => {
|
|
14
|
+
let select;
|
|
15
|
+
beforeAll( () => {
|
|
16
|
+
select = ( store ) => {
|
|
17
|
+
if ( store === blockEditorStore ) {
|
|
18
|
+
return {
|
|
19
|
+
getBlockName: ( clientId ) =>
|
|
20
|
+
clientId === '123abc456'
|
|
21
|
+
? 'core/post-date'
|
|
22
|
+
: undefined,
|
|
23
|
+
getBlockAttributes: () => ( {} ),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
getEditedEntityRecord: ( kind, name, recordId ) =>
|
|
28
|
+
name === 'post' && recordId === 123
|
|
29
|
+
? {
|
|
30
|
+
date: '2024-03-02 00:00:00',
|
|
31
|
+
modified: '2025-06-07 00:00:00',
|
|
32
|
+
link: 'https://example.com/post',
|
|
33
|
+
unknown: 'Unknown field value',
|
|
34
|
+
}
|
|
35
|
+
: false,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
} );
|
|
39
|
+
|
|
40
|
+
it( 'should return entity field values when they exist, and field name for unknown fields', () => {
|
|
41
|
+
const values = postDataBindings.getValues( {
|
|
42
|
+
select,
|
|
43
|
+
context: { postId: 123, postType: 'post' },
|
|
44
|
+
bindings: {
|
|
45
|
+
datetime: {
|
|
46
|
+
source: 'core/post-date',
|
|
47
|
+
args: { field: 'date' },
|
|
48
|
+
},
|
|
49
|
+
modified: {
|
|
50
|
+
source: 'core/post-date',
|
|
51
|
+
args: { field: 'modified' },
|
|
52
|
+
},
|
|
53
|
+
url: {
|
|
54
|
+
source: 'core/post-date',
|
|
55
|
+
args: { field: 'link' },
|
|
56
|
+
},
|
|
57
|
+
content: {
|
|
58
|
+
source: 'core/post-date',
|
|
59
|
+
args: { field: 'unknown' },
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
clientId: '123abc456',
|
|
63
|
+
} );
|
|
64
|
+
|
|
65
|
+
expect( values ).toStrictEqual( {
|
|
66
|
+
datetime: '2024-03-02 00:00:00',
|
|
67
|
+
modified: '2025-06-07 00:00:00',
|
|
68
|
+
url: 'https://example.com/post',
|
|
69
|
+
content: 'unknown',
|
|
70
|
+
} );
|
|
71
|
+
} );
|
|
72
|
+
|
|
73
|
+
it( 'should fall back to field labels when entity value does not exist, and to field name for unknown fields', () => {
|
|
74
|
+
const values = postDataBindings.getValues( {
|
|
75
|
+
select,
|
|
76
|
+
context: { postId: 456, postType: 'post' },
|
|
77
|
+
bindings: {
|
|
78
|
+
datetime: {
|
|
79
|
+
source: 'core/post-date',
|
|
80
|
+
args: { field: 'date' },
|
|
81
|
+
},
|
|
82
|
+
modified: {
|
|
83
|
+
source: 'core/post-date',
|
|
84
|
+
args: { field: 'modified' },
|
|
85
|
+
},
|
|
86
|
+
url: {
|
|
87
|
+
source: 'core/post-date',
|
|
88
|
+
args: { field: 'link' },
|
|
89
|
+
},
|
|
90
|
+
content: {
|
|
91
|
+
source: 'core/post-date',
|
|
92
|
+
args: { field: 'unknown' },
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
clientId: '123abc456',
|
|
96
|
+
} );
|
|
97
|
+
|
|
98
|
+
expect( values ).toStrictEqual( {
|
|
99
|
+
datetime: 'Post Date',
|
|
100
|
+
modified: 'Post Modified Date',
|
|
101
|
+
url: 'Post Link',
|
|
102
|
+
content: 'unknown',
|
|
103
|
+
} );
|
|
104
|
+
} );
|
|
105
|
+
} );
|
|
106
|
+
|
|
107
|
+
describe( 'for navigation blocks using block attributes', () => {
|
|
108
|
+
it( 'should use block attributes instead of context', () => {
|
|
109
|
+
const select = ( store ) => {
|
|
110
|
+
if ( store === blockEditorStore ) {
|
|
111
|
+
return {
|
|
112
|
+
getBlockName: () => 'core/navigation-link',
|
|
113
|
+
getBlockAttributes: () => ( {
|
|
114
|
+
id: 456,
|
|
115
|
+
type: 'page',
|
|
116
|
+
} ),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
getEditedEntityRecord: ( _kind, type, id ) => {
|
|
121
|
+
if ( type !== 'page' || id !== 456 ) {
|
|
122
|
+
return {};
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
link: 'https://example.com/page',
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const values = postDataBindings.getValues( {
|
|
132
|
+
select,
|
|
133
|
+
context: { postId: 123, postType: 'post' },
|
|
134
|
+
bindings: {
|
|
135
|
+
url: {
|
|
136
|
+
source: 'core/post-date',
|
|
137
|
+
args: { field: 'link' },
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
clientId: '123abc456',
|
|
141
|
+
} );
|
|
142
|
+
|
|
143
|
+
expect( values.url ).toBe( 'https://example.com/page' );
|
|
144
|
+
} );
|
|
145
|
+
} );
|
|
146
|
+
} );
|
|
147
|
+
|
|
148
|
+
describe( 'getFieldsList', () => {
|
|
149
|
+
it( 'should return the list of available post data fields when the Date block is selected, and postId and postType are provided via context', () => {
|
|
150
|
+
const select = () => ( {
|
|
151
|
+
getSelectedBlock: () => ( {
|
|
152
|
+
name: 'core/post-date',
|
|
153
|
+
} ),
|
|
154
|
+
} );
|
|
155
|
+
|
|
156
|
+
const fields = postDataBindings.getFieldsList( {
|
|
157
|
+
context: { postId: 123, postType: 'post' },
|
|
158
|
+
select,
|
|
159
|
+
} );
|
|
160
|
+
|
|
161
|
+
expect( fields ).toEqual( [
|
|
162
|
+
{
|
|
163
|
+
label: 'Post Date',
|
|
164
|
+
args: { field: 'date' },
|
|
165
|
+
type: 'string',
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
label: 'Post Modified Date',
|
|
169
|
+
args: { field: 'modified' },
|
|
170
|
+
type: 'string',
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
label: 'Post Link',
|
|
174
|
+
args: { field: 'link' },
|
|
175
|
+
type: 'string',
|
|
176
|
+
},
|
|
177
|
+
] );
|
|
178
|
+
} );
|
|
179
|
+
|
|
180
|
+
it( 'should return an empty array when the Date block is selected but no postId context is provided', () => {
|
|
181
|
+
const select = () => ( {
|
|
182
|
+
getSelectedBlock: () => ( {
|
|
183
|
+
name: 'core/post-date',
|
|
184
|
+
} ),
|
|
185
|
+
} );
|
|
186
|
+
|
|
187
|
+
const fields = postDataBindings.getFieldsList( {
|
|
188
|
+
context: { postType: 'post' },
|
|
189
|
+
select,
|
|
190
|
+
} );
|
|
191
|
+
|
|
192
|
+
expect( fields ).toEqual( [] );
|
|
193
|
+
} );
|
|
194
|
+
|
|
195
|
+
it( 'should return an empty array when any other block than the Date block is selected', () => {
|
|
196
|
+
const select = () => ( {
|
|
197
|
+
getSelectedBlock: () => ( {
|
|
198
|
+
name: 'core/paragraph',
|
|
199
|
+
} ),
|
|
200
|
+
} );
|
|
201
|
+
|
|
202
|
+
const fields = postDataBindings.getFieldsList( {
|
|
203
|
+
context: { postId: 123, postType: 'post' },
|
|
204
|
+
select,
|
|
205
|
+
} );
|
|
206
|
+
|
|
207
|
+
expect( fields ).toEqual( [] );
|
|
208
|
+
} );
|
|
209
|
+
} );
|
|
210
|
+
} );
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
5
|
+
import { store as coreDataStore } from '@wordpress/core-data';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { default as termDataBindings, termDataFields } from '../term-data';
|
|
11
|
+
|
|
12
|
+
describe( 'term-data bindings', () => {
|
|
13
|
+
const bindings = {
|
|
14
|
+
id: {
|
|
15
|
+
source: 'core/term-data',
|
|
16
|
+
args: { field: 'id' },
|
|
17
|
+
},
|
|
18
|
+
name: {
|
|
19
|
+
source: 'core/term-data',
|
|
20
|
+
args: { field: 'name' },
|
|
21
|
+
},
|
|
22
|
+
slug: {
|
|
23
|
+
source: 'core/term-data',
|
|
24
|
+
args: { field: 'slug' },
|
|
25
|
+
},
|
|
26
|
+
link: {
|
|
27
|
+
source: 'core/term-data',
|
|
28
|
+
args: { field: 'link' },
|
|
29
|
+
},
|
|
30
|
+
description: {
|
|
31
|
+
source: 'core/term-data',
|
|
32
|
+
args: { field: 'description' },
|
|
33
|
+
},
|
|
34
|
+
parent: {
|
|
35
|
+
source: 'core/term-data',
|
|
36
|
+
args: { field: 'parent' },
|
|
37
|
+
},
|
|
38
|
+
count: {
|
|
39
|
+
source: 'core/term-data',
|
|
40
|
+
args: { field: 'count' },
|
|
41
|
+
},
|
|
42
|
+
content: {
|
|
43
|
+
source: 'core/term-data',
|
|
44
|
+
args: { field: 'unknown' },
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const getEntityRecordMock = ( kind, taxonomy, termId ) => {
|
|
49
|
+
if (
|
|
50
|
+
kind === 'taxonomy' &&
|
|
51
|
+
taxonomy === 'category' &&
|
|
52
|
+
termId === 123
|
|
53
|
+
) {
|
|
54
|
+
return {
|
|
55
|
+
id: 123,
|
|
56
|
+
name: 'Technology',
|
|
57
|
+
slug: 'technology',
|
|
58
|
+
link: 'https://example.com/category/technology',
|
|
59
|
+
parent: 0,
|
|
60
|
+
count: 42,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
describe( 'getValues', () => {
|
|
67
|
+
describe( 'for regular blocks using block context', () => {
|
|
68
|
+
describe( 'when termId and taxonomy are provided in context', () => {
|
|
69
|
+
const select = ( store ) => {
|
|
70
|
+
if ( store === blockEditorStore ) {
|
|
71
|
+
return {
|
|
72
|
+
getBlockName: ( clientId ) =>
|
|
73
|
+
clientId === '123abc456'
|
|
74
|
+
? 'core/paragraph'
|
|
75
|
+
: undefined,
|
|
76
|
+
getBlockAttributes: () => ( {} ),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if ( store === coreDataStore ) {
|
|
80
|
+
return {
|
|
81
|
+
getEntityRecord: getEntityRecordMock,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
it( 'should return entity field values when they exist, fall back to field label, and to field name for unknown fields', () => {
|
|
87
|
+
const values = termDataBindings.getValues( {
|
|
88
|
+
select,
|
|
89
|
+
context: {
|
|
90
|
+
taxonomy: 'category',
|
|
91
|
+
termId: 123,
|
|
92
|
+
},
|
|
93
|
+
bindings,
|
|
94
|
+
clientId: '123abc456',
|
|
95
|
+
} );
|
|
96
|
+
|
|
97
|
+
expect( values ).toStrictEqual( {
|
|
98
|
+
id: 123,
|
|
99
|
+
name: 'Technology',
|
|
100
|
+
slug: 'technology',
|
|
101
|
+
link: 'https://example.com/category/technology',
|
|
102
|
+
description: 'Description',
|
|
103
|
+
parent: 0,
|
|
104
|
+
count: '(42)',
|
|
105
|
+
content: 'unknown',
|
|
106
|
+
} );
|
|
107
|
+
} );
|
|
108
|
+
|
|
109
|
+
it( 'should fall back to field label when entity does not exist, and to field name for unknown fields', () => {
|
|
110
|
+
const values = termDataBindings.getValues( {
|
|
111
|
+
select,
|
|
112
|
+
context: {
|
|
113
|
+
taxonomy: 'category',
|
|
114
|
+
termId: 456,
|
|
115
|
+
},
|
|
116
|
+
bindings,
|
|
117
|
+
clientId: '123abc456',
|
|
118
|
+
} );
|
|
119
|
+
|
|
120
|
+
expect( values ).toStrictEqual( {
|
|
121
|
+
id: 'Term ID',
|
|
122
|
+
name: 'Name',
|
|
123
|
+
slug: 'Slug',
|
|
124
|
+
link: 'Link',
|
|
125
|
+
description: 'Description',
|
|
126
|
+
parent: 'Parent ID',
|
|
127
|
+
count: 'Count',
|
|
128
|
+
content: 'unknown',
|
|
129
|
+
} );
|
|
130
|
+
} );
|
|
131
|
+
} );
|
|
132
|
+
|
|
133
|
+
describe( 'when termData is provided in context', () => {
|
|
134
|
+
const select = ( store ) => {
|
|
135
|
+
if ( store === blockEditorStore ) {
|
|
136
|
+
return {
|
|
137
|
+
getBlockName: () => 'core/paragraph',
|
|
138
|
+
getBlockAttributes: () => ( {} ),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if ( store === coreDataStore ) {
|
|
142
|
+
return {
|
|
143
|
+
getEntityRecord: () => null,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const termData = {
|
|
149
|
+
id: 456,
|
|
150
|
+
name: 'Design',
|
|
151
|
+
link: 'https://example.com/category/design',
|
|
152
|
+
description: 'Design resources',
|
|
153
|
+
parent: 0,
|
|
154
|
+
count: 15,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
it( 'should use termData from context when entity record is not available', () => {
|
|
158
|
+
const values = termDataBindings.getValues( {
|
|
159
|
+
select,
|
|
160
|
+
context: {
|
|
161
|
+
taxonomy: 'category',
|
|
162
|
+
termId: 456,
|
|
163
|
+
termData,
|
|
164
|
+
},
|
|
165
|
+
bindings,
|
|
166
|
+
clientId: '123abc456',
|
|
167
|
+
} );
|
|
168
|
+
|
|
169
|
+
expect( values ).toStrictEqual( {
|
|
170
|
+
id: 456,
|
|
171
|
+
name: 'Design',
|
|
172
|
+
slug: 'Slug',
|
|
173
|
+
link: 'https://example.com/category/design',
|
|
174
|
+
description: 'Design resources',
|
|
175
|
+
parent: 0,
|
|
176
|
+
count: '(15)',
|
|
177
|
+
content: 'unknown',
|
|
178
|
+
} );
|
|
179
|
+
} );
|
|
180
|
+
|
|
181
|
+
it( 'should use termData when taxonomy and termId are not provided', () => {
|
|
182
|
+
const values = termDataBindings.getValues( {
|
|
183
|
+
select,
|
|
184
|
+
context: {
|
|
185
|
+
termData,
|
|
186
|
+
},
|
|
187
|
+
bindings,
|
|
188
|
+
clientId: '123abc456',
|
|
189
|
+
} );
|
|
190
|
+
|
|
191
|
+
expect( values ).toStrictEqual( {
|
|
192
|
+
id: 456,
|
|
193
|
+
name: 'Design',
|
|
194
|
+
slug: 'Slug',
|
|
195
|
+
link: 'https://example.com/category/design',
|
|
196
|
+
description: 'Design resources',
|
|
197
|
+
parent: 0,
|
|
198
|
+
count: '(15)',
|
|
199
|
+
content: 'unknown',
|
|
200
|
+
} );
|
|
201
|
+
} );
|
|
202
|
+
} );
|
|
203
|
+
} );
|
|
204
|
+
|
|
205
|
+
describe( 'for navigation blocks using block attributes', () => {
|
|
206
|
+
it( 'should use block attributes instead of context', () => {
|
|
207
|
+
const select = ( store ) => {
|
|
208
|
+
if ( store === blockEditorStore ) {
|
|
209
|
+
return {
|
|
210
|
+
getBlockName: () => 'core/navigation-link',
|
|
211
|
+
getBlockAttributes: () => ( {
|
|
212
|
+
id: 789,
|
|
213
|
+
type: 'category',
|
|
214
|
+
} ),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
if ( store === coreDataStore ) {
|
|
218
|
+
return {
|
|
219
|
+
getEntityRecord: ( kind, taxonomy, termId ) => {
|
|
220
|
+
if (
|
|
221
|
+
kind === 'taxonomy' &&
|
|
222
|
+
taxonomy === 'category' &&
|
|
223
|
+
termId === 789
|
|
224
|
+
) {
|
|
225
|
+
return {
|
|
226
|
+
id: 789,
|
|
227
|
+
name: 'Programming',
|
|
228
|
+
slug: 'programming',
|
|
229
|
+
link: 'https://example.com/category/programming',
|
|
230
|
+
description: 'Programming resources',
|
|
231
|
+
parent: 0,
|
|
232
|
+
count: 10,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const values = termDataBindings.getValues( {
|
|
242
|
+
select,
|
|
243
|
+
context: {},
|
|
244
|
+
bindings,
|
|
245
|
+
clientId: '123abc456',
|
|
246
|
+
} );
|
|
247
|
+
|
|
248
|
+
expect( values ).toStrictEqual( {
|
|
249
|
+
id: 789,
|
|
250
|
+
name: 'Programming',
|
|
251
|
+
slug: 'programming',
|
|
252
|
+
link: 'https://example.com/category/programming',
|
|
253
|
+
description: 'Programming resources',
|
|
254
|
+
parent: 0,
|
|
255
|
+
count: '(10)',
|
|
256
|
+
content: 'unknown',
|
|
257
|
+
} );
|
|
258
|
+
} );
|
|
259
|
+
|
|
260
|
+
it( 'should convert "tag" type to "post_tag" taxonomy', () => {
|
|
261
|
+
const select = ( store ) => {
|
|
262
|
+
if ( store === blockEditorStore ) {
|
|
263
|
+
return {
|
|
264
|
+
getBlockName: () => 'core/navigation-link',
|
|
265
|
+
getBlockAttributes: () => ( {
|
|
266
|
+
id: 321,
|
|
267
|
+
type: 'tag',
|
|
268
|
+
} ),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
if ( store === coreDataStore ) {
|
|
272
|
+
return {
|
|
273
|
+
getEntityRecord: ( kind, taxonomy, termId ) => {
|
|
274
|
+
if (
|
|
275
|
+
kind === 'taxonomy' &&
|
|
276
|
+
taxonomy === 'post_tag' &&
|
|
277
|
+
termId === 321
|
|
278
|
+
) {
|
|
279
|
+
return {
|
|
280
|
+
name: 'JavaScript',
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
return null;
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const values = termDataBindings.getValues( {
|
|
290
|
+
select,
|
|
291
|
+
context: {},
|
|
292
|
+
bindings: {
|
|
293
|
+
content: {
|
|
294
|
+
source: 'core/term-data',
|
|
295
|
+
args: { field: 'name' },
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
clientId: '123abc456',
|
|
299
|
+
} );
|
|
300
|
+
|
|
301
|
+
expect( values.content ).toBe( 'JavaScript' );
|
|
302
|
+
} );
|
|
303
|
+
} );
|
|
304
|
+
} );
|
|
305
|
+
|
|
306
|
+
describe( 'getFieldsList', () => {
|
|
307
|
+
describe( 'when a Navigation block is selected', () => {
|
|
308
|
+
it( 'should return the list of available term data fields if id and type attributes are present', () => {
|
|
309
|
+
const select = ( store ) => {
|
|
310
|
+
if ( store === blockEditorStore ) {
|
|
311
|
+
return {
|
|
312
|
+
getSelectedBlockClientId: () => '123abc456',
|
|
313
|
+
getBlockName: () => 'core/navigation-link',
|
|
314
|
+
getBlockAttributes: () => ( {
|
|
315
|
+
id: 123,
|
|
316
|
+
type: 'category',
|
|
317
|
+
} ),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
if ( store === coreDataStore ) {
|
|
321
|
+
return {
|
|
322
|
+
getEntityRecord: getEntityRecordMock,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
const fields = termDataBindings.getFieldsList( { select } );
|
|
327
|
+
|
|
328
|
+
expect( fields ).toEqual( termDataFields );
|
|
329
|
+
} );
|
|
330
|
+
|
|
331
|
+
it( 'should return an empty array if id or type attributes are missing', () => {
|
|
332
|
+
const select = ( store ) => {
|
|
333
|
+
if ( store === blockEditorStore ) {
|
|
334
|
+
return {
|
|
335
|
+
getSelectedBlockClientId: () => '123abc456',
|
|
336
|
+
getBlockName: () => 'core/navigation-link',
|
|
337
|
+
getBlockAttributes: () => ( { type: 'category' } ),
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
if ( store === coreDataStore ) {
|
|
341
|
+
return {
|
|
342
|
+
getEntityRecord: getEntityRecordMock,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
const fields = termDataBindings.getFieldsList( { select } );
|
|
347
|
+
|
|
348
|
+
expect( fields ).toEqual( [] );
|
|
349
|
+
} );
|
|
350
|
+
} );
|
|
351
|
+
|
|
352
|
+
describe( 'when a non-Navigation block is selected', () => {
|
|
353
|
+
const select = ( store ) => {
|
|
354
|
+
if ( store === blockEditorStore ) {
|
|
355
|
+
return {
|
|
356
|
+
getSelectedBlockClientId: () => '123abc456',
|
|
357
|
+
getBlockName: () => 'core/paragraph',
|
|
358
|
+
getBlockAttributes: () => ( {} ),
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
if ( store === coreDataStore ) {
|
|
362
|
+
return {
|
|
363
|
+
getEntityRecord: getEntityRecordMock,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
it( 'should return the list of available term data fields when taxonomy and termId are provided by context', () => {
|
|
369
|
+
const fields = termDataBindings.getFieldsList( {
|
|
370
|
+
select,
|
|
371
|
+
context: { taxonomy: 'category', termId: 123 },
|
|
372
|
+
} );
|
|
373
|
+
|
|
374
|
+
expect( fields ).toEqual( termDataFields );
|
|
375
|
+
} );
|
|
376
|
+
|
|
377
|
+
it( 'should return empty array when neither termId nor termData is provided from context', () => {
|
|
378
|
+
const fields = termDataBindings.getFieldsList( {
|
|
379
|
+
select,
|
|
380
|
+
context: { taxonomy: 'category' },
|
|
381
|
+
} );
|
|
382
|
+
|
|
383
|
+
expect( fields ).toEqual( [] );
|
|
384
|
+
} );
|
|
385
|
+
|
|
386
|
+
it( 'should return fields when using termData from context', () => {
|
|
387
|
+
const fields = termDataBindings.getFieldsList( {
|
|
388
|
+
select,
|
|
389
|
+
context: {
|
|
390
|
+
termData: {
|
|
391
|
+
id: 456,
|
|
392
|
+
name: 'Design',
|
|
393
|
+
slug: 'design',
|
|
394
|
+
link: 'https://example.com/category/design',
|
|
395
|
+
description: 'Design resources',
|
|
396
|
+
parent: 0,
|
|
397
|
+
count: 15,
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
} );
|
|
401
|
+
|
|
402
|
+
expect( fields ).toEqual( termDataFields );
|
|
403
|
+
} );
|
|
404
|
+
} );
|
|
405
|
+
} );
|
|
406
|
+
} );
|