@dhis2-ui/organisation-unit-tree 9.12.0-alpha.4 → 9.13.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/build/cjs/organisation-unit-node/use-open-state.test.js +8 -8
- package/build/cjs/organisation-unit-node/use-org-children.test.js +103 -105
- package/build/cjs/organisation-unit-node/use-org-data/use-org-data.test.js +46 -48
- package/build/cjs/organisation-unit-tree/organisation-unit-tree-root-error.js +1 -4
- package/build/cjs/organisation-unit-tree/organisation-unit-tree-root-loading.js +1 -4
- package/build/cjs/organisation-unit-tree/organisation-unit-tree.js +8 -14
- package/build/cjs/organisation-unit-tree/organisation-unit-tree.test.js +6 -6
- package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +36 -41
- package/build/es/organisation-unit-node/use-open-state.test.js +1 -1
- package/build/es/organisation-unit-node/use-org-children.test.js +91 -93
- package/build/es/organisation-unit-node/use-org-data/use-org-data.test.js +40 -42
- package/build/es/organisation-unit-tree/organisation-unit-tree-root-error.js +1 -4
- package/build/es/organisation-unit-tree/organisation-unit-tree-root-loading.js +1 -4
- package/build/es/organisation-unit-tree/organisation-unit-tree.js +9 -14
- package/build/es/organisation-unit-tree/organisation-unit-tree.test.js +6 -6
- package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +28 -33
- package/package.json +10 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
4
|
var _useOpenState = require("./use-open-state.js");
|
|
5
5
|
describe('OrganisationUnitTree - useOpenState', () => {
|
|
6
6
|
const onExpand = jest.fn();
|
|
@@ -15,7 +15,7 @@ describe('OrganisationUnitTree - useOpenState', () => {
|
|
|
15
15
|
const expected = false;
|
|
16
16
|
const {
|
|
17
17
|
result
|
|
18
|
-
} = (0,
|
|
18
|
+
} = (0, _react.renderHook)(() => (0, _useOpenState.useOpenState)({
|
|
19
19
|
path,
|
|
20
20
|
expanded
|
|
21
21
|
}));
|
|
@@ -30,7 +30,7 @@ describe('OrganisationUnitTree - useOpenState', () => {
|
|
|
30
30
|
const expected = true;
|
|
31
31
|
const {
|
|
32
32
|
result
|
|
33
|
-
} = (0,
|
|
33
|
+
} = (0, _react.renderHook)(() => (0, _useOpenState.useOpenState)({
|
|
34
34
|
path,
|
|
35
35
|
expanded
|
|
36
36
|
}));
|
|
@@ -44,7 +44,7 @@ describe('OrganisationUnitTree - useOpenState', () => {
|
|
|
44
44
|
const expanded = ['/foo'];
|
|
45
45
|
const {
|
|
46
46
|
result
|
|
47
|
-
} = (0,
|
|
47
|
+
} = (0, _react.renderHook)(() => (0, _useOpenState.useOpenState)({
|
|
48
48
|
path,
|
|
49
49
|
expanded,
|
|
50
50
|
onCollapse
|
|
@@ -63,7 +63,7 @@ describe('OrganisationUnitTree - useOpenState', () => {
|
|
|
63
63
|
const expanded = [];
|
|
64
64
|
const {
|
|
65
65
|
result
|
|
66
|
-
} = (0,
|
|
66
|
+
} = (0, _react.renderHook)(() => (0, _useOpenState.useOpenState)({
|
|
67
67
|
path,
|
|
68
68
|
expanded,
|
|
69
69
|
onExpand
|
|
@@ -81,7 +81,7 @@ describe('OrganisationUnitTree - useOpenState', () => {
|
|
|
81
81
|
const path = '/foo';
|
|
82
82
|
const {
|
|
83
83
|
result
|
|
84
|
-
} = (0,
|
|
84
|
+
} = (0, _react.renderHook)(() => (0, _useOpenState.useOpenState)({
|
|
85
85
|
autoExpandLoadingError: true,
|
|
86
86
|
errorMessage: 'error message',
|
|
87
87
|
path,
|
|
@@ -98,7 +98,7 @@ describe('OrganisationUnitTree - useOpenState', () => {
|
|
|
98
98
|
const path = '/foo';
|
|
99
99
|
const {
|
|
100
100
|
result
|
|
101
|
-
} = (0,
|
|
101
|
+
} = (0, _react.renderHook)(() => (0, _useOpenState.useOpenState)({
|
|
102
102
|
autoExpandLoadingError: undefined,
|
|
103
103
|
errorMessage: 'error message',
|
|
104
104
|
path,
|
|
@@ -115,7 +115,7 @@ describe('OrganisationUnitTree - useOpenState', () => {
|
|
|
115
115
|
const path = '/foo';
|
|
116
116
|
const {
|
|
117
117
|
result
|
|
118
|
-
} = (0,
|
|
118
|
+
} = (0, _react.renderHook)(() => (0, _useOpenState.useOpenState)({
|
|
119
119
|
autoExpandLoadingError: true,
|
|
120
120
|
errorMessage: '',
|
|
121
121
|
path,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _appRuntime = require("@dhis2/app-runtime");
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
5
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
6
6
|
var _useOrgChildren = require("./use-org-children.js");
|
|
7
7
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
8
|
describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
@@ -28,7 +28,7 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
28
28
|
let {
|
|
29
29
|
children
|
|
30
30
|
} = _ref2;
|
|
31
|
-
return /*#__PURE__*/
|
|
31
|
+
return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
|
|
32
32
|
data: dataProviderData
|
|
33
33
|
}, children);
|
|
34
34
|
};
|
|
@@ -40,9 +40,8 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
40
40
|
};
|
|
41
41
|
it('should respond with `loading: true`, `error: null` and `data: null` initially', async () => {
|
|
42
42
|
const {
|
|
43
|
-
result
|
|
44
|
-
|
|
45
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useOrgChildren.useOrgChildren)({
|
|
43
|
+
result
|
|
44
|
+
} = (0, _react.renderHook)(() => (0, _useOrgChildren.useOrgChildren)({
|
|
46
45
|
node
|
|
47
46
|
}), {
|
|
48
47
|
wrapper
|
|
@@ -57,28 +56,28 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
57
56
|
// Prevent the following error log with
|
|
58
57
|
// "Warning: An update to TestComponent inside a test was not wrapped
|
|
59
58
|
// in act(...)."
|
|
60
|
-
await
|
|
59
|
+
await (0, _react.waitFor)(() => {});
|
|
61
60
|
});
|
|
62
61
|
it('should provide the org unit data', async () => {
|
|
63
62
|
const {
|
|
64
|
-
result
|
|
65
|
-
|
|
66
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useOrgChildren.useOrgChildren)({
|
|
63
|
+
result
|
|
64
|
+
} = (0, _react.renderHook)(() => (0, _useOrgChildren.useOrgChildren)({
|
|
67
65
|
node
|
|
68
66
|
}), {
|
|
69
67
|
wrapper
|
|
70
68
|
});
|
|
71
|
-
await
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
await (0, _react.waitFor)(() => {
|
|
70
|
+
expect(result.current).toEqual({
|
|
71
|
+
called: true,
|
|
72
|
+
loading: false,
|
|
73
|
+
error: null,
|
|
74
|
+
data: [{
|
|
75
|
+
id: 'A0000000001',
|
|
76
|
+
path: '/A0000000000/A0000000001',
|
|
77
|
+
children: [],
|
|
78
|
+
displayName: 'Org Unit 2'
|
|
79
|
+
}]
|
|
80
|
+
});
|
|
82
81
|
});
|
|
83
82
|
});
|
|
84
83
|
it('should provide the error', async () => {
|
|
@@ -86,7 +85,7 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
86
85
|
let {
|
|
87
86
|
children
|
|
88
87
|
} = _ref3;
|
|
89
|
-
return /*#__PURE__*/
|
|
88
|
+
return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
|
|
90
89
|
data: {
|
|
91
90
|
organisationUnits: async () => {
|
|
92
91
|
throw new Error('Error message');
|
|
@@ -95,19 +94,19 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
95
94
|
}, children);
|
|
96
95
|
};
|
|
97
96
|
const {
|
|
98
|
-
result
|
|
99
|
-
|
|
100
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useOrgChildren.useOrgChildren)({
|
|
97
|
+
result
|
|
98
|
+
} = (0, _react.renderHook)(() => (0, _useOrgChildren.useOrgChildren)({
|
|
101
99
|
node
|
|
102
100
|
}), {
|
|
103
101
|
wrapper: errorWrapper
|
|
104
102
|
});
|
|
105
|
-
await
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
103
|
+
await (0, _react.waitFor)(() => {
|
|
104
|
+
expect(result.current).toEqual({
|
|
105
|
+
called: true,
|
|
106
|
+
loading: false,
|
|
107
|
+
error: new Error('Error message'),
|
|
108
|
+
data: undefined
|
|
109
|
+
});
|
|
111
110
|
});
|
|
112
111
|
});
|
|
113
112
|
it('should call the onComplete callback', async () => {
|
|
@@ -116,22 +115,21 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
116
115
|
onComplete,
|
|
117
116
|
node
|
|
118
117
|
};
|
|
119
|
-
|
|
120
|
-
waitForNextUpdate
|
|
121
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useOrgChildren.useOrgChildren)(options), {
|
|
118
|
+
(0, _react.renderHook)(() => (0, _useOrgChildren.useOrgChildren)(options), {
|
|
122
119
|
wrapper
|
|
123
120
|
});
|
|
124
|
-
await
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
121
|
+
await (0, _react.waitFor)(() => {
|
|
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
|
+
}]
|
|
132
|
+
});
|
|
135
133
|
});
|
|
136
134
|
});
|
|
137
135
|
it("should sort the node's children alphabetically by default", async () => {
|
|
@@ -162,14 +160,13 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
162
160
|
let {
|
|
163
161
|
children
|
|
164
162
|
} = _ref5;
|
|
165
|
-
return /*#__PURE__*/
|
|
163
|
+
return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
|
|
166
164
|
data: dataProviderDataWithUnsortedChildren
|
|
167
165
|
}, children);
|
|
168
166
|
};
|
|
169
167
|
const {
|
|
170
|
-
result
|
|
171
|
-
|
|
172
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useOrgChildren.useOrgChildren)({
|
|
168
|
+
result
|
|
169
|
+
} = (0, _react.renderHook)(() => (0, _useOrgChildren.useOrgChildren)({
|
|
173
170
|
node: {
|
|
174
171
|
...node,
|
|
175
172
|
children: 2
|
|
@@ -177,22 +174,23 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
177
174
|
}), {
|
|
178
175
|
wrapper: wrapperWithUnsortedChildren
|
|
179
176
|
});
|
|
180
|
-
await
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
177
|
+
await (0, _react.waitFor)(() => {
|
|
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
|
+
}]
|
|
193
|
+
});
|
|
196
194
|
});
|
|
197
195
|
});
|
|
198
196
|
it(`should not sort the node's children alphabetically when "suppressAlphabeticalSorting" is true`, async () => {
|
|
@@ -223,7 +221,7 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
223
221
|
let {
|
|
224
222
|
children
|
|
225
223
|
} = _ref7;
|
|
226
|
-
return /*#__PURE__*/
|
|
224
|
+
return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
|
|
227
225
|
data: dataProviderDataWithUnsortedChildren
|
|
228
226
|
}, children);
|
|
229
227
|
};
|
|
@@ -235,27 +233,27 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
235
233
|
suppressAlphabeticalSorting: true
|
|
236
234
|
};
|
|
237
235
|
const {
|
|
238
|
-
result
|
|
239
|
-
|
|
240
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useOrgChildren.useOrgChildren)(options), {
|
|
236
|
+
result
|
|
237
|
+
} = (0, _react.renderHook)(() => (0, _useOrgChildren.useOrgChildren)(options), {
|
|
241
238
|
wrapper: wrapperWithUnsortedChildren
|
|
242
239
|
});
|
|
243
|
-
await
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
240
|
+
await (0, _react.waitFor)(() => {
|
|
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
|
+
}]
|
|
256
|
+
});
|
|
259
257
|
});
|
|
260
258
|
});
|
|
261
259
|
it(`should not sort the node's children alphabetically when "suppressAlphabeticalSorting" is true`, async () => {
|
|
@@ -286,7 +284,7 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
286
284
|
let {
|
|
287
285
|
children
|
|
288
286
|
} = _ref9;
|
|
289
|
-
return /*#__PURE__*/
|
|
287
|
+
return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
|
|
290
288
|
data: dataProviderDataWithUnsortedChildren
|
|
291
289
|
}, children);
|
|
292
290
|
};
|
|
@@ -298,27 +296,27 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
298
296
|
suppressAlphabeticalSorting: true
|
|
299
297
|
};
|
|
300
298
|
const {
|
|
301
|
-
result
|
|
302
|
-
|
|
303
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useOrgChildren.useOrgChildren)(options), {
|
|
299
|
+
result
|
|
300
|
+
} = (0, _react.renderHook)(() => (0, _useOrgChildren.useOrgChildren)(options), {
|
|
304
301
|
wrapper: wrapperWithUnsortedChildren
|
|
305
302
|
});
|
|
306
|
-
await
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
303
|
+
await (0, _react.waitFor)(() => {
|
|
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
|
+
}]
|
|
319
|
+
});
|
|
322
320
|
});
|
|
323
321
|
});
|
|
324
322
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _appRuntime = require("@dhis2/app-runtime");
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
5
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
6
6
|
var _useOrgData = require("./use-org-data.js");
|
|
7
7
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
8
|
describe('OrganisationUnitTree - useOrgData', () => {
|
|
@@ -39,14 +39,14 @@ describe('OrganisationUnitTree - useOrgData', () => {
|
|
|
39
39
|
let {
|
|
40
40
|
children
|
|
41
41
|
} = _ref2;
|
|
42
|
-
return /*#__PURE__*/
|
|
42
|
+
return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
|
|
43
43
|
data: dataProviderData
|
|
44
44
|
}, children);
|
|
45
45
|
};
|
|
46
46
|
it('should respond with `loading: true`, `error: null` and `data: { displayName, id }` initially', () => {
|
|
47
47
|
const {
|
|
48
48
|
result
|
|
49
|
-
} = (0,
|
|
49
|
+
} = (0, _react.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', {
|
|
50
50
|
displayName: 'Display name'
|
|
51
51
|
}), {
|
|
52
52
|
wrapper
|
|
@@ -62,22 +62,22 @@ describe('OrganisationUnitTree - useOrgData', () => {
|
|
|
62
62
|
});
|
|
63
63
|
it('should provide the org unit data', async () => {
|
|
64
64
|
const {
|
|
65
|
-
result
|
|
66
|
-
|
|
67
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', {
|
|
65
|
+
result
|
|
66
|
+
} = (0, _react.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', {
|
|
68
67
|
displayName: 'Display name'
|
|
69
68
|
}), {
|
|
70
69
|
wrapper
|
|
71
70
|
});
|
|
72
|
-
await
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
await (0, _react.waitFor)(() => {
|
|
72
|
+
expect(result.current).toEqual({
|
|
73
|
+
loading: false,
|
|
74
|
+
error: null,
|
|
75
|
+
data: {
|
|
76
|
+
id: 'A0000000000',
|
|
77
|
+
path: '/A0000000000',
|
|
78
|
+
displayName: 'Org Unit 1'
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
81
|
});
|
|
82
82
|
});
|
|
83
83
|
it('should provide the error', async () => {
|
|
@@ -85,7 +85,7 @@ describe('OrganisationUnitTree - useOrgData', () => {
|
|
|
85
85
|
let {
|
|
86
86
|
children
|
|
87
87
|
} = _ref3;
|
|
88
|
-
return /*#__PURE__*/
|
|
88
|
+
return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
|
|
89
89
|
data: {
|
|
90
90
|
organisationUnits: async () => {
|
|
91
91
|
throw new Error('Error message');
|
|
@@ -94,56 +94,54 @@ describe('OrganisationUnitTree - useOrgData', () => {
|
|
|
94
94
|
}, children);
|
|
95
95
|
};
|
|
96
96
|
const {
|
|
97
|
-
result
|
|
98
|
-
|
|
99
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', {
|
|
97
|
+
result
|
|
98
|
+
} = (0, _react.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', {
|
|
100
99
|
displayName: 'Display name'
|
|
101
100
|
}), {
|
|
102
101
|
wrapper: errorWrapper
|
|
103
102
|
});
|
|
104
|
-
await
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
await (0, _react.waitFor)(() => {
|
|
104
|
+
expect(result.current).toEqual({
|
|
105
|
+
loading: false,
|
|
106
|
+
error: new Error('Error message'),
|
|
107
|
+
data: {
|
|
108
|
+
displayName: 'Display name',
|
|
109
|
+
id: 'A0000000000'
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
112
|
});
|
|
113
113
|
});
|
|
114
114
|
it('should send the "isUserDataViewFallback" parameter with value "undefined"', async () => {
|
|
115
115
|
const options = {
|
|
116
116
|
displayName: 'Display name'
|
|
117
117
|
};
|
|
118
|
-
|
|
119
|
-
waitForNextUpdate
|
|
120
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', options), {
|
|
118
|
+
(0, _react.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', options), {
|
|
121
119
|
wrapper
|
|
122
120
|
});
|
|
123
|
-
await
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
121
|
+
await (0, _react.waitFor)(() => {
|
|
122
|
+
expect(dataProviderData.organisationUnits).toHaveBeenCalledWith('read', expect.objectContaining({
|
|
123
|
+
params: expect.objectContaining({
|
|
124
|
+
isUserDataViewFallback: undefined
|
|
125
|
+
})
|
|
126
|
+
}), expect.objectContaining({}) // contains the `signal`
|
|
127
|
+
);
|
|
128
|
+
});
|
|
130
129
|
});
|
|
131
130
|
it('should send the "isUserDataViewFallback" parameter with value "true"', async () => {
|
|
132
131
|
const options = {
|
|
133
132
|
isUserDataViewFallback: true,
|
|
134
133
|
displayName: 'Display name'
|
|
135
134
|
};
|
|
136
|
-
|
|
137
|
-
waitForNextUpdate
|
|
138
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', options), {
|
|
135
|
+
(0, _react.renderHook)(() => (0, _useOrgData.useOrgData)('A0000000000', options), {
|
|
139
136
|
wrapper
|
|
140
137
|
});
|
|
141
|
-
await
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
138
|
+
await (0, _react.waitFor)(() => {
|
|
139
|
+
expect(dataProviderData.organisationUnits).toHaveBeenCalledWith('read', expect.objectContaining({
|
|
140
|
+
params: expect.objectContaining({
|
|
141
|
+
isUserDataViewFallback: true
|
|
142
|
+
})
|
|
143
|
+
}), expect.objectContaining({}) // contains the `signal`
|
|
144
|
+
);
|
|
145
|
+
});
|
|
148
146
|
});
|
|
149
147
|
});
|
|
@@ -10,7 +10,7 @@ var _index = _interopRequireDefault(require("../locales/index.js"));
|
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
const OrganisationUnitTreeRootError = _ref => {
|
|
12
12
|
let {
|
|
13
|
-
dataTest,
|
|
13
|
+
dataTest = 'dhis2-uiwidgets-orgunittree-error',
|
|
14
14
|
error
|
|
15
15
|
} = _ref;
|
|
16
16
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -21,9 +21,6 @@ const OrganisationUnitTreeRootError = _ref => {
|
|
|
21
21
|
}));
|
|
22
22
|
};
|
|
23
23
|
exports.OrganisationUnitTreeRootError = OrganisationUnitTreeRootError;
|
|
24
|
-
OrganisationUnitTreeRootError.defaultProps = {
|
|
25
|
-
dataTest: 'dhis2-uiwidgets-orgunittree-error'
|
|
26
|
-
};
|
|
27
24
|
OrganisationUnitTreeRootError.propTypes = {
|
|
28
25
|
error: _propTypes.default.string.isRequired,
|
|
29
26
|
dataTest: _propTypes.default.string
|
|
@@ -11,7 +11,7 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
const OrganisationUnitTreeRootLoading = _ref => {
|
|
13
13
|
let {
|
|
14
|
-
dataTest
|
|
14
|
+
dataTest = 'dhis2-uiwidgets-orgunittree-loading'
|
|
15
15
|
} = _ref;
|
|
16
16
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
17
17
|
"data-test": dataTest,
|
|
@@ -23,9 +23,6 @@ const OrganisationUnitTreeRootLoading = _ref => {
|
|
|
23
23
|
}, ["div.jsx-814846266{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}"]));
|
|
24
24
|
};
|
|
25
25
|
exports.OrganisationUnitTreeRootLoading = OrganisationUnitTreeRootLoading;
|
|
26
|
-
OrganisationUnitTreeRootLoading.defaultProps = {
|
|
27
|
-
dataTest: 'dhis2-uiwidgets-orgunittree-loading'
|
|
28
|
-
};
|
|
29
26
|
OrganisationUnitTreeRootLoading.propTypes = {
|
|
30
27
|
dataTest: _propTypes.default.string
|
|
31
28
|
};
|
|
@@ -19,20 +19,22 @@ var _index4 = require("./use-root-org-data/index.js");
|
|
|
19
19
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
20
20
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
21
21
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
|
+
// A stable object to reference
|
|
23
|
+
const staticArray = [];
|
|
22
24
|
const OrganisationUnitTree = _ref => {
|
|
23
25
|
let {
|
|
24
26
|
onChange,
|
|
25
27
|
roots,
|
|
26
28
|
autoExpandLoadingError,
|
|
27
|
-
dataTest,
|
|
29
|
+
dataTest = 'dhis2-uiwidgets-orgunittree',
|
|
28
30
|
disableSelection,
|
|
29
31
|
forceReload,
|
|
30
|
-
highlighted,
|
|
32
|
+
highlighted = staticArray,
|
|
31
33
|
isUserDataViewFallback,
|
|
32
|
-
initiallyExpanded,
|
|
33
|
-
filter,
|
|
34
|
-
renderNodeLabel,
|
|
35
|
-
selected,
|
|
34
|
+
initiallyExpanded = staticArray,
|
|
35
|
+
filter = staticArray,
|
|
36
|
+
renderNodeLabel = _index2.defaultRenderNodeLabel,
|
|
37
|
+
selected = staticArray,
|
|
36
38
|
singleSelection,
|
|
37
39
|
suppressAlphabeticalSorting,
|
|
38
40
|
expanded: expandedControlled,
|
|
@@ -200,12 +202,4 @@ OrganisationUnitTree.propTypes = {
|
|
|
200
202
|
* we'd have to reload the sibling nodes currently as well)
|
|
201
203
|
*/
|
|
202
204
|
//idsThatShouldBeReloaded: propTypes.arrayOf(orgUnitIdPropType),
|
|
203
|
-
};
|
|
204
|
-
OrganisationUnitTree.defaultProps = {
|
|
205
|
-
dataTest: 'dhis2-uiwidgets-orgunittree',
|
|
206
|
-
filter: [],
|
|
207
|
-
highlighted: [],
|
|
208
|
-
initiallyExpanded: [],
|
|
209
|
-
selected: [],
|
|
210
|
-
renderNodeLabel: _index2.defaultRenderNodeLabel
|
|
211
205
|
};
|
|
@@ -18,7 +18,7 @@ describe('OrganisationUnitTree', () => {
|
|
|
18
18
|
describe('Controlled expanded props', () => {
|
|
19
19
|
describe('Missing props', () => {
|
|
20
20
|
it('should throw a prop-types error when "handleCollapse" is missing', () => {
|
|
21
|
-
(0, _enzyme.shallow)(
|
|
21
|
+
(0, _enzyme.shallow)(/*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
|
|
22
22
|
data: {}
|
|
23
23
|
}, /*#__PURE__*/_react.default.createElement(_organisationUnitTree.OrganisationUnitTree, {
|
|
24
24
|
roots: "/A001",
|
|
@@ -27,10 +27,10 @@ describe('OrganisationUnitTree', () => {
|
|
|
27
27
|
handleExpand: () => {}
|
|
28
28
|
})));
|
|
29
29
|
expect(errorMock).toHaveBeenCalledTimes(1);
|
|
30
|
-
expect(errorMock.mock.calls[0][
|
|
30
|
+
expect(errorMock.mock.calls[0][2]).toMatch(/Invalid prop `handleCollapse` supplied to `OrganisationUnitTree`/, {});
|
|
31
31
|
});
|
|
32
32
|
it('should throw a prop-types error when "handleExpand" is missing', () => {
|
|
33
|
-
(0, _enzyme.shallow)(
|
|
33
|
+
(0, _enzyme.shallow)(/*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
|
|
34
34
|
data: {}
|
|
35
35
|
}, /*#__PURE__*/_react.default.createElement(_organisationUnitTree.OrganisationUnitTree, {
|
|
36
36
|
roots: "/A001",
|
|
@@ -39,10 +39,10 @@ describe('OrganisationUnitTree', () => {
|
|
|
39
39
|
handleCollapse: () => {}
|
|
40
40
|
})));
|
|
41
41
|
expect(errorMock).toHaveBeenCalledTimes(1);
|
|
42
|
-
expect(errorMock.mock.calls[0][
|
|
42
|
+
expect(errorMock.mock.calls[0][2]).toMatch(/Invalid prop `handleExpand` supplied to `OrganisationUnitTree`/);
|
|
43
43
|
});
|
|
44
44
|
it('should throw a prop-types error when "expanded" is missing', () => {
|
|
45
|
-
(0, _enzyme.shallow)(
|
|
45
|
+
(0, _enzyme.shallow)(/*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
|
|
46
46
|
data: {}
|
|
47
47
|
}, /*#__PURE__*/_react.default.createElement(_organisationUnitTree.OrganisationUnitTree, {
|
|
48
48
|
roots: "/A001",
|
|
@@ -51,7 +51,7 @@ describe('OrganisationUnitTree', () => {
|
|
|
51
51
|
handleExpand: () => {}
|
|
52
52
|
})));
|
|
53
53
|
expect(errorMock).toHaveBeenCalledTimes(1);
|
|
54
|
-
expect(errorMock.mock.calls[0][
|
|
54
|
+
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`.');
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
});
|