@wordpress/data 7.2.1-next.4d3b314fd5.0 → 7.4.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 -8
- package/src/components/use-dispatch/test/use-dispatch.js +84 -127
- package/src/components/use-select/test/index.js +93 -101
- package/src/components/use-select/test/suspense.js +6 -6
- package/src/components/with-dispatch/test/index.js +116 -178
- package/src/components/with-select/test/index.js +224 -309
- package/src/redux-store/test/index.js +3 -3
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/data",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0",
|
|
4
4
|
"description": "Data module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"sideEffects": false,
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "^7.16.0",
|
|
32
|
-
"@wordpress/compose": "^5.
|
|
33
|
-
"@wordpress/deprecated": "^3.
|
|
34
|
-
"@wordpress/element": "^4.
|
|
35
|
-
"@wordpress/is-shallow-equal": "^4.
|
|
36
|
-
"@wordpress/priority-queue": "^2.
|
|
37
|
-
"@wordpress/redux-routine": "^4.
|
|
32
|
+
"@wordpress/compose": "^5.18.0",
|
|
33
|
+
"@wordpress/deprecated": "^3.20.0",
|
|
34
|
+
"@wordpress/element": "^4.18.0",
|
|
35
|
+
"@wordpress/is-shallow-equal": "^4.20.0",
|
|
36
|
+
"@wordpress/priority-queue": "^2.20.0",
|
|
37
|
+
"@wordpress/redux-routine": "^4.20.0",
|
|
38
38
|
"equivalent-key-map": "^0.2.2",
|
|
39
39
|
"is-plain-object": "^5.0.0",
|
|
40
40
|
"is-promise": "^4.0.0",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "a2ff0e6471c88436dad0287beb88d1729aa6f5dd"
|
|
53
53
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
|
+
import userEvent from '@testing-library/user-event';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Internal dependencies
|
|
@@ -11,165 +12,121 @@ import createReduxStore from '../../../redux-store';
|
|
|
11
12
|
import { createRegistry } from '../../../registry';
|
|
12
13
|
import { RegistryProvider } from '../../registry-provider';
|
|
13
14
|
|
|
15
|
+
jest.useRealTimers();
|
|
16
|
+
|
|
14
17
|
describe( 'useDispatch', () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const counterStore = {
|
|
19
|
+
reducer: ( state = 0, action ) => {
|
|
20
|
+
if ( action.type === 'INC' ) {
|
|
21
|
+
return state + 1;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return state;
|
|
25
|
+
},
|
|
26
|
+
actions: {
|
|
27
|
+
inc: () => ( { type: 'INC' } ),
|
|
28
|
+
},
|
|
29
|
+
selectors: {
|
|
30
|
+
get: ( state ) => state,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
it( 'returns dispatch function from store with no store name provided', async () => {
|
|
35
|
+
const user = userEvent.setup();
|
|
36
|
+
const registry = createRegistry();
|
|
37
|
+
registry.registerStore( 'demo', counterStore );
|
|
19
38
|
|
|
20
|
-
it( 'returns dispatch function from store with no store name provided', () => {
|
|
21
|
-
registry.registerStore( 'demoStore', {
|
|
22
|
-
reducer: ( state ) => state,
|
|
23
|
-
actions: {
|
|
24
|
-
foo: () => 'bar',
|
|
25
|
-
},
|
|
26
|
-
} );
|
|
27
39
|
const TestComponent = () => {
|
|
28
|
-
return <div></div>;
|
|
29
|
-
};
|
|
30
|
-
const Component = () => {
|
|
31
40
|
const dispatch = useDispatch();
|
|
32
|
-
return <
|
|
41
|
+
return <button onClick={ () => dispatch( 'demo' ).inc() } />;
|
|
33
42
|
};
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
</RegistryProvider>
|
|
41
|
-
);
|
|
42
|
-
} );
|
|
44
|
+
render(
|
|
45
|
+
<RegistryProvider value={ registry }>
|
|
46
|
+
<TestComponent />
|
|
47
|
+
</RegistryProvider>
|
|
48
|
+
);
|
|
43
49
|
|
|
44
|
-
|
|
50
|
+
await user.click( screen.getByRole( 'button' ) );
|
|
45
51
|
|
|
46
|
-
expect(
|
|
47
|
-
registry.dispatch
|
|
48
|
-
);
|
|
52
|
+
expect( registry.select( 'demo' ).get() ).toBe( 1 );
|
|
49
53
|
} );
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
const store = createReduxStore( 'demoStore',
|
|
54
|
-
|
|
55
|
-
actions: {
|
|
56
|
-
foo: testAction,
|
|
57
|
-
},
|
|
58
|
-
} );
|
|
54
|
+
|
|
55
|
+
it( 'returns expected action creators from store for given store descriptor', async () => {
|
|
56
|
+
const user = userEvent.setup();
|
|
57
|
+
const store = createReduxStore( 'demoStore', counterStore );
|
|
58
|
+
const registry = createRegistry();
|
|
59
59
|
registry.register( store );
|
|
60
60
|
|
|
61
61
|
const TestComponent = () => {
|
|
62
|
-
const {
|
|
63
|
-
return <button onClick={
|
|
62
|
+
const { inc } = useDispatch( store );
|
|
63
|
+
return <button onClick={ inc } />;
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
<TestComponent />
|
|
72
|
-
</RegistryProvider>
|
|
73
|
-
);
|
|
74
|
-
} );
|
|
75
|
-
|
|
76
|
-
const testInstance = testRenderer.root;
|
|
66
|
+
render(
|
|
67
|
+
<RegistryProvider value={ registry }>
|
|
68
|
+
<TestComponent />
|
|
69
|
+
</RegistryProvider>
|
|
70
|
+
);
|
|
77
71
|
|
|
78
|
-
|
|
79
|
-
testInstance.findByType( 'button' ).props.onClick();
|
|
80
|
-
} );
|
|
72
|
+
await user.click( screen.getByRole( 'button' ) );
|
|
81
73
|
|
|
82
|
-
expect(
|
|
74
|
+
expect( registry.select( store ).get() ).toBe( 1 );
|
|
83
75
|
} );
|
|
84
76
|
|
|
85
|
-
it( 'returns expected action creators from store for given
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
registry.registerStore( 'demoStore',
|
|
89
|
-
reducer: ( state ) => state,
|
|
90
|
-
actions: {
|
|
91
|
-
foo: testAction,
|
|
92
|
-
},
|
|
93
|
-
} );
|
|
77
|
+
it( 'returns expected action creators from store for given storeName', async () => {
|
|
78
|
+
const user = userEvent.setup();
|
|
79
|
+
const registry = createRegistry();
|
|
80
|
+
registry.registerStore( 'demoStore', counterStore );
|
|
94
81
|
const TestComponent = () => {
|
|
95
|
-
const {
|
|
96
|
-
return <button onClick={
|
|
82
|
+
const { inc } = useDispatch( 'demoStore' );
|
|
83
|
+
return <button onClick={ inc } />;
|
|
97
84
|
};
|
|
98
85
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
<TestComponent />
|
|
105
|
-
</RegistryProvider>
|
|
106
|
-
);
|
|
107
|
-
} );
|
|
108
|
-
|
|
109
|
-
const testInstance = testRenderer.root;
|
|
86
|
+
render(
|
|
87
|
+
<RegistryProvider value={ registry }>
|
|
88
|
+
<TestComponent />
|
|
89
|
+
</RegistryProvider>
|
|
90
|
+
);
|
|
110
91
|
|
|
111
|
-
|
|
112
|
-
testInstance.findByType( 'button' ).props.onClick();
|
|
113
|
-
} );
|
|
92
|
+
await user.click( screen.getByRole( 'button' ) );
|
|
114
93
|
|
|
115
|
-
expect(
|
|
94
|
+
expect( registry.select( 'demoStore' ).get() ).toBe( 1 );
|
|
116
95
|
} );
|
|
117
96
|
|
|
118
|
-
it( 'returns dispatch from correct registry if registries change', () => {
|
|
119
|
-
const
|
|
120
|
-
const noop = () => ( { type: '__INERT__' } );
|
|
121
|
-
const firstRegistryAction = jest.fn().mockImplementation( noop );
|
|
122
|
-
const secondRegistryAction = jest.fn().mockImplementation( noop );
|
|
97
|
+
it( 'returns dispatch from correct registry if registries change', async () => {
|
|
98
|
+
const user = userEvent.setup();
|
|
123
99
|
|
|
124
|
-
const firstRegistry =
|
|
125
|
-
firstRegistry.registerStore( 'demo',
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
},
|
|
130
|
-
} );
|
|
100
|
+
const firstRegistry = createRegistry();
|
|
101
|
+
firstRegistry.registerStore( 'demo', counterStore );
|
|
102
|
+
|
|
103
|
+
const secondRegistry = createRegistry();
|
|
104
|
+
secondRegistry.registerStore( 'demo', counterStore );
|
|
131
105
|
|
|
132
106
|
const TestComponent = () => {
|
|
133
107
|
const dispatch = useDispatch();
|
|
134
|
-
return <button onClick={ () => dispatch( 'demo' ).
|
|
108
|
+
return <button onClick={ () => dispatch( 'demo' ).inc() } />;
|
|
135
109
|
};
|
|
136
110
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
</RegistryProvider>
|
|
143
|
-
);
|
|
144
|
-
} );
|
|
145
|
-
const testInstance = testRenderer.root;
|
|
111
|
+
const { rerender } = render(
|
|
112
|
+
<RegistryProvider value={ firstRegistry }>
|
|
113
|
+
<TestComponent />
|
|
114
|
+
</RegistryProvider>
|
|
115
|
+
);
|
|
146
116
|
|
|
147
|
-
|
|
148
|
-
testInstance.findByType( 'button' ).props.onClick();
|
|
149
|
-
} );
|
|
117
|
+
await user.click( screen.getByRole( 'button' ) );
|
|
150
118
|
|
|
151
|
-
expect(
|
|
152
|
-
expect(
|
|
119
|
+
expect( firstRegistry.select( 'demo' ).get() ).toBe( 1 );
|
|
120
|
+
expect( secondRegistry.select( 'demo' ).get() ).toBe( 0 );
|
|
153
121
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
testRenderer.update(
|
|
164
|
-
<RegistryProvider value={ secondRegistry }>
|
|
165
|
-
<TestComponent />
|
|
166
|
-
</RegistryProvider>
|
|
167
|
-
);
|
|
168
|
-
} );
|
|
169
|
-
act( () => {
|
|
170
|
-
testInstance.findByType( 'button' ).props.onClick();
|
|
171
|
-
} );
|
|
172
|
-
expect( firstRegistryAction ).toHaveBeenCalledTimes( 1 );
|
|
173
|
-
expect( secondRegistryAction ).toHaveBeenCalledTimes( 1 );
|
|
122
|
+
rerender(
|
|
123
|
+
<RegistryProvider value={ secondRegistry }>
|
|
124
|
+
<TestComponent />
|
|
125
|
+
</RegistryProvider>
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
await user.click( screen.getByRole( 'button' ) );
|
|
129
|
+
expect( firstRegistry.select( 'demo' ).get() ).toBe( 1 );
|
|
130
|
+
expect( secondRegistry.select( 'demo' ).get() ).toBe( 1 );
|
|
174
131
|
} );
|
|
175
132
|
} );
|