@wordpress/core-data 6.2.0 → 6.3.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 +2 -0
- package/build/entities.js +6 -4
- package/build/entities.js.map +1 -1
- package/build/fetch/index.js +0 -8
- package/build/fetch/index.js.map +1 -1
- package/build/queried-data/reducer.js +1 -1
- package/build/queried-data/reducer.js.map +1 -1
- package/build/reducer.js +1 -1
- package/build/reducer.js.map +1 -1
- package/build/selectors.js +4 -2
- package/build/selectors.js.map +1 -1
- package/build-module/entities.js +7 -5
- package/build-module/entities.js.map +1 -1
- package/build-module/fetch/index.js +0 -1
- package/build-module/fetch/index.js.map +1 -1
- package/build-module/queried-data/reducer.js +2 -2
- package/build-module/queried-data/reducer.js.map +1 -1
- package/build-module/reducer.js +2 -2
- package/build-module/reducer.js.map +1 -1
- package/build-module/selectors.js +5 -3
- package/build-module/selectors.js.map +1 -1
- package/build-types/fetch/index.d.ts +0 -1
- package/build-types/reducer.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/entities.js +3 -3
- package/src/fetch/index.js +0 -1
- package/src/fetch/test/__experimental-fetch-url-data.js +7 -7
- package/src/hooks/test/use-entity-record.js +20 -31
- package/src/hooks/test/use-entity-records.js +6 -15
- package/src/hooks/test/use-query-select.js +10 -18
- package/src/hooks/test/use-resource-permissions.js +21 -34
- package/src/queried-data/reducer.js +2 -2
- package/src/reducer.js +2 -5
- package/src/selectors.ts +3 -3
- package/src/test/actions.js +0 -18
- package/src/test/entities.js +0 -6
- package/src/test/resolvers.js +0 -12
- package/tsconfig.tsbuildinfo +1 -1
- package/build/fetch/fetch-media.js +0 -23
- package/build/fetch/fetch-media.js.map +0 -1
- package/build-module/fetch/fetch-media.js +0 -14
- package/build-module/fetch/fetch-media.js.map +0 -1
- package/build-types/fetch/fetch-media.d.ts +0 -2
- package/build-types/fetch/fetch-media.d.ts.map +0 -1
- package/src/fetch/fetch-media.js +0 -13
|
@@ -9,7 +9,7 @@ jest.mock( '@wordpress/api-fetch' );
|
|
|
9
9
|
/**
|
|
10
10
|
* External dependencies
|
|
11
11
|
*/
|
|
12
|
-
import { act, render } from '@testing-library/react';
|
|
12
|
+
import { act, render, waitFor } from '@testing-library/react';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Internal dependencies
|
|
@@ -21,17 +21,10 @@ describe( 'useEntityRecord', () => {
|
|
|
21
21
|
let registry;
|
|
22
22
|
|
|
23
23
|
beforeEach( () => {
|
|
24
|
-
jest.useFakeTimers();
|
|
25
|
-
|
|
26
24
|
registry = createRegistry();
|
|
27
25
|
registry.register( coreDataStore );
|
|
28
26
|
} );
|
|
29
27
|
|
|
30
|
-
afterEach( () => {
|
|
31
|
-
jest.runOnlyPendingTimers();
|
|
32
|
-
jest.useRealTimers();
|
|
33
|
-
} );
|
|
34
|
-
|
|
35
28
|
const TEST_RECORD = { id: 1, hello: 'world' };
|
|
36
29
|
|
|
37
30
|
it( 'resolves the entity record when missing from the state', async () => {
|
|
@@ -60,14 +53,12 @@ describe( 'useEntityRecord', () => {
|
|
|
60
53
|
status: 'IDLE',
|
|
61
54
|
} );
|
|
62
55
|
|
|
63
|
-
await act( async () => {
|
|
64
|
-
jest.advanceTimersByTime( 1 );
|
|
65
|
-
} );
|
|
66
|
-
|
|
67
56
|
// Fetch request should have been issued
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
await waitFor( () =>
|
|
58
|
+
expect( triggerFetch ).toHaveBeenCalledWith( {
|
|
59
|
+
path: '/wp/v2/widgets/1?context=edit',
|
|
60
|
+
} )
|
|
61
|
+
);
|
|
71
62
|
|
|
72
63
|
expect( data ).toEqual( {
|
|
73
64
|
edit: expect.any( Function ),
|
|
@@ -96,27 +87,25 @@ describe( 'useEntityRecord', () => {
|
|
|
96
87
|
</RegistryProvider>
|
|
97
88
|
);
|
|
98
89
|
|
|
99
|
-
await
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
status: 'SUCCESS',
|
|
112
|
-
} );
|
|
90
|
+
await waitFor( () =>
|
|
91
|
+
expect( widget ).toEqual( {
|
|
92
|
+
edit: expect.any( Function ),
|
|
93
|
+
editedRecord: { hello: 'world', id: 1 },
|
|
94
|
+
hasEdits: false,
|
|
95
|
+
record: { hello: 'world', id: 1 },
|
|
96
|
+
save: expect.any( Function ),
|
|
97
|
+
hasResolved: true,
|
|
98
|
+
isResolving: false,
|
|
99
|
+
status: 'SUCCESS',
|
|
100
|
+
} )
|
|
101
|
+
);
|
|
113
102
|
|
|
114
103
|
await act( async () => {
|
|
115
104
|
widget.edit( { hello: 'foo' } );
|
|
116
|
-
jest.advanceTimersByTime( 1 );
|
|
117
105
|
} );
|
|
118
106
|
|
|
119
|
-
expect( widget.hasEdits ).toEqual( true );
|
|
107
|
+
await waitFor( () => expect( widget.hasEdits ).toEqual( true ) );
|
|
108
|
+
|
|
120
109
|
expect( widget.record ).toEqual( { hello: 'world', id: 1 } );
|
|
121
110
|
expect( widget.editedRecord ).toEqual( { hello: 'foo', id: 1 } );
|
|
122
111
|
} );
|
|
@@ -9,7 +9,7 @@ jest.mock( '@wordpress/api-fetch' );
|
|
|
9
9
|
/**
|
|
10
10
|
* External dependencies
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
12
|
+
import { render, waitFor } from '@testing-library/react';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Internal dependencies
|
|
@@ -21,17 +21,10 @@ describe( 'useEntityRecords', () => {
|
|
|
21
21
|
let registry;
|
|
22
22
|
|
|
23
23
|
beforeEach( () => {
|
|
24
|
-
jest.useFakeTimers();
|
|
25
|
-
|
|
26
24
|
registry = createRegistry();
|
|
27
25
|
registry.register( coreDataStore );
|
|
28
26
|
} );
|
|
29
27
|
|
|
30
|
-
afterEach( () => {
|
|
31
|
-
jest.runOnlyPendingTimers();
|
|
32
|
-
jest.useRealTimers();
|
|
33
|
-
} );
|
|
34
|
-
|
|
35
28
|
const TEST_RECORDS = [
|
|
36
29
|
{ id: 1, hello: 'world1' },
|
|
37
30
|
{ id: 2, hello: 'world2' },
|
|
@@ -60,14 +53,12 @@ describe( 'useEntityRecords', () => {
|
|
|
60
53
|
status: 'IDLE',
|
|
61
54
|
} );
|
|
62
55
|
|
|
63
|
-
await act( async () => {
|
|
64
|
-
jest.advanceTimersByTime( 1 );
|
|
65
|
-
} );
|
|
66
|
-
|
|
67
56
|
// Fetch request should have been issued
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
await waitFor( () =>
|
|
58
|
+
expect( triggerFetch ).toHaveBeenCalledWith( {
|
|
59
|
+
path: '/wp/v2/widgets?context=edit&status=draft',
|
|
60
|
+
} )
|
|
61
|
+
);
|
|
71
62
|
|
|
72
63
|
expect( data ).toEqual( {
|
|
73
64
|
records: TEST_RECORDS,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
/**
|
|
11
11
|
* External dependencies
|
|
12
12
|
*/
|
|
13
|
-
import {
|
|
13
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Internal dependencies
|
|
@@ -21,8 +21,6 @@ describe( 'useQuerySelect', () => {
|
|
|
21
21
|
let registry;
|
|
22
22
|
|
|
23
23
|
beforeEach( () => {
|
|
24
|
-
jest.useFakeTimers();
|
|
25
|
-
|
|
26
24
|
registry = createRegistry();
|
|
27
25
|
registry.registerStore( 'testStore', {
|
|
28
26
|
reducer: () => ( { foo: 'bar' } ),
|
|
@@ -33,11 +31,6 @@ describe( 'useQuerySelect', () => {
|
|
|
33
31
|
} );
|
|
34
32
|
} );
|
|
35
33
|
|
|
36
|
-
afterEach( () => {
|
|
37
|
-
jest.runOnlyPendingTimers();
|
|
38
|
-
jest.useRealTimers();
|
|
39
|
-
} );
|
|
40
|
-
|
|
41
34
|
const getTestComponent = ( mapSelectSpy, dependencyKey ) => ( props ) => {
|
|
42
35
|
const dependencies = props[ dependencyKey ];
|
|
43
36
|
mapSelectSpy.mockImplementation( ( select ) => ( {
|
|
@@ -177,21 +170,20 @@ describe( 'useQuerySelect', () => {
|
|
|
177
170
|
status: 'IDLE',
|
|
178
171
|
} );
|
|
179
172
|
|
|
180
|
-
await act( async () => {
|
|
181
|
-
jest.advanceTimersToNextTimer();
|
|
182
|
-
} );
|
|
183
|
-
|
|
184
173
|
// Re-render, expect resolved data
|
|
185
174
|
render(
|
|
186
175
|
<RegistryProvider value={ registry }>
|
|
187
176
|
<TestComponent />
|
|
188
177
|
</RegistryProvider>
|
|
189
178
|
);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
179
|
+
|
|
180
|
+
await waitFor( () =>
|
|
181
|
+
expect( querySelectData ).toEqual( {
|
|
182
|
+
data: 15,
|
|
183
|
+
isResolving: false,
|
|
184
|
+
hasResolved: true,
|
|
185
|
+
status: 'SUCCESS',
|
|
186
|
+
} )
|
|
187
|
+
);
|
|
196
188
|
} );
|
|
197
189
|
} );
|
|
@@ -9,7 +9,7 @@ jest.mock( '@wordpress/api-fetch' );
|
|
|
9
9
|
/**
|
|
10
10
|
* External dependencies
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
12
|
+
import { render, waitFor } from '@testing-library/react';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Internal dependencies
|
|
@@ -20,8 +20,6 @@ import useResourcePermissions from '../use-resource-permissions';
|
|
|
20
20
|
describe( 'useResourcePermissions', () => {
|
|
21
21
|
let registry;
|
|
22
22
|
beforeEach( () => {
|
|
23
|
-
jest.useFakeTimers();
|
|
24
|
-
|
|
25
23
|
registry = createRegistry();
|
|
26
24
|
registry.register( coreDataStore );
|
|
27
25
|
|
|
@@ -34,11 +32,6 @@ describe( 'useResourcePermissions', () => {
|
|
|
34
32
|
} ) );
|
|
35
33
|
} );
|
|
36
34
|
|
|
37
|
-
afterEach( () => {
|
|
38
|
-
jest.runOnlyPendingTimers();
|
|
39
|
-
jest.useRealTimers();
|
|
40
|
-
} );
|
|
41
|
-
|
|
42
35
|
it( 'retrieves the relevant permissions for a key-less resource', async () => {
|
|
43
36
|
let data;
|
|
44
37
|
const TestComponent = () => {
|
|
@@ -58,18 +51,15 @@ describe( 'useResourcePermissions', () => {
|
|
|
58
51
|
canRead: false,
|
|
59
52
|
} );
|
|
60
53
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
canCreate: true,
|
|
71
|
-
canRead: false,
|
|
72
|
-
} );
|
|
54
|
+
await waitFor( () =>
|
|
55
|
+
expect( data ).toEqual( {
|
|
56
|
+
status: 'SUCCESS',
|
|
57
|
+
isResolving: false,
|
|
58
|
+
hasResolved: true,
|
|
59
|
+
canCreate: true,
|
|
60
|
+
canRead: false,
|
|
61
|
+
} )
|
|
62
|
+
);
|
|
73
63
|
} );
|
|
74
64
|
|
|
75
65
|
it( 'retrieves the relevant permissions for a resource with a key', async () => {
|
|
@@ -93,19 +83,16 @@ describe( 'useResourcePermissions', () => {
|
|
|
93
83
|
canDelete: false,
|
|
94
84
|
} );
|
|
95
85
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
canUpdate: false,
|
|
108
|
-
canDelete: false,
|
|
109
|
-
} );
|
|
86
|
+
await waitFor( () =>
|
|
87
|
+
expect( data ).toEqual( {
|
|
88
|
+
status: 'SUCCESS',
|
|
89
|
+
isResolving: false,
|
|
90
|
+
hasResolved: true,
|
|
91
|
+
canCreate: true,
|
|
92
|
+
canRead: false,
|
|
93
|
+
canUpdate: false,
|
|
94
|
+
canDelete: false,
|
|
95
|
+
} )
|
|
96
|
+
);
|
|
110
97
|
} );
|
|
111
98
|
} );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { mapValues } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -230,7 +230,7 @@ const receiveQueries = compose( [
|
|
|
230
230
|
|
|
231
231
|
return getMergedItemIds(
|
|
232
232
|
state || [],
|
|
233
|
-
|
|
233
|
+
action.items.map( ( item ) => item[ key ] ),
|
|
234
234
|
page,
|
|
235
235
|
perPage
|
|
236
236
|
);
|
package/src/reducer.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import fastDeepEqual from 'fast-deep-equal/es6';
|
|
5
|
-
import {
|
|
5
|
+
import { groupBy, get } from 'lodash';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
@@ -68,10 +68,7 @@ export function users( state = { byId: {}, queries: {} }, action ) {
|
|
|
68
68
|
},
|
|
69
69
|
queries: {
|
|
70
70
|
...state.queries,
|
|
71
|
-
[ action.queryID ]: map(
|
|
72
|
-
action.users,
|
|
73
|
-
( user ) => user.id
|
|
74
|
-
),
|
|
71
|
+
[ action.queryID ]: action.users.map( ( user ) => user.id ),
|
|
75
72
|
},
|
|
76
73
|
};
|
|
77
74
|
}
|
package/src/selectors.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import createSelector from 'rememo';
|
|
5
|
-
import { set,
|
|
5
|
+
import { set, get } from 'lodash';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
@@ -147,9 +147,9 @@ export function getCurrentUser( state: State ): ET.User< 'edit' > {
|
|
|
147
147
|
*/
|
|
148
148
|
export const getUserQueryResults = createSelector(
|
|
149
149
|
( state: State, queryID: string ): ET.User< 'edit' >[] => {
|
|
150
|
-
const queryResults = state.users.queries[ queryID ];
|
|
150
|
+
const queryResults = state.users.queries[ queryID ] ?? [];
|
|
151
151
|
|
|
152
|
-
return map(
|
|
152
|
+
return queryResults.map( ( id ) => state.users.byId[ id ] );
|
|
153
153
|
},
|
|
154
154
|
( state: State, queryID: string ) => [
|
|
155
155
|
state.users.queries[ queryID ],
|
package/src/test/actions.js
CHANGED
|
@@ -55,12 +55,6 @@ describe( 'editEntityRecord', () => {
|
|
|
55
55
|
describe( 'deleteEntityRecord', () => {
|
|
56
56
|
beforeEach( async () => {
|
|
57
57
|
apiFetch.mockReset();
|
|
58
|
-
jest.useFakeTimers();
|
|
59
|
-
} );
|
|
60
|
-
|
|
61
|
-
afterEach( () => {
|
|
62
|
-
jest.runOnlyPendingTimers();
|
|
63
|
-
jest.useRealTimers();
|
|
64
58
|
} );
|
|
65
59
|
|
|
66
60
|
it( 'triggers a DELETE request for an existing record', async () => {
|
|
@@ -182,12 +176,6 @@ describe( 'deleteEntityRecord', () => {
|
|
|
182
176
|
describe( 'saveEditedEntityRecord', () => {
|
|
183
177
|
beforeEach( async () => {
|
|
184
178
|
apiFetch.mockReset();
|
|
185
|
-
jest.useFakeTimers();
|
|
186
|
-
} );
|
|
187
|
-
|
|
188
|
-
afterEach( () => {
|
|
189
|
-
jest.runOnlyPendingTimers();
|
|
190
|
-
jest.useRealTimers();
|
|
191
179
|
} );
|
|
192
180
|
|
|
193
181
|
it( 'Uses "id" as a key when no entity key is provided', async () => {
|
|
@@ -277,7 +265,6 @@ describe( 'saveEntityRecord', () => {
|
|
|
277
265
|
|
|
278
266
|
beforeEach( async () => {
|
|
279
267
|
apiFetch.mockReset();
|
|
280
|
-
jest.useFakeTimers();
|
|
281
268
|
dispatch = Object.assign( jest.fn(), {
|
|
282
269
|
receiveEntityRecords: jest.fn(),
|
|
283
270
|
__unstableAcquireStoreLock: jest.fn(),
|
|
@@ -285,11 +272,6 @@ describe( 'saveEntityRecord', () => {
|
|
|
285
272
|
} );
|
|
286
273
|
} );
|
|
287
274
|
|
|
288
|
-
afterEach( () => {
|
|
289
|
-
jest.runOnlyPendingTimers();
|
|
290
|
-
jest.useRealTimers();
|
|
291
|
-
} );
|
|
292
|
-
|
|
293
275
|
it( 'triggers a POST request for a new record', async () => {
|
|
294
276
|
const post = { title: 'new post' };
|
|
295
277
|
const configs = [
|
package/src/test/entities.js
CHANGED
|
@@ -52,12 +52,6 @@ describe( 'getMethodName', () => {
|
|
|
52
52
|
describe( 'getKindEntities', () => {
|
|
53
53
|
beforeEach( async () => {
|
|
54
54
|
triggerFetch.mockReset();
|
|
55
|
-
jest.useFakeTimers();
|
|
56
|
-
} );
|
|
57
|
-
|
|
58
|
-
afterEach( () => {
|
|
59
|
-
jest.runOnlyPendingTimers();
|
|
60
|
-
jest.useRealTimers();
|
|
61
55
|
} );
|
|
62
56
|
|
|
63
57
|
it( 'shouldn’t do anything if the entities have already been resolved', async () => {
|
package/src/test/resolvers.js
CHANGED
|
@@ -30,12 +30,6 @@ describe( 'getEntityRecord', () => {
|
|
|
30
30
|
|
|
31
31
|
beforeEach( async () => {
|
|
32
32
|
triggerFetch.mockReset();
|
|
33
|
-
jest.useFakeTimers();
|
|
34
|
-
} );
|
|
35
|
-
|
|
36
|
-
afterEach( () => {
|
|
37
|
-
jest.runOnlyPendingTimers();
|
|
38
|
-
jest.useRealTimers();
|
|
39
33
|
} );
|
|
40
34
|
|
|
41
35
|
it( 'yields with requested post type', async () => {
|
|
@@ -152,12 +146,6 @@ describe( 'getEntityRecords', () => {
|
|
|
152
146
|
|
|
153
147
|
beforeEach( async () => {
|
|
154
148
|
triggerFetch.mockReset();
|
|
155
|
-
jest.useFakeTimers();
|
|
156
|
-
} );
|
|
157
|
-
|
|
158
|
-
afterEach( () => {
|
|
159
|
-
jest.runOnlyPendingTimers();
|
|
160
|
-
jest.useRealTimers();
|
|
161
149
|
} );
|
|
162
150
|
|
|
163
151
|
it( 'dispatches the requested post type', async () => {
|