@beinformed/ui 1.12.0 → 1.13.1
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 +32 -2
- package/esm/builder/mergeLayoutHintConfigurations.js +3 -3
- package/esm/builder/mergeLayoutHintConfigurations.js.map +1 -1
- package/esm/exceptions/ConfigurationException.js +2 -1
- package/esm/exceptions/ConfigurationException.js.map +1 -1
- package/esm/exceptions/FetchException.js +4 -3
- package/esm/exceptions/FetchException.js.map +1 -1
- package/esm/exceptions/IllegalArgumentException.js +2 -1
- package/esm/exceptions/IllegalArgumentException.js.map +1 -1
- package/esm/exceptions/IllegalReturnException.js +2 -1
- package/esm/exceptions/IllegalReturnException.js.map +1 -1
- package/esm/exceptions/IllegalStateException.js +2 -1
- package/esm/exceptions/IllegalStateException.js.map +1 -1
- package/esm/exceptions/JsonParseException.js +2 -1
- package/esm/exceptions/JsonParseException.js.map +1 -1
- package/esm/exceptions/MissingPropertyException.js +2 -1
- package/esm/exceptions/MissingPropertyException.js.map +1 -1
- package/esm/exceptions/NetworkException.js +2 -1
- package/esm/exceptions/NetworkException.js.map +1 -1
- package/esm/exceptions/NotAllowedUriException.js +2 -1
- package/esm/exceptions/NotAllowedUriException.js.map +1 -1
- package/esm/exceptions/NotFoundException.js +2 -1
- package/esm/exceptions/NotFoundException.js.map +1 -1
- package/esm/exceptions/ServerRequestException.js +2 -1
- package/esm/exceptions/ServerRequestException.js.map +1 -1
- package/esm/exceptions/ThemePropertyException.js +2 -1
- package/esm/exceptions/ThemePropertyException.js.map +1 -1
- package/esm/exceptions/TimeoutException.js +2 -1
- package/esm/exceptions/TimeoutException.js.map +1 -1
- package/esm/exceptions/UnauthorizedException.js +2 -1
- package/esm/exceptions/UnauthorizedException.js.map +1 -1
- package/esm/exceptions/UnsupportedOperationException.js +2 -1
- package/esm/exceptions/UnsupportedOperationException.js.map +1 -1
- package/esm/hooks/useContent.js +2 -2
- package/esm/hooks/useContent.js.map +1 -1
- package/esm/hooks/useDeepCompareEffect.js +2 -1
- package/esm/hooks/useDeepCompareEffect.js.map +1 -1
- package/esm/hooks/useForm.js.map +1 -1
- package/esm/hooks/useModal.js +2 -2
- package/esm/hooks/useModal.js.map +1 -1
- package/esm/hooks/useModularUI.js +0 -1
- package/esm/hooks/useModularUI.js.map +1 -1
- package/esm/hooks/useProgressIndicator.js +2 -2
- package/esm/i18n/Locale.js +11 -4
- package/esm/i18n/Locale.js.map +1 -1
- package/esm/i18n/Locales.js +2 -2
- package/esm/i18n/Message.js +2 -2
- package/esm/i18n/languages.js +2 -1
- package/esm/i18n/languages.js.map +1 -1
- package/esm/models/attributes/AttributeCollection.js +2 -2
- package/esm/models/attributes/AttributeContent.js +58 -30
- package/esm/models/attributes/AttributeContent.js.map +1 -1
- package/esm/models/attributes/AttributeDataHelper.js +3 -3
- package/esm/models/attributes/AttributeDataHelper.js.map +1 -1
- package/esm/models/attributes/BooleanAttributeModel.js +2 -2
- package/esm/models/attributes/ChoiceAttributeModel.js +2 -2
- package/esm/models/attributes/ChoiceAttributeOptionCollection.js +2 -2
- package/esm/models/attributes/CompositeAttributeChildCollection.js +2 -2
- package/esm/models/attributes/HelptextAttributeModel.js +24 -9
- package/esm/models/attributes/HelptextAttributeModel.js.map +1 -1
- package/esm/models/attributes/_createAttribute.js +2 -2
- package/esm/models/base/ResourceModel.js +2 -2
- package/esm/models/caseview/CaseViewModel.js +4 -5
- package/esm/models/caseview/CaseViewModel.js.map +1 -1
- package/esm/models/concepts/ConceptDetailModel.js +2 -2
- package/esm/models/concepts/SourceReferenceModel.js +2 -2
- package/esm/models/content/ContentTOCModel.js +2 -2
- package/esm/models/filters/AssignmentFilterModel.js +2 -2
- package/esm/models/filters/BaseFilterModel.js +2 -2
- package/esm/models/filters/ConceptIndexFilterModel.js +2 -1
- package/esm/models/filters/ConceptIndexFilterModel.js.map +1 -1
- package/esm/models/filters/FilterCollection.js +2 -2
- package/esm/models/filters/FilterModel.js +2 -1
- package/esm/models/filters/FilterModel.js.map +1 -1
- package/esm/models/form/FormModel.js +28 -4
- package/esm/models/form/FormModel.js.map +1 -1
- package/esm/models/form/FormObjectModel.js +5 -7
- package/esm/models/form/FormObjectModel.js.map +1 -1
- package/esm/models/grouping/GroupingModel.js +2 -2
- package/esm/models/links/normalizeLinkJSON.js +2 -2
- package/esm/models/list/ListDetailModel.js +4 -6
- package/esm/models/list/ListDetailModel.js.map +1 -1
- package/esm/models/list/ListItemCollection.js +38 -0
- package/esm/models/list/ListItemCollection.js.map +1 -1
- package/esm/models/list/ListItemModel.js +14 -2
- package/esm/models/list/ListItemModel.js.map +1 -1
- package/esm/models/list/ListModel.js +19 -74
- package/esm/models/list/ListModel.js.map +1 -1
- package/esm/models/lookup/LookupOptionCollection.js +2 -2
- package/esm/models/panels/GroupingPanelModel.js +2 -4
- package/esm/models/panels/GroupingPanelModel.js.map +1 -1
- package/esm/modularui/ModularUIError.js +2 -1
- package/esm/modularui/ModularUIError.js.map +1 -1
- package/esm/modularui/ModularUIRequest.js +71 -49
- package/esm/modularui/ModularUIRequest.js.map +1 -1
- package/esm/react-server/serverUtil.js +2 -2
- package/esm/react-theme/createTheme.js +2 -2
- package/esm/redux/_i18n/reducer.js +2 -2
- package/esm/redux/_modularui/actions.js +2 -2
- package/esm/redux/_modularui/connector.js +2 -2
- package/esm/redux/_modularui/reducer.js +2 -2
- package/esm/redux/_modularui/selectors.js +2 -2
- package/esm/redux/reducers/AuthReducer.js +2 -2
- package/esm/redux/reducers/ModalsReducer.js +2 -2
- package/esm/redux/reducers/NotificationReducer.js +2 -2
- package/esm/redux/reducers/PreferencesReducer.js +2 -2
- package/esm/redux/reducers/ProgressIndicatorReducer.js +2 -2
- package/esm/redux/store/configureStore.js +2 -2
- package/esm/utils/browser/Cookies.js +18 -32
- package/esm/utils/browser/Cookies.js.map +1 -1
- package/esm/utils/fetch/xhr.js +4 -3
- package/esm/utils/fetch/xhr.js.map +1 -1
- package/lib/builder/mergeLayoutHintConfigurations.js +3 -3
- package/lib/builder/mergeLayoutHintConfigurations.js.flow +3 -3
- package/lib/builder/mergeLayoutHintConfigurations.js.map +1 -1
- package/lib/exceptions/ConfigurationException.js +3 -1
- package/lib/exceptions/ConfigurationException.js.map +1 -1
- package/lib/exceptions/FetchException.js +5 -3
- package/lib/exceptions/FetchException.js.map +1 -1
- package/lib/exceptions/IllegalArgumentException.js +3 -1
- package/lib/exceptions/IllegalArgumentException.js.map +1 -1
- package/lib/exceptions/IllegalReturnException.js +3 -1
- package/lib/exceptions/IllegalReturnException.js.map +1 -1
- package/lib/exceptions/IllegalStateException.js +3 -1
- package/lib/exceptions/IllegalStateException.js.map +1 -1
- package/lib/exceptions/JsonParseException.js +3 -1
- package/lib/exceptions/JsonParseException.js.map +1 -1
- package/lib/exceptions/MissingPropertyException.js +3 -1
- package/lib/exceptions/MissingPropertyException.js.map +1 -1
- package/lib/exceptions/NetworkException.js +3 -1
- package/lib/exceptions/NetworkException.js.map +1 -1
- package/lib/exceptions/NotAllowedUriException.js +3 -1
- package/lib/exceptions/NotAllowedUriException.js.map +1 -1
- package/lib/exceptions/NotFoundException.js +3 -1
- package/lib/exceptions/NotFoundException.js.map +1 -1
- package/lib/exceptions/ServerRequestException.js +3 -1
- package/lib/exceptions/ServerRequestException.js.map +1 -1
- package/lib/exceptions/ThemePropertyException.js +3 -1
- package/lib/exceptions/ThemePropertyException.js.map +1 -1
- package/lib/exceptions/TimeoutException.js +3 -1
- package/lib/exceptions/TimeoutException.js.map +1 -1
- package/lib/exceptions/UnauthorizedException.js +3 -1
- package/lib/exceptions/UnauthorizedException.js.map +1 -1
- package/lib/exceptions/UnsupportedOperationException.js +3 -1
- package/lib/exceptions/UnsupportedOperationException.js.map +1 -1
- package/lib/hooks/useContent.js +2 -2
- package/lib/hooks/useContent.js.flow +2 -2
- package/lib/hooks/useContent.js.map +1 -1
- package/lib/hooks/useDeepCompareEffect.js +2 -1
- package/lib/hooks/useDeepCompareEffect.js.flow +1 -1
- package/lib/hooks/useDeepCompareEffect.js.map +1 -1
- package/lib/hooks/useForm.js.flow +1 -2
- package/lib/hooks/useForm.js.map +1 -1
- package/lib/hooks/useModal.js +2 -2
- package/lib/hooks/useModal.js.flow +1 -1
- package/lib/hooks/useModal.js.map +1 -1
- package/lib/hooks/useModularUI.js +0 -1
- package/lib/hooks/useModularUI.js.flow +0 -2
- package/lib/hooks/useModularUI.js.map +1 -1
- package/lib/hooks/useProgressIndicator.js +2 -2
- package/lib/i18n/Locale.js +11 -5
- package/lib/i18n/Locale.js.flow +7 -0
- package/lib/i18n/Locale.js.map +1 -1
- package/lib/i18n/Locales.js +2 -2
- package/lib/i18n/Message.js +2 -2
- package/lib/i18n/__tests__/Locale.spec.js.flow +14 -0
- package/lib/i18n/languages.js +2 -1
- package/lib/i18n/languages.js.flow +1 -0
- package/lib/i18n/languages.js.map +1 -1
- package/lib/i18n/types.js.flow +1 -0
- package/lib/models/attributes/AttributeCollection.js +2 -2
- package/lib/models/attributes/AttributeContent.js +59 -31
- package/lib/models/attributes/AttributeContent.js.flow +63 -16
- package/lib/models/attributes/AttributeContent.js.map +1 -1
- package/lib/models/attributes/AttributeDataHelper.js +3 -3
- package/lib/models/attributes/AttributeDataHelper.js.flow +1 -0
- package/lib/models/attributes/AttributeDataHelper.js.map +1 -1
- package/lib/models/attributes/BooleanAttributeModel.js +2 -2
- package/lib/models/attributes/ChoiceAttributeModel.js +2 -2
- package/lib/models/attributes/ChoiceAttributeOptionCollection.js +2 -2
- package/lib/models/attributes/CompositeAttributeChildCollection.js +2 -2
- package/lib/models/attributes/HelptextAttributeModel.js +24 -9
- package/lib/models/attributes/HelptextAttributeModel.js.flow +18 -5
- package/lib/models/attributes/HelptextAttributeModel.js.map +1 -1
- package/lib/models/attributes/__tests__/AttributeCollection.spec.js.flow +4 -4
- package/lib/models/attributes/__tests__/AttributeContent.spec.js.flow +13 -19
- package/lib/models/attributes/__tests__/HelptextAttributeModel.spec.js.flow +18 -10
- package/lib/models/attributes/_createAttribute.js +2 -2
- package/lib/models/base/ResourceModel.js +2 -2
- package/lib/models/caseview/CaseViewModel.js +5 -5
- package/lib/models/caseview/CaseViewModel.js.flow +5 -3
- package/lib/models/caseview/CaseViewModel.js.map +1 -1
- package/lib/models/caseview/__tests__/CaseViewModel.spec.js.flow +43 -4
- package/lib/models/concepts/ConceptDetailModel.js +2 -2
- package/lib/models/concepts/SourceReferenceModel.js +2 -2
- package/lib/models/content/ContentTOCModel.js +2 -2
- package/lib/models/filters/AssignmentFilterModel.js +2 -2
- package/lib/models/filters/BaseFilterModel.js +2 -2
- package/lib/models/filters/ConceptIndexFilterModel.js +3 -1
- package/lib/models/filters/ConceptIndexFilterModel.js.map +1 -1
- package/lib/models/filters/FilterCollection.js +2 -2
- package/lib/models/filters/FilterModel.js +3 -1
- package/lib/models/filters/FilterModel.js.map +1 -1
- package/lib/models/form/FormModel.js +28 -4
- package/lib/models/form/FormModel.js.flow +18 -1
- package/lib/models/form/FormModel.js.map +1 -1
- package/lib/models/form/FormObjectModel.js +5 -7
- package/lib/models/form/FormObjectModel.js.flow +2 -4
- package/lib/models/form/FormObjectModel.js.map +1 -1
- package/lib/models/form/__tests__/FormModel.getters.spec.js.flow +15 -0
- package/lib/models/form/__tests__/FormObjectModel.spec.js.flow +29 -3
- package/lib/models/grouping/GroupingModel.js +2 -2
- package/lib/models/links/normalizeLinkJSON.js +2 -2
- package/lib/models/list/ListDetailModel.js +4 -6
- package/lib/models/list/ListDetailModel.js.flow +2 -2
- package/lib/models/list/ListDetailModel.js.map +1 -1
- package/lib/models/list/ListItemCollection.js +40 -0
- package/lib/models/list/ListItemCollection.js.flow +38 -1
- package/lib/models/list/ListItemCollection.js.map +1 -1
- package/lib/models/list/ListItemModel.js +14 -2
- package/lib/models/list/ListItemModel.js.flow +15 -0
- package/lib/models/list/ListItemModel.js.map +1 -1
- package/lib/models/list/ListModel.js +18 -75
- package/lib/models/list/ListModel.js.flow +3 -47
- package/lib/models/list/ListModel.js.map +1 -1
- package/lib/models/list/__tests__/ListDetailModel.spec.js.flow +5 -3
- package/lib/models/list/__tests__/ListItemCollection.spec.js.flow +22 -0
- package/lib/models/list/__tests__/ListModel.spec.js.flow +5 -5
- package/lib/models/lookup/LookupOptionCollection.js +2 -2
- package/lib/models/panels/GroupingPanelModel.js +2 -4
- package/lib/models/panels/GroupingPanelModel.js.flow +2 -2
- package/lib/models/panels/GroupingPanelModel.js.map +1 -1
- package/lib/models/panels/__tests__/GroupingPanelModel.spec.js.flow +43 -24
- package/lib/models/process/__tests__/ProcessStatusSettingsModel.spec.js.flow +11 -0
- package/lib/models/types.js.flow +3 -3
- package/lib/modularui/ModularUIError.js +3 -1
- package/lib/modularui/ModularUIError.js.map +1 -1
- package/lib/modularui/ModularUIRequest.js +69 -49
- package/lib/modularui/ModularUIRequest.js.flow +38 -22
- package/lib/modularui/ModularUIRequest.js.map +1 -1
- package/lib/react-server/serverUtil.js +2 -2
- package/lib/react-theme/createTheme.js +2 -2
- package/lib/redux/_i18n/reducer.js +2 -2
- package/lib/redux/_modularui/actions.js +2 -2
- package/lib/redux/_modularui/connector.js +2 -2
- package/lib/redux/_modularui/reducer.js +2 -2
- package/lib/redux/_modularui/selectors.js +2 -2
- package/lib/redux/reducers/AuthReducer.js +2 -2
- package/lib/redux/reducers/ModalsReducer.js +2 -2
- package/lib/redux/reducers/NotificationReducer.js +2 -2
- package/lib/redux/reducers/PreferencesReducer.js +2 -2
- package/lib/redux/reducers/ProgressIndicatorReducer.js +2 -2
- package/lib/redux/store/configureStore.js +2 -2
- package/lib/utils/browser/Cookies.js +18 -31
- package/lib/utils/browser/Cookies.js.flow +22 -28
- package/lib/utils/browser/Cookies.js.map +1 -1
- package/lib/utils/browser/__tests__/Cookies.spec.js.flow +51 -0
- package/lib/utils/fetch/xhr.js +4 -3
- package/lib/utils/fetch/xhr.js.flow +3 -1
- package/lib/utils/fetch/xhr.js.map +1 -1
- package/package.json +36 -34
- package/src/builder/mergeLayoutHintConfigurations.js +3 -3
- package/src/hooks/useContent.js +2 -2
- package/src/hooks/useDeepCompareEffect.js +1 -1
- package/src/hooks/useForm.js +1 -2
- package/src/hooks/useModal.js +1 -1
- package/src/hooks/useModularUI.js +0 -2
- package/src/i18n/Locale.js +7 -0
- package/src/i18n/__tests__/Locale.spec.js +14 -0
- package/src/i18n/languages.js +1 -0
- package/src/i18n/types.js +1 -0
- package/src/models/attributes/AttributeContent.js +63 -16
- package/src/models/attributes/AttributeDataHelper.js +1 -0
- package/src/models/attributes/HelptextAttributeModel.js +18 -5
- package/src/models/attributes/__mock__/_FormCollectionContribution.json +9 -0
- package/src/models/attributes/__mock__/_FormCollectionData.json +12 -3
- package/src/models/attributes/__tests__/AttributeCollection.spec.js +4 -4
- package/src/models/attributes/__tests__/AttributeContent.spec.js +13 -19
- package/src/models/attributes/__tests__/HelptextAttributeModel.spec.js +18 -10
- package/src/models/caseview/CaseViewModel.js +5 -3
- package/src/models/caseview/__tests__/CaseViewModel.spec.js +43 -4
- package/src/models/caseview/__tests__/caseview.json +14 -3
- package/src/models/caseview/__tests__/caseviewContributions.json +48 -77
- package/src/models/caseview/__tests__/caseview_local_taskgroup.json +57 -0
- package/src/models/form/FormModel.js +18 -1
- package/src/models/form/FormObjectModel.js +2 -4
- package/src/models/form/__tests__/FormModel.getters.spec.js +15 -0
- package/src/models/form/__tests__/FormObjectModel.spec.js +29 -3
- package/src/models/list/ListDetailModel.js +2 -2
- package/src/models/list/ListItemCollection.js +38 -1
- package/src/models/list/ListItemModel.js +15 -0
- package/src/models/list/ListModel.js +3 -47
- package/src/models/list/__tests__/ListDetailModel.spec.js +5 -3
- package/src/models/list/__tests__/ListItemCollection.spec.js +22 -0
- package/src/models/list/__tests__/ListModel.spec.js +5 -5
- package/src/models/panels/GroupingPanelModel.js +2 -2
- package/src/models/panels/__tests__/GroupingPanelModel.spec.js +43 -24
- package/src/models/panels/__tests__/groupingPanel.json +20 -1
- package/src/models/panels/__tests__/groupingPanelContributions.json +14 -1
- package/src/models/process/__tests__/ProcessStatusSettingsModel.spec.js +11 -0
- package/src/models/types.js +3 -3
- package/src/modularui/ModularUIRequest.js +38 -22
- package/src/utils/browser/Cookies.js +22 -28
- package/src/utils/browser/__tests__/Cookies.spec.js +51 -0
- package/src/utils/fetch/xhr.js +3 -1
|
@@ -1,13 +1,50 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import BaseCollection from "../base/BaseCollection";
|
|
3
3
|
import ActionCollection from "../actions/ActionCollection";
|
|
4
|
+
import ListItemModel from "../list/ListItemModel";
|
|
4
5
|
|
|
5
|
-
import
|
|
6
|
+
import ConfigurationException from "../../exceptions/ConfigurationException";
|
|
7
|
+
|
|
8
|
+
import type ListModel from "../list/ListModel";
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* Collection of list items
|
|
9
12
|
*/
|
|
10
13
|
class ListItemCollection extends BaseCollection<ListItemModel> {
|
|
14
|
+
/**
|
|
15
|
+
* Create a list item collection from the given list
|
|
16
|
+
*/
|
|
17
|
+
static createFromList(list: ListModel): ListItemCollection {
|
|
18
|
+
const _embedded = list.getData("_embedded");
|
|
19
|
+
if (_embedded != null) {
|
|
20
|
+
if (Array.isArray(_embedded)) {
|
|
21
|
+
throw new ConfigurationException(
|
|
22
|
+
`One record panel with multiple tables is not supported, place all types in one panel for the panel with key ${list.key}`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const dynamicschema = list.getData("dynamicschema");
|
|
27
|
+
|
|
28
|
+
const collection = _embedded.results.map((resultItem) => {
|
|
29
|
+
const [key] = Object.keys(resultItem);
|
|
30
|
+
const listitemData = resultItem[key];
|
|
31
|
+
listitemData.dynamicschema = dynamicschema;
|
|
32
|
+
|
|
33
|
+
const listitemContributions = list.contributions.results[key];
|
|
34
|
+
|
|
35
|
+
return ListItemModel.createFromListResult(
|
|
36
|
+
key,
|
|
37
|
+
listitemData,
|
|
38
|
+
listitemContributions
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return new ListItemCollection(collection);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return new ListItemCollection();
|
|
46
|
+
}
|
|
47
|
+
|
|
11
48
|
/**
|
|
12
49
|
*/
|
|
13
50
|
get additionalDetailRoutePath(): string {
|
|
@@ -14,6 +14,21 @@ import type LinkCollection from "../links/LinkCollection";
|
|
|
14
14
|
* List Item
|
|
15
15
|
*/
|
|
16
16
|
export default class ListItemModel extends DetailModel {
|
|
17
|
+
/**
|
|
18
|
+
*/
|
|
19
|
+
static createFromListResult(
|
|
20
|
+
key: string,
|
|
21
|
+
data: Object,
|
|
22
|
+
contributions: Object
|
|
23
|
+
): ListItemModel {
|
|
24
|
+
const listitemInput = new ModularUIResponse();
|
|
25
|
+
listitemInput.key = key;
|
|
26
|
+
listitemInput.data = data;
|
|
27
|
+
listitemInput.contributions = contributions;
|
|
28
|
+
|
|
29
|
+
return new ListItemModel(listitemInput);
|
|
30
|
+
}
|
|
31
|
+
|
|
17
32
|
/**
|
|
18
33
|
*/
|
|
19
34
|
static createFromChoiceAttributeOption(
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import { ConfigurationException } from "../../exceptions";
|
|
3
|
-
|
|
4
2
|
import ModularUIResponse from "../../modularui/ModularUIResponse";
|
|
5
3
|
|
|
6
4
|
import ListItemCollection from "../list/ListItemCollection";
|
|
@@ -98,8 +96,8 @@ export default class ListModel extends ResourceModel {
|
|
|
98
96
|
* Getting the introduction text
|
|
99
97
|
*/
|
|
100
98
|
get introtext(): string {
|
|
101
|
-
if (this.data.
|
|
102
|
-
return this.data.text.message
|
|
99
|
+
if (this.data.content) {
|
|
100
|
+
return this.data.content.text.message;
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
if (this.contributions.text) {
|
|
@@ -113,54 +111,12 @@ export default class ListModel extends ResourceModel {
|
|
|
113
111
|
return "";
|
|
114
112
|
}
|
|
115
113
|
|
|
116
|
-
/**
|
|
117
|
-
* Create a listitem collection from the data and contributions of a list
|
|
118
|
-
*/
|
|
119
|
-
createListItemCollection(): ListItemCollection {
|
|
120
|
-
const listitemCollection = new ListItemCollection();
|
|
121
|
-
|
|
122
|
-
const _embedded = this.getData("_embedded");
|
|
123
|
-
if (_embedded !== null) {
|
|
124
|
-
if (Array.isArray(_embedded)) {
|
|
125
|
-
throw new ConfigurationException(
|
|
126
|
-
`One record panel with multiple tables is not supported, place all types in one panel for the panel with key ${this.key}`
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
listitemCollection.collection = _embedded.results.map((result) =>
|
|
131
|
-
this.createListItem(result)
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return listitemCollection;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Create a ListItem
|
|
140
|
-
*/
|
|
141
|
-
createListItem(resultItem: Object): ListItemModel {
|
|
142
|
-
const [key] = Object.keys(resultItem);
|
|
143
|
-
const listitemData = resultItem[key];
|
|
144
|
-
const listitemContributions = this.contributions.results[key];
|
|
145
|
-
|
|
146
|
-
if (this.data.dynamicschema) {
|
|
147
|
-
listitemData.dynamicschema = this.data.dynamicschema;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const listitemModelInput = new ModularUIResponse();
|
|
151
|
-
listitemModelInput.key = key;
|
|
152
|
-
listitemModelInput.data = listitemData;
|
|
153
|
-
listitemModelInput.contributions = listitemContributions;
|
|
154
|
-
|
|
155
|
-
return new ListItemModel(listitemModelInput);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
114
|
/**
|
|
159
115
|
* Getting the results
|
|
160
116
|
*/
|
|
161
117
|
get listItemCollection(): ListItemCollection {
|
|
162
118
|
if (!this._listItemCollection) {
|
|
163
|
-
this._listItemCollection =
|
|
119
|
+
this._listItemCollection = ListItemCollection.createFromList(this);
|
|
164
120
|
}
|
|
165
121
|
|
|
166
122
|
return this._listItemCollection;
|
|
@@ -40,7 +40,7 @@ describe("listDetailModel", () => {
|
|
|
40
40
|
const listdetailFromDataPlain = new ListDetailModel({
|
|
41
41
|
key: "Book",
|
|
42
42
|
data: {
|
|
43
|
-
|
|
43
|
+
_content: { text: { message: "<p>This is introtext</p>" } },
|
|
44
44
|
...data.Book,
|
|
45
45
|
},
|
|
46
46
|
contributions: contributions.Book,
|
|
@@ -52,8 +52,10 @@ describe("listDetailModel", () => {
|
|
|
52
52
|
key: "Book",
|
|
53
53
|
data: {
|
|
54
54
|
...data.Book,
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
_content: {
|
|
56
|
+
text: {
|
|
57
|
+
message: "<p>This is introtext</p>",
|
|
58
|
+
},
|
|
57
59
|
},
|
|
58
60
|
},
|
|
59
61
|
contributions: contributions.Book,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import ListItemCollection from "../ListItemCollection";
|
|
2
|
+
|
|
3
|
+
import caselist from "../__mock__/caselist";
|
|
4
|
+
|
|
5
|
+
describe("listItemCollection spec", () => {
|
|
6
|
+
it("should be able to create an empty collection", () => {
|
|
7
|
+
const collection = new ListItemCollection();
|
|
8
|
+
|
|
9
|
+
expect(collection).toBeInstanceOf(ListItemCollection);
|
|
10
|
+
expect(collection.additionalDetailRoutePath).toBe("__NON_EXISTING_ROUTE__");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("can create a ListItemCollection from list items", () => {
|
|
14
|
+
const collection = ListItemCollection.createFromList(caselist);
|
|
15
|
+
expect(collection).toBeInstanceOf(ListItemCollection);
|
|
16
|
+
|
|
17
|
+
expect(collection.additionalDetailRoutePath).toBe(
|
|
18
|
+
"(/books/books/34/contributors|/books/books/34/publishedbypublishinghouse|/books/books/35/contributors|/books/books/35/publishedbypublishinghouse|/books/books/36/contributors|/books/books/36/publishedbypublishinghouse|/books/books/37/contributors|/books/books/37/publishedbypublishinghouse|/books/books/38/contributors|/books/books/38/publishedbypublishinghouse|/books/books/39/contributors|/books/books/39/publishedbypublishinghouse|/books/books/42/contributors|/books/books/42/publishedbypublishinghouse|/books/books/45/contributors|/books/books/45/publishedbypublishinghouse|/books/books/46/contributors|/books/books/46/publishedbypublishinghouse|/books/books/47/contributors|/books/books/47/publishedbypublishinghouse)"
|
|
19
|
+
);
|
|
20
|
+
expect(collection.actionCollection).toHaveLength(42);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -24,8 +24,6 @@ describe("listModel spec", () => {
|
|
|
24
24
|
expect(list.headers).toHaveLength(0);
|
|
25
25
|
|
|
26
26
|
expect(list.introtext).toBe("");
|
|
27
|
-
|
|
28
|
-
expect(typeof list.createListItem).toBe("function");
|
|
29
27
|
});
|
|
30
28
|
|
|
31
29
|
it("should be able to create a list from a typical modular ui response", () => {
|
|
@@ -69,7 +67,7 @@ describe("listModel spec", () => {
|
|
|
69
67
|
const listFromDataPlain = new ListModel({
|
|
70
68
|
key: "Books",
|
|
71
69
|
data: {
|
|
72
|
-
text: "<p>This is introtext</p>",
|
|
70
|
+
content: { text: { message: "<p>This is introtext</p>" } },
|
|
73
71
|
...mockList.Books,
|
|
74
72
|
},
|
|
75
73
|
contributions: mockListContributions.Books,
|
|
@@ -81,8 +79,10 @@ describe("listModel spec", () => {
|
|
|
81
79
|
key: "Books",
|
|
82
80
|
data: {
|
|
83
81
|
...mockList.Books,
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
content: {
|
|
83
|
+
text: {
|
|
84
|
+
message: "<p>This is introtext</p>",
|
|
85
|
+
},
|
|
86
86
|
},
|
|
87
87
|
},
|
|
88
88
|
contributions: mockListContributions.Books,
|
|
@@ -85,8 +85,8 @@ export default class GroupingPanelModel extends ResourceModel {
|
|
|
85
85
|
* Getting the introduction text configured on the grouping panel
|
|
86
86
|
*/
|
|
87
87
|
get introtext(): string {
|
|
88
|
-
if (this.data.
|
|
89
|
-
return this.data.
|
|
88
|
+
if (this.data._content) {
|
|
89
|
+
return this.data._content.text.message;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
if (this.contributions.text) {
|
|
@@ -2,13 +2,14 @@ import GroupingPanelModel from "../GroupingPanelModel";
|
|
|
2
2
|
|
|
3
3
|
import panelJson from "./groupingPanel.json";
|
|
4
4
|
import panelContributionsJson from "./groupingPanelContributions.json";
|
|
5
|
-
import CaseViewModel from "../../caseview/CaseViewModel";
|
|
6
5
|
|
|
7
6
|
describe("groupingPanelModel", () => {
|
|
8
7
|
it("should be able to create an empty GroupingPanelModel object", () => {
|
|
9
8
|
const groupingPanel = new GroupingPanelModel();
|
|
10
9
|
|
|
11
10
|
expect(groupingPanel).toBeInstanceOf(GroupingPanelModel);
|
|
11
|
+
expect(groupingPanel.type).toBe("GroupingPanel");
|
|
12
|
+
expect(groupingPanel.introtext).toBe("");
|
|
12
13
|
|
|
13
14
|
expect(
|
|
14
15
|
GroupingPanelModel.isApplicableModel({
|
|
@@ -51,10 +52,24 @@ describe("groupingPanelModel", () => {
|
|
|
51
52
|
expect(groupingPanel.panelLinks).toHaveLength(1);
|
|
52
53
|
|
|
53
54
|
expect(groupingPanel.hasIntroText()).toBe(true);
|
|
55
|
+
|
|
56
|
+
expect(groupingPanel.getInitialChildModelLinks()).toHaveLength(4);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("can handle local taskgroups", () => {
|
|
60
|
+
const groupingPanel = new GroupingPanelModel({
|
|
61
|
+
key: "AskingQuestions",
|
|
62
|
+
data: panelJson,
|
|
63
|
+
contributions: panelContributionsJson,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(groupingPanel.hasTaskGroups()).toBe(true);
|
|
67
|
+
expect(groupingPanel.hasTasks()).toBe(true);
|
|
68
|
+
expect(groupingPanel.taskGroupCollection).toHaveLength(1);
|
|
54
69
|
});
|
|
55
70
|
|
|
56
71
|
it("should be able to handle different kind of introtext", () => {
|
|
57
|
-
const groupingPanelOldStructure = new
|
|
72
|
+
const groupingPanelOldStructure = new GroupingPanelModel({
|
|
58
73
|
key: "Book",
|
|
59
74
|
data: panelJson,
|
|
60
75
|
contributions: panelContributionsJson,
|
|
@@ -64,10 +79,10 @@ describe("groupingPanelModel", () => {
|
|
|
64
79
|
"<p>This is introtext</p>"
|
|
65
80
|
);
|
|
66
81
|
|
|
67
|
-
const groupingPanelFromDataPlain = new
|
|
82
|
+
const groupingPanelFromDataPlain = new GroupingPanelModel({
|
|
68
83
|
key: "Book",
|
|
69
84
|
data: {
|
|
70
|
-
|
|
85
|
+
_content: { text: { message: "<p>This is introtext</p>" } },
|
|
71
86
|
...panelJson,
|
|
72
87
|
},
|
|
73
88
|
contributions: panelContributionsJson,
|
|
@@ -77,12 +92,14 @@ describe("groupingPanelModel", () => {
|
|
|
77
92
|
"<p>This is introtext</p>"
|
|
78
93
|
);
|
|
79
94
|
|
|
80
|
-
const groupingPanelFromDataApplicationMessage = new
|
|
95
|
+
const groupingPanelFromDataApplicationMessage = new GroupingPanelModel({
|
|
81
96
|
key: "Book",
|
|
82
97
|
data: {
|
|
83
98
|
...panelJson,
|
|
84
|
-
|
|
85
|
-
|
|
99
|
+
_content: {
|
|
100
|
+
text: {
|
|
101
|
+
message: "<p>This is introtext</p>",
|
|
102
|
+
},
|
|
86
103
|
},
|
|
87
104
|
},
|
|
88
105
|
contributions: panelContributionsJson,
|
|
@@ -92,29 +109,31 @@ describe("groupingPanelModel", () => {
|
|
|
92
109
|
"<p>This is introtext</p>"
|
|
93
110
|
);
|
|
94
111
|
|
|
95
|
-
const groupingPanelFromNewContributionsRawTextMessage =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
112
|
+
const groupingPanelFromNewContributionsRawTextMessage =
|
|
113
|
+
new GroupingPanelModel({
|
|
114
|
+
key: "Book",
|
|
115
|
+
data: panelJson,
|
|
116
|
+
contributions: {
|
|
117
|
+
...panelContributionsJson,
|
|
118
|
+
text: {
|
|
119
|
+
message: "<p>This is introtext</p>",
|
|
120
|
+
},
|
|
102
121
|
},
|
|
103
|
-
}
|
|
104
|
-
});
|
|
122
|
+
});
|
|
105
123
|
|
|
106
124
|
expect(groupingPanelFromNewContributionsRawTextMessage.introtext).toBe(
|
|
107
125
|
"<p>This is introtext</p>"
|
|
108
126
|
);
|
|
109
127
|
|
|
110
|
-
const groupingPanelFromNewContributionsSimpleMessage =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
128
|
+
const groupingPanelFromNewContributionsSimpleMessage =
|
|
129
|
+
new GroupingPanelModel({
|
|
130
|
+
key: "Book",
|
|
131
|
+
data: panelJson,
|
|
132
|
+
contributions: {
|
|
133
|
+
...panelContributionsJson,
|
|
134
|
+
text: "<p>This is introtext</p>",
|
|
135
|
+
},
|
|
136
|
+
});
|
|
118
137
|
|
|
119
138
|
expect(groupingPanelFromNewContributionsSimpleMessage.introtext).toBe(
|
|
120
139
|
"<p>This is introtext</p>"
|
|
@@ -26,5 +26,24 @@
|
|
|
26
26
|
"name": "TextFragments"
|
|
27
27
|
}
|
|
28
28
|
]
|
|
29
|
-
}
|
|
29
|
+
},
|
|
30
|
+
"taskgroups": [
|
|
31
|
+
{
|
|
32
|
+
"name": "taskgroup",
|
|
33
|
+
"actions": [
|
|
34
|
+
{
|
|
35
|
+
"name": "delivery",
|
|
36
|
+
"method": "POST",
|
|
37
|
+
"href": "/books/book/24/activities/delivery",
|
|
38
|
+
"fields": [
|
|
39
|
+
{
|
|
40
|
+
"name": "PrintAssignmentID",
|
|
41
|
+
"type": "number",
|
|
42
|
+
"value": null
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
]
|
|
30
49
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ProcessStatusSettingsModel from "../ProcessStatusSettingsModel";
|
|
2
|
+
import { DateUtil } from "../../../utils";
|
|
2
3
|
|
|
3
4
|
describe("processStatusSettingsModel", () => {
|
|
4
5
|
it("should be able to create an empty ProcessStatusSettingsModel object", () => {
|
|
@@ -37,5 +38,15 @@ describe("processStatusSettingsModel", () => {
|
|
|
37
38
|
expect(processStatus.isApplicable).toBeTruthy();
|
|
38
39
|
expect(processStatus.isCompleted).toBeFalsy();
|
|
39
40
|
expect(processStatus.isNeeded).toBeTruthy();
|
|
41
|
+
|
|
42
|
+
expect(processStatus.state).toBeNull();
|
|
43
|
+
expect(processStatus.canComplete).toBeNull();
|
|
44
|
+
|
|
45
|
+
expect(processStatus.referenceDate).toBe(DateUtil.now());
|
|
46
|
+
|
|
47
|
+
expect(processStatus.links).toHaveLength(1);
|
|
48
|
+
expect(processStatus.conceptLink.href.path).toBe(
|
|
49
|
+
"/concepts/Research grant/Business design/Constraints/Eligible for research grant.bixml/EligibleResearchGrant"
|
|
50
|
+
);
|
|
40
51
|
});
|
|
41
52
|
});
|
package/src/models/types.js
CHANGED
|
@@ -215,21 +215,21 @@ export type ContentElement = {
|
|
|
215
215
|
},
|
|
216
216
|
};
|
|
217
217
|
|
|
218
|
-
type PropertyElementMapped = {
|
|
218
|
+
export type PropertyElementMapped = {
|
|
219
219
|
propertyElement: {
|
|
220
220
|
label: string,
|
|
221
221
|
layouthint: LayoutHintCollection,
|
|
222
222
|
properties: Array<PropertyData>,
|
|
223
223
|
},
|
|
224
224
|
};
|
|
225
|
-
type TextFragmentElementMapped = {
|
|
225
|
+
export type TextFragmentElementMapped = {
|
|
226
226
|
textFragmentElement: {
|
|
227
227
|
label: string,
|
|
228
228
|
layouthint: LayoutHintCollection,
|
|
229
229
|
textfragments: Array<TextFragmentData>,
|
|
230
230
|
},
|
|
231
231
|
};
|
|
232
|
-
type ContentElementMapped = {
|
|
232
|
+
export type ContentElementMapped = {
|
|
233
233
|
contentElement: {
|
|
234
234
|
label: string,
|
|
235
235
|
layouthint: LayoutHintCollection,
|
|
@@ -386,6 +386,20 @@ class ModularUIRequest {
|
|
|
386
386
|
return Promise.resolve();
|
|
387
387
|
}
|
|
388
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Retrieve an object of key: link
|
|
391
|
+
*/
|
|
392
|
+
dataLinksPerName(dataLinks: any): { [linkName: string]: any } {
|
|
393
|
+
if (Array.isArray(dataLinks)) {
|
|
394
|
+
const links = {};
|
|
395
|
+
for (const dataLink of dataLinks) {
|
|
396
|
+
links[dataLink.name] = dataLink;
|
|
397
|
+
}
|
|
398
|
+
return links;
|
|
399
|
+
}
|
|
400
|
+
return dataLinks;
|
|
401
|
+
}
|
|
402
|
+
|
|
389
403
|
/**
|
|
390
404
|
* Check if links are empty and hide them when hide-when-empty hint exists
|
|
391
405
|
*/
|
|
@@ -393,42 +407,44 @@ class ModularUIRequest {
|
|
|
393
407
|
dataLinks: any,
|
|
394
408
|
contributionLinks: any
|
|
395
409
|
): Promise<Object | Array<Object>> {
|
|
410
|
+
const linksPerName = this.dataLinksPerName(dataLinks);
|
|
411
|
+
const hideWhenEmptyLinks = contributionLinks.filter((contributionLink) =>
|
|
412
|
+
contributionLink.layouthint?.includes(HIDE_WHEN_EMPTY)
|
|
413
|
+
);
|
|
414
|
+
|
|
396
415
|
const isHiddenListChecks = [];
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
isHiddenListChecks.push(
|
|
405
|
-
this.isHiddenList(contributionLink.name, dataLink.href)
|
|
406
|
-
);
|
|
407
|
-
}
|
|
416
|
+
|
|
417
|
+
for (const contributionLink of hideWhenEmptyLinks) {
|
|
418
|
+
const dataLink = linksPerName[contributionLink.name];
|
|
419
|
+
if (dataLink?.href) {
|
|
420
|
+
isHiddenListChecks.push(
|
|
421
|
+
this.isHiddenList(contributionLink.name, dataLink.href)
|
|
422
|
+
);
|
|
408
423
|
}
|
|
409
424
|
}
|
|
410
425
|
|
|
411
|
-
return Promise.all(isHiddenListChecks).then(
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
426
|
+
return Promise.all(isHiddenListChecks).then(
|
|
427
|
+
(hiddenLinks: Array<string>) => {
|
|
428
|
+
if (Array.isArray(dataLinks)) {
|
|
429
|
+
return dataLinks.filter(
|
|
430
|
+
(dataLink) => !hiddenLinks.includes(dataLink.name)
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
const newDataLinks = {};
|
|
419
435
|
for (const dataLinkKey in dataLinks) {
|
|
420
436
|
if (!hiddenLinks.includes(dataLinkKey)) {
|
|
421
437
|
newDataLinks[dataLinkKey] = dataLinks[dataLinkKey];
|
|
422
438
|
}
|
|
423
439
|
}
|
|
440
|
+
return newDataLinks;
|
|
424
441
|
}
|
|
425
|
-
|
|
426
|
-
});
|
|
442
|
+
);
|
|
427
443
|
}
|
|
428
444
|
|
|
429
445
|
/**
|
|
430
446
|
*/
|
|
431
|
-
isHiddenList(name: string, href: string): Promise
|
|
447
|
+
isHiddenList(name: string, href: string): Promise<string> {
|
|
432
448
|
return universalFetch({
|
|
433
449
|
...this.options,
|
|
434
450
|
url: `${BASE}${href}`,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
|
+
import Cookies from "js-cookie";
|
|
3
|
+
|
|
2
4
|
import { BASE } from "../../constants/Constants";
|
|
3
5
|
|
|
4
6
|
type CookieOptions = {
|
|
@@ -7,18 +9,17 @@ type CookieOptions = {
|
|
|
7
9
|
secure?: boolean,
|
|
8
10
|
};
|
|
9
11
|
|
|
12
|
+
type CookieAttributes = {
|
|
13
|
+
path: string,
|
|
14
|
+
expires?: number,
|
|
15
|
+
sameSite?: string,
|
|
16
|
+
secure?: boolean,
|
|
17
|
+
};
|
|
18
|
+
|
|
10
19
|
/**
|
|
11
20
|
*/
|
|
12
21
|
const getCookie = (name: string): null | string => {
|
|
13
|
-
|
|
14
|
-
const value = `;${document.cookie}`;
|
|
15
|
-
const parts = value.split(`; ${name}=`);
|
|
16
|
-
if (parts.length === 2) {
|
|
17
|
-
return parts.pop().split(";").shift();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return null;
|
|
22
|
+
return Cookies.get(name);
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -28,31 +29,24 @@ const setCookie = (
|
|
|
28
29
|
value: any,
|
|
29
30
|
{ days, sameSite = "Strict", secure }: CookieOptions = {}
|
|
30
31
|
) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
let sameSitePart = "";
|
|
41
|
-
if (sameSite) {
|
|
42
|
-
sameSitePart = `; SameSite=${sameSite}`;
|
|
43
|
-
}
|
|
44
|
-
const securePart = secure ? "Secure" : "";
|
|
45
|
-
|
|
46
|
-
document.cookie = `${valuePart}${expires}${sameSitePart}${securePart}; path=${BASE}`;
|
|
32
|
+
const attributes: CookieAttributes = { path: BASE };
|
|
33
|
+
if (days) {
|
|
34
|
+
attributes.expires = days;
|
|
35
|
+
}
|
|
36
|
+
if (sameSite) {
|
|
37
|
+
attributes.sameSite = sameSite;
|
|
38
|
+
}
|
|
39
|
+
if (secure) {
|
|
40
|
+
attributes.secure = secure;
|
|
47
41
|
}
|
|
42
|
+
|
|
43
|
+
Cookies.set(name, value, attributes);
|
|
48
44
|
};
|
|
49
45
|
|
|
50
46
|
/**
|
|
51
47
|
*/
|
|
52
48
|
const clearCookie = (name: string) => {
|
|
53
|
-
|
|
54
|
-
document.cookie = `${name}=; Max-Age=-99999999;`;
|
|
55
|
-
}
|
|
49
|
+
Cookies.remove(name, { path: BASE });
|
|
56
50
|
};
|
|
57
51
|
|
|
58
52
|
export { getCookie, setCookie, clearCookie };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { getCookie, setCookie, clearCookie } from "../Cookies";
|
|
2
|
+
|
|
3
|
+
describe("cookies util", () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
Object.defineProperty(
|
|
6
|
+
window.document,
|
|
7
|
+
"cookie",
|
|
8
|
+
(function (cookies) {
|
|
9
|
+
return {
|
|
10
|
+
get: function _get() {
|
|
11
|
+
const output = [];
|
|
12
|
+
for (const cookieName in cookies) {
|
|
13
|
+
output.push(cookieName + "=" + cookies[cookieName]);
|
|
14
|
+
}
|
|
15
|
+
return output.join("; ");
|
|
16
|
+
},
|
|
17
|
+
set: function _set(s) {
|
|
18
|
+
const indexOfSeparator = s.indexOf("=");
|
|
19
|
+
const key = s.substr(0, indexOfSeparator);
|
|
20
|
+
const value = s.substring(indexOfSeparator + 1);
|
|
21
|
+
const valueWithoutAttributes = value.substr(0, value.indexOf(";"));
|
|
22
|
+
|
|
23
|
+
if (valueWithoutAttributes === "") {
|
|
24
|
+
delete cookies[key];
|
|
25
|
+
} else {
|
|
26
|
+
cookies[key] = value;
|
|
27
|
+
}
|
|
28
|
+
return key + "=" + value;
|
|
29
|
+
},
|
|
30
|
+
reset: function _reset() {
|
|
31
|
+
cookies = {};
|
|
32
|
+
},
|
|
33
|
+
configurable: true,
|
|
34
|
+
};
|
|
35
|
+
})({})
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should be able retrieve cookies by name", () => {
|
|
40
|
+
setCookie("newCookie", "test");
|
|
41
|
+
expect(getCookie("newCookie")).toBe("test");
|
|
42
|
+
|
|
43
|
+
setCookie("newCookie2", "test2");
|
|
44
|
+
expect(getCookie("newCookie")).toBe("test");
|
|
45
|
+
expect(getCookie("newCookie2")).toBe("test2");
|
|
46
|
+
|
|
47
|
+
clearCookie("newCookie2");
|
|
48
|
+
expect(getCookie("newCookie")).toBe("test");
|
|
49
|
+
expect(getCookie("newCookie2")).toBeUndefined();
|
|
50
|
+
});
|
|
51
|
+
});
|