@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 CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 7.4.0 (2022-10-19)
6
+
7
+ ## 7.3.0 (2022-10-05)
8
+
5
9
  ## 7.2.0 (2022-09-21)
6
10
 
7
11
  ## 7.1.0 (2022-09-13)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/data",
3
- "version": "7.2.1-next.4d3b314fd5.0",
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.16.1-next.4d3b314fd5.0",
33
- "@wordpress/deprecated": "^3.18.1-next.4d3b314fd5.0",
34
- "@wordpress/element": "^4.16.1-next.4d3b314fd5.0",
35
- "@wordpress/is-shallow-equal": "^4.18.1-next.4d3b314fd5.0",
36
- "@wordpress/priority-queue": "^2.18.1-next.4d3b314fd5.0",
37
- "@wordpress/redux-routine": "^4.18.1-next.4d3b314fd5.0",
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": "25054766423cb49d959eb656c2533530073ff5c2"
52
+ "gitHead": "a2ff0e6471c88436dad0287beb88d1729aa6f5dd"
53
53
  }
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import TestRenderer, { act } from 'react-test-renderer';
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
- let registry;
16
- beforeEach( () => {
17
- registry = createRegistry();
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 <TestComponent dispatch={ dispatch } />;
41
+ return <button onClick={ () => dispatch( 'demo' ).inc() } />;
33
42
  };
34
43
 
35
- let testRenderer;
36
- act( () => {
37
- testRenderer = TestRenderer.create(
38
- <RegistryProvider value={ registry }>
39
- <Component />
40
- </RegistryProvider>
41
- );
42
- } );
44
+ render(
45
+ <RegistryProvider value={ registry }>
46
+ <TestComponent />
47
+ </RegistryProvider>
48
+ );
43
49
 
44
- const testInstance = testRenderer.root;
50
+ await user.click( screen.getByRole( 'button' ) );
45
51
 
46
- expect( testInstance.findByType( TestComponent ).props.dispatch ).toBe(
47
- registry.dispatch
48
- );
52
+ expect( registry.select( 'demo' ).get() ).toBe( 1 );
49
53
  } );
50
- it( 'returns expected action creators from store for given storeName', () => {
51
- const noop = () => ( { type: '__INERT__' } );
52
- const testAction = jest.fn().mockImplementation( noop );
53
- const store = createReduxStore( 'demoStore', {
54
- reducer: ( state ) => state,
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 { foo } = useDispatch( store );
63
- return <button onClick={ foo } />;
62
+ const { inc } = useDispatch( store );
63
+ return <button onClick={ inc } />;
64
64
  };
65
65
 
66
- let testRenderer;
67
-
68
- act( () => {
69
- testRenderer = TestRenderer.create(
70
- <RegistryProvider value={ registry }>
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
- act( () => {
79
- testInstance.findByType( 'button' ).props.onClick();
80
- } );
72
+ await user.click( screen.getByRole( 'button' ) );
81
73
 
82
- expect( testAction ).toHaveBeenCalledTimes( 1 );
74
+ expect( registry.select( store ).get() ).toBe( 1 );
83
75
  } );
84
76
 
85
- it( 'returns expected action creators from store for given store descriptor', () => {
86
- const noop = () => ( { type: '__INERT__' } );
87
- const testAction = jest.fn().mockImplementation( noop );
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 { foo } = useDispatch( 'demoStore' );
96
- return <button onClick={ foo } />;
82
+ const { inc } = useDispatch( 'demoStore' );
83
+ return <button onClick={ inc } />;
97
84
  };
98
85
 
99
- let testRenderer;
100
-
101
- act( () => {
102
- testRenderer = TestRenderer.create(
103
- <RegistryProvider value={ registry }>
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
- act( () => {
112
- testInstance.findByType( 'button' ).props.onClick();
113
- } );
92
+ await user.click( screen.getByRole( 'button' ) );
114
93
 
115
- expect( testAction ).toHaveBeenCalledTimes( 1 );
94
+ expect( registry.select( 'demoStore' ).get() ).toBe( 1 );
116
95
  } );
117
96
 
118
- it( 'returns dispatch from correct registry if registries change', () => {
119
- const reducer = ( state ) => state;
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 = registry;
125
- firstRegistry.registerStore( 'demo', {
126
- reducer,
127
- actions: {
128
- noop: firstRegistryAction,
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' ).noop() } />;
108
+ return <button onClick={ () => dispatch( 'demo' ).inc() } />;
135
109
  };
136
110
 
137
- let testRenderer;
138
- act( () => {
139
- testRenderer = TestRenderer.create(
140
- <RegistryProvider value={ firstRegistry }>
141
- <TestComponent />
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
- act( () => {
148
- testInstance.findByType( 'button' ).props.onClick();
149
- } );
117
+ await user.click( screen.getByRole( 'button' ) );
150
118
 
151
- expect( firstRegistryAction ).toHaveBeenCalledTimes( 1 );
152
- expect( secondRegistryAction ).toHaveBeenCalledTimes( 0 );
119
+ expect( firstRegistry.select( 'demo' ).get() ).toBe( 1 );
120
+ expect( secondRegistry.select( 'demo' ).get() ).toBe( 0 );
153
121
 
154
- const secondRegistry = createRegistry();
155
- secondRegistry.registerStore( 'demo', {
156
- reducer,
157
- actions: {
158
- noop: secondRegistryAction,
159
- },
160
- } );
161
-
162
- act( () => {
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
  } );