@dhis2-ui/organisation-unit-tree 10.0.0-alpha.7 → 10.0.0-alpha.8

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.
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  var _appRuntime = require("@dhis2/app-runtime");
4
- var _reactHooks = require("@testing-library/react-hooks");
5
- var _react = _interopRequireDefault(require("react"));
4
+ var _react = require("@testing-library/react");
5
+ var _react2 = _interopRequireDefault(require("react"));
6
6
  var _useRootOrgData = require("./use-root-org-data.js");
7
7
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
8
  describe('OrganisationUnitTree - useRootOrgData', () => {
@@ -47,14 +47,14 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
47
47
  let {
48
48
  children
49
49
  } = _ref;
50
- return /*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
50
+ return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
51
51
  data: dataProviderData
52
52
  }, children);
53
53
  };
54
54
  it('should respond with `loading: false`, `error: null` and `data: null` initially', () => {
55
55
  const {
56
56
  result
57
- } = (0, _reactHooks.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000']), {
57
+ } = (0, _react.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000']), {
58
58
  wrapper
59
59
  });
60
60
  expect(result.current).toEqual(expect.objectContaining({
@@ -66,12 +66,11 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
66
66
  });
67
67
  it('should provide the org unit data', async () => {
68
68
  const {
69
- result,
70
- waitForNextUpdate
71
- } = (0, _reactHooks.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000']), {
69
+ result
70
+ } = (0, _react.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000']), {
72
71
  wrapper
73
72
  });
74
- await waitForNextUpdate();
73
+ await (0, _react.waitFor)(() => {});
75
74
  expect(result.current).toEqual(expect.objectContaining({
76
75
  loading: false,
77
76
  error: null,
@@ -89,7 +88,7 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
89
88
  let {
90
89
  children
91
90
  } = _ref2;
92
- return /*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
91
+ return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
93
92
  data: {
94
93
  organisationUnits: async () => {
95
94
  throw new Error('Error message');
@@ -98,25 +97,23 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
98
97
  }, children);
99
98
  };
100
99
  const {
101
- result,
102
- waitForNextUpdate
103
- } = (0, _reactHooks.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000']), {
100
+ result
101
+ } = (0, _react.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000']), {
104
102
  wrapper: errorWrapper
105
103
  });
106
- await waitForNextUpdate();
107
- expect(result.current).toEqual(expect.objectContaining({
108
- loading: false,
109
- error: new Error('Error message'),
110
- data: null
111
- }));
104
+ await (0, _react.waitFor)(() => {
105
+ expect(result.current).toEqual(expect.objectContaining({
106
+ loading: false,
107
+ error: new Error('Error message'),
108
+ data: null
109
+ }));
110
+ });
112
111
  });
113
112
  it('should send the "isUserDataViewFallback" parameter with value "undefined"', async () => {
114
- const {
115
- waitForNextUpdate
116
- } = (0, _reactHooks.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000']), {
113
+ (0, _react.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000']), {
117
114
  wrapper
118
115
  });
119
- await waitForNextUpdate();
116
+ await (0, _react.waitFor)(() => {});
120
117
  expect(dataProviderData.organisationUnits).toHaveBeenCalledWith('read', expect.objectContaining({
121
118
  params: expect.objectContaining({
122
119
  isUserDataViewFallback: undefined
@@ -128,12 +125,10 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
128
125
  const options = {
129
126
  isUserDataViewFallback: true
130
127
  };
131
- const {
132
- waitForNextUpdate
133
- } = (0, _reactHooks.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000'], options), {
128
+ (0, _react.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000'], options), {
134
129
  wrapper
135
130
  });
136
- await waitForNextUpdate();
131
+ await (0, _react.waitFor)(() => {});
137
132
  expect(dataProviderData.organisationUnits).toHaveBeenCalledWith('read', expect.objectContaining({
138
133
  params: expect.objectContaining({
139
134
  isUserDataViewFallback: true
@@ -154,27 +149,27 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
154
149
  let {
155
150
  children
156
151
  } = _ref3;
157
- return /*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
152
+ return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
158
153
  data: dataProviderDataWithoutDisplayName
159
154
  }, children);
160
155
  };
161
156
  const {
162
- result,
163
- waitForNextUpdate
164
- } = (0, _reactHooks.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000']), {
157
+ result
158
+ } = (0, _react.renderHook)(() => (0, _useRootOrgData.useRootOrgData)(['A0000000000']), {
165
159
  wrapper: wrapperWithoutDisplayName
166
160
  });
167
- await waitForNextUpdate();
168
- expect(result.current).toEqual(expect.objectContaining({
169
- loading: false,
170
- error: null,
171
- data: {
172
- A0000000000: {
173
- id: 'A0000000000',
174
- path: '/A0000000000',
175
- displayName: ''
161
+ await (0, _react.waitFor)(() => {
162
+ expect(result.current).toEqual(expect.objectContaining({
163
+ loading: false,
164
+ error: null,
165
+ data: {
166
+ A0000000000: {
167
+ id: 'A0000000000',
168
+ path: '/A0000000000',
169
+ displayName: ''
170
+ }
176
171
  }
177
- }
178
- }));
172
+ }));
173
+ });
179
174
  });
180
175
  });
@@ -1,4 +1,4 @@
1
- import { renderHook } from '@testing-library/react-hooks';
1
+ import { renderHook } from '@testing-library/react';
2
2
  import { useOpenState } from './use-open-state.js';
3
3
  describe('OrganisationUnitTree - useOpenState', () => {
4
4
  const onExpand = jest.fn();
@@ -1,5 +1,5 @@
1
1
  import { CustomDataProvider } from '@dhis2/app-runtime';
2
- import { renderHook } from '@testing-library/react-hooks';
2
+ import { renderHook, waitFor } from '@testing-library/react';
3
3
  import React from 'react';
4
4
  import { useOrgChildren } from './use-org-children.js';
5
5
  describe('OrganisationUnitTree - useOrgChildren', () => {
@@ -37,8 +37,7 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
37
37
  };
38
38
  it('should respond with `loading: true`, `error: null` and `data: null` initially', async () => {
39
39
  const {
40
- result,
41
- waitForNextUpdate
40
+ result
42
41
  } = renderHook(() => useOrgChildren({
43
42
  node
44
43
  }), {
@@ -54,28 +53,28 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
54
53
  // Prevent the following error log with
55
54
  // "Warning: An update to TestComponent inside a test was not wrapped
56
55
  // in act(...)."
57
- await waitForNextUpdate();
56
+ await waitFor(() => {});
58
57
  });
59
58
  it('should provide the org unit data', async () => {
60
59
  const {
61
- result,
62
- waitForNextUpdate
60
+ result
63
61
  } = renderHook(() => useOrgChildren({
64
62
  node
65
63
  }), {
66
64
  wrapper
67
65
  });
68
- await waitForNextUpdate();
69
- expect(result.current).toEqual({
70
- called: true,
71
- loading: false,
72
- error: null,
73
- data: [{
74
- id: 'A0000000001',
75
- path: '/A0000000000/A0000000001',
76
- children: [],
77
- displayName: 'Org Unit 2'
78
- }]
66
+ await waitFor(() => {
67
+ expect(result.current).toEqual({
68
+ called: true,
69
+ loading: false,
70
+ error: null,
71
+ data: [{
72
+ id: 'A0000000001',
73
+ path: '/A0000000000/A0000000001',
74
+ children: [],
75
+ displayName: 'Org Unit 2'
76
+ }]
77
+ });
79
78
  });
80
79
  });
81
80
  it('should provide the error', async () => {
@@ -92,19 +91,19 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
92
91
  }, children);
93
92
  };
94
93
  const {
95
- result,
96
- waitForNextUpdate
94
+ result
97
95
  } = renderHook(() => useOrgChildren({
98
96
  node
99
97
  }), {
100
98
  wrapper: errorWrapper
101
99
  });
102
- await waitForNextUpdate();
103
- expect(result.current).toEqual({
104
- called: true,
105
- loading: false,
106
- error: new Error('Error message'),
107
- data: undefined
100
+ await waitFor(() => {
101
+ expect(result.current).toEqual({
102
+ called: true,
103
+ loading: false,
104
+ error: new Error('Error message'),
105
+ data: undefined
106
+ });
108
107
  });
109
108
  });
110
109
  it('should call the onComplete callback', async () => {
@@ -113,22 +112,21 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
113
112
  onComplete,
114
113
  node
115
114
  };
116
- const {
117
- waitForNextUpdate
118
- } = renderHook(() => useOrgChildren(options), {
115
+ renderHook(() => useOrgChildren(options), {
119
116
  wrapper
120
117
  });
121
- await waitForNextUpdate();
122
- expect(onComplete).toHaveBeenCalledWith({
123
- id: 'A0000000000',
124
- path: '/A0000000000',
125
- displayName: 'Org Unit 1',
126
- children: [{
127
- id: 'A0000000001',
128
- path: '/A0000000000/A0000000001',
129
- children: [],
130
- displayName: 'Org Unit 2'
131
- }]
118
+ await waitFor(() => {
119
+ expect(onComplete).toHaveBeenCalledWith({
120
+ id: 'A0000000000',
121
+ path: '/A0000000000',
122
+ displayName: 'Org Unit 1',
123
+ children: [{
124
+ id: 'A0000000001',
125
+ path: '/A0000000000/A0000000001',
126
+ children: [],
127
+ displayName: 'Org Unit 2'
128
+ }]
129
+ });
132
130
  });
133
131
  });
134
132
  it("should sort the node's children alphabetically by default", async () => {
@@ -164,8 +162,7 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
164
162
  }, children);
165
163
  };
166
164
  const {
167
- result,
168
- waitForNextUpdate
165
+ result
169
166
  } = renderHook(() => useOrgChildren({
170
167
  node: {
171
168
  ...node,
@@ -174,22 +171,23 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
174
171
  }), {
175
172
  wrapper: wrapperWithUnsortedChildren
176
173
  });
177
- await waitForNextUpdate();
178
- expect(result.current).toEqual({
179
- called: true,
180
- loading: false,
181
- error: null,
182
- data: [{
183
- id: 'A0000000001',
184
- path: '/A0000000000/A0000000001',
185
- children: [],
186
- displayName: 'Org Unit 2'
187
- }, {
188
- id: 'A0000000002',
189
- path: '/A0000000000/A0000000002',
190
- children: [],
191
- displayName: 'Org Unit 3'
192
- }]
174
+ await waitFor(() => {
175
+ expect(result.current).toEqual({
176
+ called: true,
177
+ loading: false,
178
+ error: null,
179
+ data: [{
180
+ id: 'A0000000001',
181
+ path: '/A0000000000/A0000000001',
182
+ children: [],
183
+ displayName: 'Org Unit 2'
184
+ }, {
185
+ id: 'A0000000002',
186
+ path: '/A0000000000/A0000000002',
187
+ children: [],
188
+ displayName: 'Org Unit 3'
189
+ }]
190
+ });
193
191
  });
194
192
  });
195
193
  it(`should not sort the node's children alphabetically when "suppressAlphabeticalSorting" is true`, async () => {
@@ -232,27 +230,27 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
232
230
  suppressAlphabeticalSorting: true
233
231
  };
234
232
  const {
235
- result,
236
- waitForNextUpdate
233
+ result
237
234
  } = renderHook(() => useOrgChildren(options), {
238
235
  wrapper: wrapperWithUnsortedChildren
239
236
  });
240
- await waitForNextUpdate();
241
- expect(result.current).toEqual({
242
- called: true,
243
- loading: false,
244
- error: null,
245
- data: [{
246
- id: 'A0000000002',
247
- path: '/A0000000000/A0000000002',
248
- children: [],
249
- displayName: 'Org Unit 3'
250
- }, {
251
- id: 'A0000000001',
252
- path: '/A0000000000/A0000000001',
253
- children: [],
254
- displayName: 'Org Unit 2'
255
- }]
237
+ await waitFor(() => {
238
+ expect(result.current).toEqual({
239
+ called: true,
240
+ loading: false,
241
+ error: null,
242
+ data: [{
243
+ id: 'A0000000002',
244
+ path: '/A0000000000/A0000000002',
245
+ children: [],
246
+ displayName: 'Org Unit 3'
247
+ }, {
248
+ id: 'A0000000001',
249
+ path: '/A0000000000/A0000000001',
250
+ children: [],
251
+ displayName: 'Org Unit 2'
252
+ }]
253
+ });
256
254
  });
257
255
  });
258
256
  it(`should not sort the node's children alphabetically when "suppressAlphabeticalSorting" is true`, async () => {
@@ -295,27 +293,27 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
295
293
  suppressAlphabeticalSorting: true
296
294
  };
297
295
  const {
298
- result,
299
- waitForNextUpdate
296
+ result
300
297
  } = renderHook(() => useOrgChildren(options), {
301
298
  wrapper: wrapperWithUnsortedChildren
302
299
  });
303
- await waitForNextUpdate();
304
- expect(result.current).toEqual({
305
- called: true,
306
- loading: false,
307
- error: null,
308
- data: [{
309
- id: 'A0000000002',
310
- path: '/A0000000000/A0000000002',
311
- children: [],
312
- displayName: 'Org Unit 3'
313
- }, {
314
- id: 'A0000000001',
315
- path: '/A0000000000/A0000000001',
316
- children: [],
317
- displayName: 'Org Unit 2'
318
- }]
300
+ await waitFor(() => {
301
+ expect(result.current).toEqual({
302
+ called: true,
303
+ loading: false,
304
+ error: null,
305
+ data: [{
306
+ id: 'A0000000002',
307
+ path: '/A0000000000/A0000000002',
308
+ children: [],
309
+ displayName: 'Org Unit 3'
310
+ }, {
311
+ id: 'A0000000001',
312
+ path: '/A0000000000/A0000000001',
313
+ children: [],
314
+ displayName: 'Org Unit 2'
315
+ }]
316
+ });
319
317
  });
320
318
  });
321
319
  });
@@ -1,5 +1,5 @@
1
1
  import { CustomDataProvider } from '@dhis2/app-runtime';
2
- import { renderHook } from '@testing-library/react-hooks';
2
+ import { renderHook, waitFor } from '@testing-library/react';
3
3
  import React from 'react';
4
4
  import { useOrgData } from './use-org-data.js';
5
5
  describe('OrganisationUnitTree - useOrgData', () => {
@@ -59,22 +59,22 @@ describe('OrganisationUnitTree - useOrgData', () => {
59
59
  });
60
60
  it('should provide the org unit data', async () => {
61
61
  const {
62
- result,
63
- waitForNextUpdate
62
+ result
64
63
  } = renderHook(() => useOrgData('A0000000000', {
65
64
  displayName: 'Display name'
66
65
  }), {
67
66
  wrapper
68
67
  });
69
- await waitForNextUpdate();
70
- expect(result.current).toEqual({
71
- loading: false,
72
- error: null,
73
- data: {
74
- id: 'A0000000000',
75
- path: '/A0000000000',
76
- displayName: 'Org Unit 1'
77
- }
68
+ await waitFor(() => {
69
+ expect(result.current).toEqual({
70
+ loading: false,
71
+ error: null,
72
+ data: {
73
+ id: 'A0000000000',
74
+ path: '/A0000000000',
75
+ displayName: 'Org Unit 1'
76
+ }
77
+ });
78
78
  });
79
79
  });
80
80
  it('should provide the error', async () => {
@@ -91,56 +91,54 @@ describe('OrganisationUnitTree - useOrgData', () => {
91
91
  }, children);
92
92
  };
93
93
  const {
94
- result,
95
- waitForNextUpdate
94
+ result
96
95
  } = renderHook(() => useOrgData('A0000000000', {
97
96
  displayName: 'Display name'
98
97
  }), {
99
98
  wrapper: errorWrapper
100
99
  });
101
- await waitForNextUpdate();
102
- expect(result.current).toEqual({
103
- loading: false,
104
- error: new Error('Error message'),
105
- data: {
106
- displayName: 'Display name',
107
- id: 'A0000000000'
108
- }
100
+ await waitFor(() => {
101
+ expect(result.current).toEqual({
102
+ loading: false,
103
+ error: new Error('Error message'),
104
+ data: {
105
+ displayName: 'Display name',
106
+ id: 'A0000000000'
107
+ }
108
+ });
109
109
  });
110
110
  });
111
111
  it('should send the "isUserDataViewFallback" parameter with value "undefined"', async () => {
112
112
  const options = {
113
113
  displayName: 'Display name'
114
114
  };
115
- const {
116
- waitForNextUpdate
117
- } = renderHook(() => useOrgData('A0000000000', options), {
115
+ renderHook(() => useOrgData('A0000000000', options), {
118
116
  wrapper
119
117
  });
120
- await waitForNextUpdate();
121
- expect(dataProviderData.organisationUnits).toHaveBeenCalledWith('read', expect.objectContaining({
122
- params: expect.objectContaining({
123
- isUserDataViewFallback: undefined
124
- })
125
- }), expect.objectContaining({}) // contains the `signal`
126
- );
118
+ await waitFor(() => {
119
+ expect(dataProviderData.organisationUnits).toHaveBeenCalledWith('read', expect.objectContaining({
120
+ params: expect.objectContaining({
121
+ isUserDataViewFallback: undefined
122
+ })
123
+ }), expect.objectContaining({}) // contains the `signal`
124
+ );
125
+ });
127
126
  });
128
127
  it('should send the "isUserDataViewFallback" parameter with value "true"', async () => {
129
128
  const options = {
130
129
  isUserDataViewFallback: true,
131
130
  displayName: 'Display name'
132
131
  };
133
- const {
134
- waitForNextUpdate
135
- } = renderHook(() => useOrgData('A0000000000', options), {
132
+ renderHook(() => useOrgData('A0000000000', options), {
136
133
  wrapper
137
134
  });
138
- await waitForNextUpdate();
139
- expect(dataProviderData.organisationUnits).toHaveBeenCalledWith('read', expect.objectContaining({
140
- params: expect.objectContaining({
141
- isUserDataViewFallback: true
142
- })
143
- }), expect.objectContaining({}) // contains the `signal`
144
- );
135
+ await waitFor(() => {
136
+ expect(dataProviderData.organisationUnits).toHaveBeenCalledWith('read', expect.objectContaining({
137
+ params: expect.objectContaining({
138
+ isUserDataViewFallback: true
139
+ })
140
+ }), expect.objectContaining({}) // contains the `signal`
141
+ );
142
+ });
145
143
  });
146
144
  });
@@ -15,7 +15,7 @@ describe('OrganisationUnitTree', () => {
15
15
  describe('Controlled expanded props', () => {
16
16
  describe('Missing props', () => {
17
17
  it('should throw a prop-types error when "handleCollapse" is missing', () => {
18
- shallow( /*#__PURE__*/React.createElement(CustomDataProvider, {
18
+ shallow(/*#__PURE__*/React.createElement(CustomDataProvider, {
19
19
  data: {}
20
20
  }, /*#__PURE__*/React.createElement(OrganisationUnitTree, {
21
21
  roots: "/A001",
@@ -24,10 +24,10 @@ describe('OrganisationUnitTree', () => {
24
24
  handleExpand: () => {}
25
25
  })));
26
26
  expect(errorMock).toHaveBeenCalledTimes(1);
27
- expect(errorMock.mock.calls[0][0]).toMatch(/^Warning: Failed prop type: Invalid prop `handleCollapse` supplied to `OrganisationUnitTree`/);
27
+ expect(errorMock.mock.calls[0][2]).toMatch(/Invalid prop `handleCollapse` supplied to `OrganisationUnitTree`/, {});
28
28
  });
29
29
  it('should throw a prop-types error when "handleExpand" is missing', () => {
30
- shallow( /*#__PURE__*/React.createElement(CustomDataProvider, {
30
+ shallow(/*#__PURE__*/React.createElement(CustomDataProvider, {
31
31
  data: {}
32
32
  }, /*#__PURE__*/React.createElement(OrganisationUnitTree, {
33
33
  roots: "/A001",
@@ -36,10 +36,10 @@ describe('OrganisationUnitTree', () => {
36
36
  handleCollapse: () => {}
37
37
  })));
38
38
  expect(errorMock).toHaveBeenCalledTimes(1);
39
- expect(errorMock.mock.calls[0][0]).toMatch(/^Warning: Failed prop type: Invalid prop `handleExpand` supplied to `OrganisationUnitTree`/);
39
+ expect(errorMock.mock.calls[0][2]).toMatch(/Invalid prop `handleExpand` supplied to `OrganisationUnitTree`/);
40
40
  });
41
41
  it('should throw a prop-types error when "expanded" is missing', () => {
42
- shallow( /*#__PURE__*/React.createElement(CustomDataProvider, {
42
+ shallow(/*#__PURE__*/React.createElement(CustomDataProvider, {
43
43
  data: {}
44
44
  }, /*#__PURE__*/React.createElement(OrganisationUnitTree, {
45
45
  roots: "/A001",
@@ -48,7 +48,7 @@ describe('OrganisationUnitTree', () => {
48
48
  handleExpand: () => {}
49
49
  })));
50
50
  expect(errorMock).toHaveBeenCalledTimes(1);
51
- expect(errorMock.mock.calls[0][0]).toMatch(/^Warning: Failed prop type: Invalid prop `expanded` supplied to `OrganisationUnitTree`/);
51
+ expect(errorMock.mock.calls[0][2]).toMatch('Invalid prop `expanded` supplied to `OrganisationUnitTree`, this prop is conditionally required but has value `undefined`. The condition that made this prop required is: `props => !!props.handleExpand || !!props.handleCollapse`.');
52
52
  });
53
53
  });
54
54
  });