@dhis2-ui/organisation-unit-tree 10.16.3 → 10.16.5
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/__e2e__/children_as_child_nodes.js +8 -11
- package/build/cjs/__e2e__/common.js +19 -26
- package/build/cjs/__e2e__/controlled_expanded.js +7 -10
- package/build/cjs/__e2e__/displaying_loading_error.js +1 -4
- package/build/cjs/__e2e__/expanded.js +25 -34
- package/build/cjs/__e2e__/force_reload.js +15 -22
- package/build/cjs/__e2e__/get-organisation-unit-data.js +25 -29
- package/build/cjs/__e2e__/highlight.js +7 -10
- package/build/cjs/__e2e__/loading_state.js +7 -13
- package/build/cjs/__e2e__/multi_selection.js +8 -11
- package/build/cjs/__e2e__/no_selection.js +15 -21
- package/build/cjs/__e2e__/path_based_filtering.js +16 -22
- package/build/cjs/__e2e__/single_selection.js +10 -16
- package/build/cjs/__e2e__/sub_unit_as_root.js +5 -7
- package/build/cjs/__e2e__/tree_api.js +15 -21
- package/build/cjs/__stories__/custom-expanded-imperative-open.js +7 -10
- package/build/cjs/__stories__/custom-node-label.js +4 -5
- package/build/cjs/__stories__/development-stories.js +6 -8
- package/build/cjs/__stories__/force-reload-all.js +1 -2
- package/build/cjs/__stories__/loading-error-grandchild.js +1 -4
- package/build/cjs/__stories__/loading.js +1 -4
- package/build/cjs/__stories__/multiple-roots.js +9 -12
- package/build/cjs/__stories__/root-error.js +1 -4
- package/build/cjs/__stories__/root-loading.js +1 -4
- package/build/cjs/__stories__/shared.js +46 -79
- package/build/cjs/features/controlled_expanded/index.js +3 -6
- package/build/cjs/locales/index.js +49 -27
- package/build/cjs/organisation-unit-node/error-message.js +10 -13
- package/build/cjs/organisation-unit-node/label/disabled-selection-label.js +9 -12
- package/build/cjs/organisation-unit-node/label/icon-empty.js +19 -22
- package/build/cjs/organisation-unit-node/label/icon-folder-closed.js +25 -28
- package/build/cjs/organisation-unit-node/label/icon-folder-open.js +34 -37
- package/build/cjs/organisation-unit-node/label/icon-single.js +28 -31
- package/build/cjs/organisation-unit-node/label/icon.js +6 -7
- package/build/cjs/organisation-unit-node/label/iconized-checkbox.js +12 -13
- package/build/cjs/organisation-unit-node/label/label-container.js +13 -16
- package/build/cjs/organisation-unit-node/label/label.js +27 -30
- package/build/cjs/organisation-unit-node/label/single-selection-label.js +18 -21
- package/build/cjs/organisation-unit-node/organisation-unit-node-children.js +27 -29
- package/build/cjs/organisation-unit-node/organisation-unit-node.js +22 -23
- package/build/cjs/organisation-unit-node/use-open-state.js +8 -9
- package/build/cjs/organisation-unit-node/use-org-children.js +14 -21
- package/build/cjs/organisation-unit-node/use-org-children.test.js +40 -59
- package/build/cjs/organisation-unit-node/use-org-data/use-org-data.js +13 -20
- package/build/cjs/organisation-unit-node/use-org-data/use-org-data.test.js +17 -27
- package/build/cjs/organisation-unit-tree/default-render-node-label/default-render-node-label.js +3 -6
- package/build/cjs/organisation-unit-tree/organisation-unit-tree-root-error.js +9 -12
- package/build/cjs/organisation-unit-tree/organisation-unit-tree-root-loading.js +10 -13
- package/build/cjs/organisation-unit-tree/organisation-unit-tree.js +41 -35
- package/build/cjs/organisation-unit-tree/organisation-unit-tree.test.js +78 -7
- package/build/cjs/organisation-unit-tree/use-expanded/create-expand-handlers.js +14 -17
- package/build/cjs/organisation-unit-tree/use-expanded/use-expanded.js +8 -9
- package/build/cjs/organisation-unit-tree/use-root-org-data/patch-missing-display-name.js +1 -2
- package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-data.js +10 -14
- package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +32 -46
- package/build/es/__e2e__/children_as_child_nodes.js +8 -11
- package/build/es/__e2e__/common.js +18 -24
- package/build/es/__e2e__/controlled_expanded.js +6 -8
- package/build/es/__e2e__/displaying_loading_error.js +1 -4
- package/build/es/__e2e__/expanded.js +25 -34
- package/build/es/__e2e__/force_reload.js +14 -20
- package/build/es/__e2e__/get-organisation-unit-data.js +25 -29
- package/build/es/__e2e__/highlight.js +7 -10
- package/build/es/__e2e__/loading_state.js +7 -13
- package/build/es/__e2e__/multi_selection.js +8 -11
- package/build/es/__e2e__/no_selection.js +15 -21
- package/build/es/__e2e__/path_based_filtering.js +16 -22
- package/build/es/__e2e__/single_selection.js +10 -16
- package/build/es/__e2e__/sub_unit_as_root.js +4 -5
- package/build/es/__e2e__/tree_api.js +15 -21
- package/build/es/__stories__/custom-expanded-imperative-open.js +6 -8
- package/build/es/__stories__/custom-node-label.js +4 -5
- package/build/es/__stories__/development-stories.js +5 -6
- package/build/es/__stories__/loading-error-grandchild.js +1 -4
- package/build/es/__stories__/loading.js +1 -4
- package/build/es/__stories__/multiple-roots.js +9 -12
- package/build/es/__stories__/root-error.js +1 -4
- package/build/es/__stories__/root-loading.js +1 -4
- package/build/es/__stories__/shared.js +45 -77
- package/build/es/features/controlled_expanded/index.js +3 -6
- package/build/es/locales/index.js +40 -18
- package/build/es/organisation-unit-node/error-message.js +10 -13
- package/build/es/organisation-unit-node/label/disabled-selection-label.js +9 -12
- package/build/es/organisation-unit-node/label/icon-empty.js +19 -22
- package/build/es/organisation-unit-node/label/icon-folder-closed.js +25 -28
- package/build/es/organisation-unit-node/label/icon-folder-open.js +34 -37
- package/build/es/organisation-unit-node/label/icon-single.js +28 -31
- package/build/es/organisation-unit-node/label/icon.js +6 -7
- package/build/es/organisation-unit-node/label/iconized-checkbox.js +12 -13
- package/build/es/organisation-unit-node/label/label-container.js +13 -16
- package/build/es/organisation-unit-node/label/label.js +27 -30
- package/build/es/organisation-unit-node/label/single-selection-label.js +18 -21
- package/build/es/organisation-unit-node/organisation-unit-node-children.js +27 -29
- package/build/es/organisation-unit-node/organisation-unit-node.js +22 -23
- package/build/es/organisation-unit-node/use-open-state.js +8 -9
- package/build/es/organisation-unit-node/use-org-children.js +14 -21
- package/build/es/organisation-unit-node/use-org-children.test.js +40 -59
- package/build/es/organisation-unit-node/use-org-data/use-org-data.js +13 -20
- package/build/es/organisation-unit-node/use-org-data/use-org-data.test.js +17 -27
- package/build/es/organisation-unit-tree/default-render-node-label/default-render-node-label.js +3 -6
- package/build/es/organisation-unit-tree/organisation-unit-tree-root-error.js +9 -12
- package/build/es/organisation-unit-tree/organisation-unit-tree-root-loading.js +10 -13
- package/build/es/organisation-unit-tree/organisation-unit-tree.js +34 -27
- package/build/es/organisation-unit-tree/organisation-unit-tree.test.js +71 -0
- package/build/es/organisation-unit-tree/use-expanded/create-expand-handlers.js +14 -17
- package/build/es/organisation-unit-tree/use-expanded/use-expanded.js +8 -9
- package/build/es/organisation-unit-tree/use-root-org-data/patch-missing-display-name.js +1 -2
- package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-data.js +10 -14
- package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +32 -46
- package/package.json +6 -6
- package/src/locales/index.js +57 -18
- package/src/organisation-unit-tree/organisation-unit-tree.js +14 -3
- package/src/organisation-unit-tree/organisation-unit-tree.test.js +64 -0
- package/src/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +14 -14
|
@@ -5,10 +5,7 @@ import { useRootOrgData } from './use-root-org-data.js';
|
|
|
5
5
|
describe('OrganisationUnitTree - useRootOrgData', () => {
|
|
6
6
|
// @TODO: Figure out why this is necessary at all...
|
|
7
7
|
const origError = console.error;
|
|
8
|
-
jest.spyOn(console, 'error').mockImplementation(
|
|
9
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
10
|
-
args[_key] = arguments[_key];
|
|
11
|
-
}
|
|
8
|
+
jest.spyOn(console, 'error').mockImplementation((...args) => {
|
|
12
9
|
const [err] = args;
|
|
13
10
|
if (!err.toString().match(/^Warning: An update to/)) {
|
|
14
11
|
origError(...args);
|
|
@@ -18,10 +15,7 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
|
|
|
18
15
|
// @TODO: This is kind of necessary; no idea if we can get rid of this
|
|
19
16
|
const origWarn = console.warn;
|
|
20
17
|
const dynamicQueryWarningMsg = "The query should be static, don't create it within the render loop!";
|
|
21
|
-
jest.spyOn(console, 'warn').mockImplementation(
|
|
22
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
23
|
-
args[_key2] = arguments[_key2];
|
|
24
|
-
}
|
|
18
|
+
jest.spyOn(console, 'warn').mockImplementation((...args) => {
|
|
25
19
|
const [err] = args;
|
|
26
20
|
if (!err.toString().match(dynamicQueryWarningMsg)) {
|
|
27
21
|
origWarn(...args);
|
|
@@ -40,14 +34,11 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
|
|
|
40
34
|
};
|
|
41
35
|
})
|
|
42
36
|
};
|
|
43
|
-
const wrapper =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
data: dataProviderData
|
|
49
|
-
}, children);
|
|
50
|
-
};
|
|
37
|
+
const wrapper = ({
|
|
38
|
+
children
|
|
39
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
40
|
+
data: dataProviderData
|
|
41
|
+
}, children);
|
|
51
42
|
it('should respond with `loading: false`, `error: null` and `data: null` initially', () => {
|
|
52
43
|
const {
|
|
53
44
|
result
|
|
@@ -67,32 +58,30 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
|
|
|
67
58
|
} = renderHook(() => useRootOrgData(['A0000000000']), {
|
|
68
59
|
wrapper
|
|
69
60
|
});
|
|
70
|
-
await waitFor(() => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
61
|
+
await waitFor(() => {
|
|
62
|
+
expect(result.current).toEqual(expect.objectContaining({
|
|
63
|
+
loading: false,
|
|
64
|
+
error: null,
|
|
65
|
+
data: {
|
|
66
|
+
A0000000000: {
|
|
67
|
+
id: 'A0000000000',
|
|
68
|
+
path: '/A0000000000',
|
|
69
|
+
displayName: 'Org Unit 1'
|
|
70
|
+
}
|
|
79
71
|
}
|
|
80
|
-
}
|
|
81
|
-
})
|
|
72
|
+
}));
|
|
73
|
+
});
|
|
82
74
|
});
|
|
83
75
|
it('should provide the error', async () => {
|
|
84
|
-
const errorWrapper =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
organisationUnits: async () => {
|
|
91
|
-
throw new Error('Error message');
|
|
92
|
-
}
|
|
76
|
+
const errorWrapper = ({
|
|
77
|
+
children
|
|
78
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
79
|
+
data: {
|
|
80
|
+
organisationUnits: async () => {
|
|
81
|
+
throw new Error('Error message');
|
|
93
82
|
}
|
|
94
|
-
}
|
|
95
|
-
};
|
|
83
|
+
}
|
|
84
|
+
}, children);
|
|
96
85
|
const {
|
|
97
86
|
result
|
|
98
87
|
} = renderHook(() => useRootOrgData(['A0000000000']), {
|
|
@@ -142,14 +131,11 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
|
|
|
142
131
|
};
|
|
143
132
|
})
|
|
144
133
|
};
|
|
145
|
-
const wrapperWithoutDisplayName =
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
data: dataProviderDataWithoutDisplayName
|
|
151
|
-
}, children);
|
|
152
|
-
};
|
|
134
|
+
const wrapperWithoutDisplayName = ({
|
|
135
|
+
children
|
|
136
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
137
|
+
data: dataProviderDataWithoutDisplayName
|
|
138
|
+
}, children);
|
|
153
139
|
const {
|
|
154
140
|
result
|
|
155
141
|
} = renderHook(() => useRootOrgData(['A0000000000']), {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhis2-ui/organisation-unit-tree",
|
|
3
|
-
"version": "10.16.
|
|
3
|
+
"version": "10.16.5",
|
|
4
4
|
"description": "UI OrganisationUnitTree",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@dhis2/prop-types": "^3.1.2",
|
|
38
|
-
"@dhis2-ui/button": "10.16.
|
|
39
|
-
"@dhis2-ui/checkbox": "10.16.
|
|
40
|
-
"@dhis2-ui/loader": "10.16.
|
|
41
|
-
"@dhis2-ui/node": "10.16.
|
|
42
|
-
"@dhis2/ui-constants": "10.16.
|
|
38
|
+
"@dhis2-ui/button": "10.16.5",
|
|
39
|
+
"@dhis2-ui/checkbox": "10.16.5",
|
|
40
|
+
"@dhis2-ui/loader": "10.16.5",
|
|
41
|
+
"@dhis2-ui/node": "10.16.5",
|
|
42
|
+
"@dhis2/ui-constants": "10.16.5",
|
|
43
43
|
"classnames": "^2.3.1",
|
|
44
44
|
"prop-types": "^15.7.2"
|
|
45
45
|
},
|
package/src/locales/index.js
CHANGED
|
@@ -28,23 +28,62 @@ import zhTranslations from './zh/translations.json'
|
|
|
28
28
|
import zh_CNTranslations from './zh_CN/translations.json'
|
|
29
29
|
|
|
30
30
|
const namespace = 'default'
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
i18n.
|
|
36
|
-
i18n.
|
|
37
|
-
|
|
38
|
-
i18n.
|
|
39
|
-
i18n.
|
|
40
|
-
|
|
41
|
-
i18n.
|
|
42
|
-
i18n.
|
|
43
|
-
|
|
44
|
-
i18n.
|
|
45
|
-
i18n.
|
|
46
|
-
|
|
47
|
-
i18n.
|
|
48
|
-
i18n.
|
|
31
|
+
|
|
32
|
+
// Use 'deep' = true and 'overwrite' = false to add to, but not overwrite,
|
|
33
|
+
// custom translations from the datastore (added by the app adapter)
|
|
34
|
+
|
|
35
|
+
i18n.addResourceBundle('ar', namespace, arTranslations, true, false)
|
|
36
|
+
i18n.addResourceBundle('ar', namespace, arTranslations, true, false)
|
|
37
|
+
|
|
38
|
+
i18n.addResourceBundle('cs', namespace, csTranslations, true, false)
|
|
39
|
+
i18n.addResourceBundle('cs', namespace, csTranslations, true, false)
|
|
40
|
+
|
|
41
|
+
i18n.addResourceBundle('en', namespace, enTranslations, true, false)
|
|
42
|
+
i18n.addResourceBundle('en', namespace, enTranslations, true, false)
|
|
43
|
+
|
|
44
|
+
i18n.addResourceBundle('es', namespace, esTranslations, true, false)
|
|
45
|
+
i18n.addResourceBundle('es', namespace, esTranslations, true, false)
|
|
46
|
+
|
|
47
|
+
i18n.addResourceBundle('es_419', namespace, es_419Translations, true, false)
|
|
48
|
+
i18n.addResourceBundle('es-419', namespace, es_419Translations, true, false)
|
|
49
|
+
|
|
50
|
+
i18n.addResourceBundle('fr', namespace, frTranslations, true, false)
|
|
51
|
+
i18n.addResourceBundle('fr', namespace, frTranslations, true, false)
|
|
52
|
+
|
|
53
|
+
i18n.addResourceBundle('lo', namespace, loTranslations, true, false)
|
|
54
|
+
i18n.addResourceBundle('lo', namespace, loTranslations, true, false)
|
|
55
|
+
|
|
56
|
+
i18n.addResourceBundle('nb', namespace, nbTranslations, true, false)
|
|
57
|
+
i18n.addResourceBundle('nb', namespace, nbTranslations, true, false)
|
|
58
|
+
|
|
59
|
+
i18n.addResourceBundle('nl', namespace, nlTranslations, true, false)
|
|
60
|
+
i18n.addResourceBundle('nl', namespace, nlTranslations, true, false)
|
|
61
|
+
|
|
62
|
+
i18n.addResourceBundle('pt', namespace, ptTranslations, true, false)
|
|
63
|
+
i18n.addResourceBundle('pt', namespace, ptTranslations, true, false)
|
|
64
|
+
|
|
65
|
+
i18n.addResourceBundle('ru', namespace, ruTranslations, true, false)
|
|
66
|
+
i18n.addResourceBundle('ru', namespace, ruTranslations, true, false)
|
|
67
|
+
|
|
68
|
+
i18n.addResourceBundle('uk', namespace, ukTranslations, true, false)
|
|
69
|
+
i18n.addResourceBundle('uk', namespace, ukTranslations, true, false)
|
|
70
|
+
|
|
71
|
+
i18n.addResourceBundle('uz_Latn', namespace, uz_LatnTranslations, true, false)
|
|
72
|
+
i18n.addResourceBundle('uz-Latn', namespace, uz_LatnTranslations, true, false)
|
|
73
|
+
|
|
74
|
+
i18n.addResourceBundle('uz_UZ_Cyrl', namespace, uz_UZ_CyrlTranslations, true, false)
|
|
75
|
+
i18n.addResourceBundle('uz-Cyrl-UZ', namespace, uz_UZ_CyrlTranslations, true, false)
|
|
76
|
+
|
|
77
|
+
i18n.addResourceBundle('uz_UZ_Latn', namespace, uz_UZ_LatnTranslations, true, false)
|
|
78
|
+
i18n.addResourceBundle('uz-Latn-UZ', namespace, uz_UZ_LatnTranslations, true, false)
|
|
79
|
+
|
|
80
|
+
i18n.addResourceBundle('vi', namespace, viTranslations, true, false)
|
|
81
|
+
i18n.addResourceBundle('vi', namespace, viTranslations, true, false)
|
|
82
|
+
|
|
83
|
+
i18n.addResourceBundle('zh', namespace, zhTranslations, true, false)
|
|
84
|
+
i18n.addResourceBundle('zh', namespace, zhTranslations, true, false)
|
|
85
|
+
|
|
86
|
+
i18n.addResourceBundle('zh_CN', namespace, zh_CNTranslations, true, false)
|
|
87
|
+
i18n.addResourceBundle('zh-CN', namespace, zh_CNTranslations, true, false)
|
|
49
88
|
|
|
50
89
|
export default i18n
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { requiredIf } from '@dhis2/prop-types'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
|
-
import React, { useEffect, useState } from 'react'
|
|
3
|
+
import React, { useEffect, useMemo, useState } from 'react'
|
|
4
|
+
import { sortNodeChildrenAlphabetically } from '../helpers/index.js'
|
|
4
5
|
import { OrganisationUnitNode } from '../organisation-unit-node/index.js'
|
|
5
6
|
import { orgUnitPathPropType } from '../prop-types.js'
|
|
6
7
|
import { defaultRenderNodeLabel } from './default-render-node-label/index.js'
|
|
@@ -75,14 +76,24 @@ const OrganisationUnitTree = ({
|
|
|
75
76
|
|
|
76
77
|
const isLoading = !called || loading
|
|
77
78
|
|
|
79
|
+
const sortedRoots = useMemo(() => {
|
|
80
|
+
if (!data) {
|
|
81
|
+
return staticArray
|
|
82
|
+
}
|
|
83
|
+
const rootNodes = rootIds.map((rootId) => data[rootId])
|
|
84
|
+
return suppressAlphabeticalSorting
|
|
85
|
+
? rootNodes
|
|
86
|
+
: sortNodeChildrenAlphabetically(rootNodes)
|
|
87
|
+
}, [data, rootIds, suppressAlphabeticalSorting])
|
|
88
|
+
|
|
78
89
|
return (
|
|
79
90
|
<div data-test={dataTest}>
|
|
80
91
|
{isLoading && <OrganisationUnitTreeRootLoading />}
|
|
81
92
|
{error && <OrganisationUnitTreeRootError error={error} />}
|
|
82
93
|
{!error &&
|
|
83
94
|
!isLoading &&
|
|
84
|
-
|
|
85
|
-
const
|
|
95
|
+
sortedRoots.map((rootNode) => {
|
|
96
|
+
const rootId = rootNode.id
|
|
86
97
|
|
|
87
98
|
return (
|
|
88
99
|
<OrganisationUnitNode
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CustomDataProvider } from '@dhis2/app-runtime'
|
|
2
|
+
import { render } from '@testing-library/react'
|
|
2
3
|
import { shallow } from 'enzyme'
|
|
3
4
|
import React from 'react'
|
|
4
5
|
import { OrganisationUnitTree } from './organisation-unit-tree.js'
|
|
@@ -74,4 +75,67 @@ describe('OrganisationUnitTree', () => {
|
|
|
74
75
|
})
|
|
75
76
|
})
|
|
76
77
|
})
|
|
78
|
+
|
|
79
|
+
describe('Root node sorting', () => {
|
|
80
|
+
// displayNames intentionally out of alphabetical order relative to ids
|
|
81
|
+
const rootNodes = {
|
|
82
|
+
A001: { id: 'A001', path: '/A001', displayName: 'Bravo' },
|
|
83
|
+
A002: { id: 'A002', path: '/A002', displayName: 'Alpha' },
|
|
84
|
+
A003: { id: 'A003', path: '/A003', displayName: 'Charlie' },
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const dataProvider = {
|
|
88
|
+
organisationUnits: (type, { id }) => {
|
|
89
|
+
const node = rootNodes[id]
|
|
90
|
+
if (node) {
|
|
91
|
+
// children: 0 so nodes don't try to load descendants
|
|
92
|
+
return { ...node, children: 0 }
|
|
93
|
+
}
|
|
94
|
+
return Promise.reject(`No org unit with id "${id}"`)
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
it('sorts root nodes alphabetically by displayName by default', async () => {
|
|
99
|
+
const { container, findByText } = render(
|
|
100
|
+
<CustomDataProvider data={dataProvider}>
|
|
101
|
+
<OrganisationUnitTree
|
|
102
|
+
roots={['A001', 'A002', 'A003']}
|
|
103
|
+
onChange={() => {}}
|
|
104
|
+
/>
|
|
105
|
+
</CustomDataProvider>
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
await findByText('Alpha')
|
|
109
|
+
|
|
110
|
+
const { textContent } = container
|
|
111
|
+
expect(textContent.indexOf('Alpha')).toBeLessThan(
|
|
112
|
+
textContent.indexOf('Bravo')
|
|
113
|
+
)
|
|
114
|
+
expect(textContent.indexOf('Bravo')).toBeLessThan(
|
|
115
|
+
textContent.indexOf('Charlie')
|
|
116
|
+
)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('keeps the provided roots order when suppressAlphabeticalSorting is true', async () => {
|
|
120
|
+
const { container, findByText } = render(
|
|
121
|
+
<CustomDataProvider data={dataProvider}>
|
|
122
|
+
<OrganisationUnitTree
|
|
123
|
+
roots={['A003', 'A001', 'A002']}
|
|
124
|
+
suppressAlphabeticalSorting
|
|
125
|
+
onChange={() => {}}
|
|
126
|
+
/>
|
|
127
|
+
</CustomDataProvider>
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
await findByText('Charlie')
|
|
131
|
+
|
|
132
|
+
const { textContent } = container
|
|
133
|
+
expect(textContent.indexOf('Charlie')).toBeLessThan(
|
|
134
|
+
textContent.indexOf('Bravo')
|
|
135
|
+
)
|
|
136
|
+
expect(textContent.indexOf('Bravo')).toBeLessThan(
|
|
137
|
+
textContent.indexOf('Alpha')
|
|
138
|
+
)
|
|
139
|
+
})
|
|
140
|
+
})
|
|
77
141
|
})
|
|
@@ -67,21 +67,21 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
|
|
|
67
67
|
wrapper,
|
|
68
68
|
})
|
|
69
69
|
|
|
70
|
-
await waitFor(() => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
await waitFor(() => {
|
|
71
|
+
expect(result.current).toEqual(
|
|
72
|
+
expect.objectContaining({
|
|
73
|
+
loading: false,
|
|
74
|
+
error: null,
|
|
75
|
+
data: {
|
|
76
|
+
A0000000000: {
|
|
77
|
+
id: 'A0000000000',
|
|
78
|
+
path: '/A0000000000',
|
|
79
|
+
displayName: 'Org Unit 1',
|
|
80
|
+
},
|
|
81
81
|
},
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
)
|
|
82
|
+
})
|
|
83
|
+
)
|
|
84
|
+
})
|
|
85
85
|
})
|
|
86
86
|
|
|
87
87
|
it('should provide the error', async () => {
|