@beinformed/ui 1.27.5 → 1.28.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.
Files changed (134) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/esm/constants/LayoutHintConfig.js +0 -9
  3. package/esm/constants/LayoutHintConfig.js.map +1 -1
  4. package/esm/constants/LayoutHints.js +0 -4
  5. package/esm/constants/LayoutHints.js.map +1 -1
  6. package/esm/constants/Settings.js +0 -4
  7. package/esm/constants/Settings.js.map +1 -1
  8. package/esm/hooks/useForm.js.map +1 -1
  9. package/esm/models/attributes/ChoiceAttributeModel.js +1 -0
  10. package/esm/models/attributes/ChoiceAttributeModel.js.map +1 -1
  11. package/esm/models/attributes/ChoiceAttributeOptionModel.js +2 -2
  12. package/esm/models/attributes/ChoiceAttributeOptionModel.js.map +1 -1
  13. package/esm/models/attributes/DatetimeAttributeModel.js +3 -29
  14. package/esm/models/attributes/DatetimeAttributeModel.js.map +1 -1
  15. package/esm/react-client/Init.js +2 -2
  16. package/esm/react-client/Init.js.map +1 -1
  17. package/esm/react-client/client.js +80 -52
  18. package/esm/react-client/client.js.map +1 -1
  19. package/esm/redux/_modularui/ModularUIActions.js +7 -0
  20. package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
  21. package/esm/redux/_modularui/ModularUIReducer.js +1 -0
  22. package/esm/redux/_modularui/ModularUIReducer.js.map +1 -1
  23. package/esm/redux/_modularui/types.js.map +1 -1
  24. package/esm/redux/actions/Form.js +2 -2
  25. package/esm/redux/actions/Form.js.map +1 -1
  26. package/esm/redux/actions/FormAttributeSet.js +2 -2
  27. package/esm/redux/actions/FormAttributeSet.js.map +1 -1
  28. package/esm/redux/actions/FormAttributeSetRepeatable.js +4 -4
  29. package/esm/redux/actions/FormAttributeSetRepeatable.js.map +1 -1
  30. package/esm/redux/actions/FormAutosave.js +2 -2
  31. package/esm/redux/actions/FormAutosave.js.map +1 -1
  32. package/esm/redux/actions/FormValidations.js +2 -2
  33. package/esm/redux/actions/FormValidations.js.map +1 -1
  34. package/esm/redux/connectors/Form.js.map +1 -1
  35. package/esm/redux/connectors/FormAttributeSet.js.map +1 -1
  36. package/esm/redux/store/configureStore.js +4 -4
  37. package/esm/redux/store/configureStore.js.map +1 -1
  38. package/esm/redux/types.js.map +1 -1
  39. package/lib/constants/LayoutHintConfig.js +0 -9
  40. package/lib/constants/LayoutHintConfig.js.flow +0 -9
  41. package/lib/constants/LayoutHintConfig.js.map +1 -1
  42. package/lib/constants/LayoutHints.js +2 -7
  43. package/lib/constants/LayoutHints.js.flow +0 -4
  44. package/lib/constants/LayoutHints.js.map +1 -1
  45. package/lib/constants/Settings.js +0 -4
  46. package/lib/constants/Settings.js.flow +0 -6
  47. package/lib/constants/Settings.js.map +1 -1
  48. package/lib/hooks/__tests__/useForm.spec.js.flow +4 -4
  49. package/lib/hooks/useForm.js.flow +5 -5
  50. package/lib/hooks/useForm.js.map +1 -1
  51. package/lib/models/attributes/ChoiceAttributeModel.js +1 -0
  52. package/lib/models/attributes/ChoiceAttributeModel.js.flow +1 -0
  53. package/lib/models/attributes/ChoiceAttributeModel.js.map +1 -1
  54. package/lib/models/attributes/ChoiceAttributeOptionModel.js +2 -2
  55. package/lib/models/attributes/ChoiceAttributeOptionModel.js.flow +2 -2
  56. package/lib/models/attributes/ChoiceAttributeOptionModel.js.map +1 -1
  57. package/lib/models/attributes/DatetimeAttributeModel.js +3 -29
  58. package/lib/models/attributes/DatetimeAttributeModel.js.flow +7 -41
  59. package/lib/models/attributes/DatetimeAttributeModel.js.map +1 -1
  60. package/lib/models/attributes/__tests__/DateAttributeModel.spec.js.flow +1 -35
  61. package/lib/models/attributes/__tests__/DatetimeAttributeModel.spec.js.flow +158 -216
  62. package/lib/models/attributes/__tests__/TimestampModel.spec.js.flow +0 -5
  63. package/lib/react-client/Init.js +2 -2
  64. package/lib/react-client/Init.js.flow +3 -3
  65. package/lib/react-client/Init.js.map +1 -1
  66. package/lib/react-client/client.js +83 -53
  67. package/lib/react-client/client.js.flow +106 -67
  68. package/lib/react-client/client.js.map +1 -1
  69. package/lib/redux/_modularui/ModularUIActions.js +9 -1
  70. package/lib/redux/_modularui/ModularUIActions.js.flow +8 -0
  71. package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
  72. package/lib/redux/_modularui/ModularUIReducer.js +1 -0
  73. package/lib/redux/_modularui/ModularUIReducer.js.flow +1 -0
  74. package/lib/redux/_modularui/ModularUIReducer.js.map +1 -1
  75. package/lib/redux/_modularui/types.js.flow +5 -0
  76. package/lib/redux/_modularui/types.js.map +1 -1
  77. package/lib/redux/actions/Form.js +1 -1
  78. package/lib/redux/actions/Form.js.flow +4 -4
  79. package/lib/redux/actions/Form.js.map +1 -1
  80. package/lib/redux/actions/FormAttributeSet.js +1 -1
  81. package/lib/redux/actions/FormAttributeSet.js.flow +3 -2
  82. package/lib/redux/actions/FormAttributeSet.js.map +1 -1
  83. package/lib/redux/actions/FormAttributeSetRepeatable.js +3 -3
  84. package/lib/redux/actions/FormAttributeSetRepeatable.js.flow +8 -8
  85. package/lib/redux/actions/FormAttributeSetRepeatable.js.map +1 -1
  86. package/lib/redux/actions/FormAutosave.js +1 -1
  87. package/lib/redux/actions/FormAutosave.js.flow +2 -2
  88. package/lib/redux/actions/FormAutosave.js.map +1 -1
  89. package/lib/redux/actions/FormValidations.js +1 -1
  90. package/lib/redux/actions/FormValidations.js.flow +2 -2
  91. package/lib/redux/actions/FormValidations.js.map +1 -1
  92. package/lib/redux/actions/__tests__/Form.spec.js.flow +1 -1
  93. package/lib/redux/connectors/Form.js.flow +2 -5
  94. package/lib/redux/connectors/Form.js.map +1 -1
  95. package/lib/redux/connectors/FormAttributeSet.js.flow +5 -5
  96. package/lib/redux/connectors/FormAttributeSet.js.map +1 -1
  97. package/lib/redux/store/configureStore.js +4 -4
  98. package/lib/redux/store/configureStore.js.flow +5 -5
  99. package/lib/redux/store/configureStore.js.map +1 -1
  100. package/lib/redux/types.js.flow +2 -0
  101. package/lib/redux/types.js.map +1 -1
  102. package/package.json +17 -19
  103. package/src/constants/LayoutHintConfig.js +0 -9
  104. package/src/constants/LayoutHints.js +0 -4
  105. package/src/constants/Settings.js +0 -6
  106. package/src/hooks/__tests__/useForm.spec.js +4 -4
  107. package/src/hooks/useForm.js +5 -5
  108. package/src/models/attributes/ChoiceAttributeModel.js +1 -0
  109. package/src/models/attributes/ChoiceAttributeOptionModel.js +2 -2
  110. package/src/models/attributes/DatetimeAttributeModel.js +7 -41
  111. package/src/models/attributes/__tests__/DateAttributeModel.spec.js +1 -35
  112. package/src/models/attributes/__tests__/DatetimeAttributeModel.spec.js +158 -216
  113. package/src/models/attributes/__tests__/TimestampModel.spec.js +0 -5
  114. package/src/react-client/Init.js +3 -3
  115. package/src/react-client/client.js +106 -67
  116. package/src/redux/_modularui/ModularUIActions.js +8 -0
  117. package/src/redux/_modularui/ModularUIReducer.js +1 -0
  118. package/src/redux/_modularui/types.js +5 -0
  119. package/src/redux/actions/Form.js +4 -4
  120. package/src/redux/actions/FormAttributeSet.js +3 -2
  121. package/src/redux/actions/FormAttributeSetRepeatable.js +8 -8
  122. package/src/redux/actions/FormAutosave.js +2 -2
  123. package/src/redux/actions/FormValidations.js +2 -2
  124. package/src/redux/actions/__tests__/Form.spec.js +1 -1
  125. package/src/redux/connectors/Form.js +2 -5
  126. package/src/redux/connectors/FormAttributeSet.js +5 -5
  127. package/src/redux/store/configureStore.js +5 -5
  128. package/src/redux/types.js +2 -0
  129. package/types/constants/LayoutHintConfig.d.ts +8 -23
  130. package/types/constants/LayoutHints.d.ts +0 -4
  131. package/types/models/actions/ActionCollection.d.ts +1 -1
  132. package/types/models/attributes/DatetimeAttributeModel.d.ts +8 -2
  133. package/types/redux/_modularui/types.d.ts +4 -0
  134. package/types/redux/types.d.ts +1 -1
@@ -66,8 +66,8 @@ class ChoiceAttributeOptionModel
66
66
  const option = new ChoiceAttributeOptionModel();
67
67
 
68
68
  option.code = listitem.id.toString();
69
- option.attributeCollection = listitem.attributeCollection;
70
- option.links = listitem.links;
69
+ option.attributeCollection = listitem.attributeCollection.clone();
70
+ option.links = listitem.links.clone();
71
71
 
72
72
  return option;
73
73
  }
@@ -17,14 +17,9 @@ import DatetimeFormatConstraint from "./input-constraints/DatetimeFormatConstrai
17
17
  import DateBoundaryConstraint from "./input-constraints/DateBoundaryConstraint";
18
18
 
19
19
  import { ATTRIBUTE_WIDTH, ISO_DATE_FORMAT } from "../../constants";
20
- import { getSetting } from "../../constants/Settings";
21
- import { IGNORE_FORMAT_SETTING } from "../../constants/LayoutHints";
22
20
 
23
21
  import type { FormErrorAnchor, IConstraintModel } from "../types";
24
22
 
25
- // date format of default
26
- const PRODUCT_DEFAULT_DATE_FORMAT = "dd-MM-yyyy";
27
-
28
23
  /**
29
24
  */
30
25
  class DatetimeAttributeModel extends StringAttributeModel {
@@ -239,22 +234,9 @@ class DatetimeAttributeModel extends StringAttributeModel {
239
234
  return "";
240
235
  }
241
236
 
242
- // setting for date input
243
- const ignoreFormatSetting = this.layouthint.has(IGNORE_FORMAT_SETTING);
244
- if (!ignoreFormatSetting) {
245
- const dateInputFormatSetting = getSetting("DATE_INPUT_FORMAT", "");
246
- if (dateInputFormatSetting) {
247
- return dateInputFormatSetting;
248
- }
249
- }
250
-
251
- let format = this.format;
252
-
253
- let dateFormat = this.hasTime
254
- ? format.replace(this.timeInputFormat, "").trim()
255
- : format;
256
-
257
- return dateFormat;
237
+ return this.hasTime
238
+ ? this.format.replace(this.timeInputFormat, "").trim()
239
+ : this.format;
258
240
  }
259
241
 
260
242
  /**
@@ -264,35 +246,19 @@ class DatetimeAttributeModel extends StringAttributeModel {
264
246
  return "";
265
247
  }
266
248
 
267
- let format = this.format;
268
-
269
- let dateFormat = this.hasTime
270
- ? format.replace(this.timeInputFormat, "").trim()
271
- : format;
272
-
273
- const readonlyFormatSetting = getSetting("DATE_READONLY_FORMAT", "");
274
-
275
- if (dateFormat === PRODUCT_DEFAULT_DATE_FORMAT && readonlyFormatSetting) {
276
- dateFormat = readonlyFormatSetting;
277
- }
278
-
279
- return dateFormat;
249
+ return this.hasTime
250
+ ? this.format.replace(this.timeInputFormat, "").trim()
251
+ : this.format;
280
252
  }
281
253
 
282
254
  /**
283
- * return attribute placeholder or, if DATE_INPUT_FORMAT setting is used, lowercased setting, otherwise return formatlabel without time input format from contributions
255
+ * return attribute placeholder or return formatlabel without time input format from contributions
284
256
  */
285
257
  get placeholder(): string {
286
258
  if (this._placeholder !== "") {
287
259
  return this._placeholder;
288
260
  }
289
261
 
290
- const dateInputFormatSetting = getSetting("DATE_INPUT_FORMAT", "");
291
-
292
- if (dateInputFormatSetting) {
293
- return dateInputFormatSetting.toLowerCase();
294
- }
295
-
296
262
  const formatLabel = this.getContribution("formatlabel", "");
297
263
 
298
264
  if (this.hasDate && this.hasTime && formatLabel.includes(" ")) {
@@ -1,12 +1,7 @@
1
1
  import DatetimeAttributeModel from "../DatetimeAttributeModel";
2
- import { setSettings } from "../../../constants/Settings";
3
2
 
4
3
  describe("dateAttributeModel", () => {
5
4
  describe("with date related settings set", () => {
6
- beforeAll(() => {
7
- setSettings({ DATE_INPUT_FORMAT: "dd-MM-yyyy" });
8
- setSettings({ DATE_READONLY_FORMAT: "dd-MM-yyyy" });
9
- });
10
5
  it("should be able to create an empty Attribute object", () => {
11
6
  const attribute = new DatetimeAttributeModel();
12
7
 
@@ -51,7 +46,7 @@ describe("dateAttributeModel", () => {
51
46
 
52
47
  it("can set input", () => {
53
48
  const attribute = new DatetimeAttributeModel({});
54
- attribute.inputvalue = "10-12-2010";
49
+ attribute.inputvalue = "2010-12-10";
55
50
 
56
51
  expect(attribute.readonlyvalue).toBe("2010-12-10");
57
52
 
@@ -65,36 +60,7 @@ describe("dateAttributeModel", () => {
65
60
  });
66
61
  });
67
62
 
68
- describe("with non default date related settings configured", () => {
69
- beforeAll(() => {
70
- setSettings({ DATE_INPUT_FORMAT: "MM/dd/yyyy" });
71
- setSettings({ DATE_READONLY_FORMAT: "mm/dd/yyyy" });
72
- });
73
-
74
- it("returns the right date formats", () => {
75
- const attribute = new DatetimeAttributeModel(
76
- {},
77
- {
78
- label: "Date of birth",
79
- type: "date",
80
- format: "dd-MM-yyyy",
81
- formatlabel: "dd-mm-yyyy",
82
- }
83
- );
84
-
85
- // expect date input and readonly format to match the settings
86
- expect(attribute.format).toBe("dd-MM-yyyy");
87
- expect(attribute.dateInputFormat).toBe("MM/dd/yyyy");
88
- expect(attribute.dateReadonlyFormat).toBe("mm/dd/yyyy");
89
- });
90
- });
91
-
92
63
  describe("without date input and date readonly settings defined", () => {
93
- beforeAll(() => {
94
- // explicitly clear setting
95
- setSettings({ DATE_INPUT_FORMAT: "" });
96
- setSettings({ DATE_READONLY_FORMAT: "" });
97
- });
98
64
  it("should be able to return contributions format as date input format", () => {
99
65
  const attribute = new DatetimeAttributeModel(
100
66
  {},
@@ -1,226 +1,168 @@
1
1
  import DatetimeAttributeModel from "../DatetimeAttributeModel";
2
- import { setSettings } from "../../../constants/Settings";
3
2
  import { ATTRIBUTE_WIDTH } from "../../../constants";
4
3
 
5
4
  describe("datetimeAttributeModel", () => {
6
- describe("with date readonly format in product default format", () => {
7
- beforeAll(() => {
8
- // using product default format
9
- setSettings({ DATE_READONLY_FORMAT: "dd-MM-yyyy" });
10
- setSettings({ DATE_INPUT_FORMAT: "dd-MM-yyyy" });
11
- });
12
-
13
- it("should be able to create an empty DatetimeAttribute object", () => {
14
- const attribute = new DatetimeAttributeModel({}, { type: "datetime" });
15
-
16
- expect(attribute).toBeInstanceOf(DatetimeAttributeModel);
17
-
18
- expect(attribute.type).toBe("datetime");
19
- expect(attribute.format).toBe("yyyy-MM-dd'T'HH:mm:ss");
20
- expect(attribute.getInputValue()).toBe("");
21
- expect(attribute.inputvalue).toBe("");
22
- expect(attribute.readonlyvalue).toBe("");
23
-
24
- attribute.addConstraints();
25
- expect(attribute.constraintCollection).toHaveLength(1);
26
- });
27
-
28
- it("should be able to update", () => {
29
- const attribute = new DatetimeAttributeModel(
30
- {},
31
- {
32
- type: "datetime",
33
- format: "dd-MM-yyyy HH:mm",
34
- }
35
- );
36
-
37
- attribute.update("18-08-2016 13:45");
38
- expect(attribute.getInputValue()).toBe("18-08-2016 13:45");
39
- expect(attribute.getInitialInputValue("2016-08-18T13:45:23")).toBe(
40
- "18-08-2016 13:45"
41
- );
42
-
43
- expect(attribute.readonlyvalue).toBe("18-08-2016 13:45");
44
-
45
- attribute.update(null);
46
- expect(attribute.getInputValue()).toBe("");
47
-
48
- attribute.update("");
49
- expect(attribute.value).toBeNull();
50
-
51
- attribute.update("aaaa");
52
- expect(attribute.value).toBe("Invalid Date");
53
- });
54
-
55
- it("should be able to handle min and max date in only date format and renders in format", () => {
56
- const attribute = new DatetimeAttributeModel(
57
- {},
58
- {
59
- type: "datetime",
60
- format: "dd-MM-yyyy HH:mm",
61
- mindate: "2010-10-01T00:00:00",
62
- maxdate: "2010-10-31T23:59:59",
63
- }
64
- );
65
-
66
- attribute.update("18-08-2016 13:45");
67
-
68
- expect(attribute.isValid).toBe(false);
69
- expect(attribute.formatValue(attribute.mindate)).toBe("01-10-2010 00:00");
70
- expect(attribute.formatValue(attribute.maxdate)).toBe("31-10-2010 23:59");
71
- });
5
+ it("should be able to create an empty DatetimeAttribute object", () => {
6
+ const attribute = new DatetimeAttributeModel({}, { type: "datetime" });
7
+
8
+ expect(attribute).toBeInstanceOf(DatetimeAttributeModel);
9
+
10
+ expect(attribute.type).toBe("datetime");
11
+ expect(attribute.format).toBe("yyyy-MM-dd'T'HH:mm:ss");
12
+ expect(attribute.getInputValue()).toBe("");
13
+ expect(attribute.inputvalue).toBe("");
14
+ expect(attribute.readonlyvalue).toBe("");
15
+
16
+ attribute.addConstraints();
17
+ expect(attribute.constraintCollection).toHaveLength(1);
72
18
  });
73
19
 
74
- describe("with customized readonly format for dates", () => {
75
- beforeAll(() => {
76
- // readonly format in non product default format
77
- setSettings({ DATE_READONLY_FORMAT: "MM-dd-yyyy" });
78
- });
79
-
80
- it("should show datetime readonly value in custom date format", () => {
81
- const attribute = new DatetimeAttributeModel(
82
- {},
83
- {
84
- type: "datetime",
85
- format: "dd-MM-yyyy HH:mm",
86
- }
87
- );
88
-
89
- attribute.update("18-08-2016 13:45");
90
- expect(attribute.readonlyvalue).toBe("08-18-2016 13:45");
91
- });
92
-
93
- it("should show date only value according in custom date format", () => {
94
- const attribute = new DatetimeAttributeModel(
95
- { value: "2017-07-29" },
96
- {
97
- type: "date",
98
- format: "dd-MM-yyyy",
99
- }
100
- );
101
-
102
- expect(attribute.readonlyvalue).toBe("07-29-2017");
103
- });
104
-
105
- it("should show custom format with am/pm in custom date format", () => {
106
- const attribute = new DatetimeAttributeModel(
107
- { value: "2031-12-21T17:41:21" },
108
- { type: "datetime", format: "dd-MM-yyyy hh:mm:ss a" }
109
- );
110
-
111
- expect(attribute.readonlyvalue).toBe("12-21-2031 05:41:21 PM");
112
- });
113
-
114
- it("should return AttributeWidth for dates", () => {
115
- const attribute = new DatetimeAttributeModel(
116
- {},
117
- {
118
- type: "date",
119
- }
120
- );
121
- expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.SMALL);
122
- });
123
-
124
- it("should return AttributeWidth for times", () => {
125
- const attribute = new DatetimeAttributeModel(
126
- {},
127
- {
128
- type: "time",
129
- }
130
- );
131
- expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.SMALL);
132
- });
133
-
134
- it("should return AttributeWidth for datetime", () => {
135
- const attribute = new DatetimeAttributeModel(
136
- {},
137
- {
138
- type: "datetime",
139
- }
140
- );
141
- expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.MEDIUM);
142
- });
143
-
144
- it("can validate datetime with datetime format", () => {
145
- const datetimeFormat = new DatetimeAttributeModel(
146
- {},
147
- {
148
- type: "datetime",
149
- format: "dd-MM-yyyy HH:mm",
150
- }
151
- );
152
-
153
- expect(datetimeFormat.validate("19-10-2010 1:45")).toBe(true);
154
- expect(datetimeFormat.validate("19-10-2010 13:45")).toBe(true);
155
-
156
- expect(datetimeFormat.validate("19-10-2010")).toBe(false);
157
- expect(datetimeFormat.validate("13:45")).toBe(false);
158
- expect(datetimeFormat.validate("19-10-2010 1:45 am")).toBe(false);
159
- });
160
-
161
- it("can validate datetime with only date format", () => {
162
- const dateFormat = new DatetimeAttributeModel(
163
- {},
164
- {
165
- type: "datetime",
166
- format: "dd-MM-yyyy",
167
- }
168
- );
169
-
170
- expect(dateFormat.validate("19-10-2010")).toBe(true);
171
-
172
- expect(dateFormat.validate("19-10-2010 1:45")).toBe(false);
173
- expect(dateFormat.validate("13:45")).toBe(false);
174
- expect(dateFormat.validate("19-10-2010 1:45 am")).toBe(false);
175
- });
176
-
177
- it("can validate datetime with datetime am/pm format", () => {
178
- const datetimeAmPmFormat = new DatetimeAttributeModel(
179
- {},
180
- {
181
- type: "datetime",
182
- format: "dd-MM-yyyy hh:mm a",
183
- }
184
- );
185
-
186
- expect(datetimeAmPmFormat.validate("19-10-2010 1:45 am")).toBe(true);
187
- expect(datetimeAmPmFormat.validate("19-10-2010 1:45 pm")).toBe(true);
188
-
189
- expect(datetimeAmPmFormat.validate("19-10-2010 1:45")).toBe(false);
190
- expect(datetimeAmPmFormat.validate("19-10-2010 13:45")).toBe(false);
191
- });
192
-
193
- it("can handle old datetime format with ms", () => {
194
- const attribute = new DatetimeAttributeModel(
195
- { value: "2031-12-21T17:41:21.000" },
196
- {
197
- type: "datetime",
198
- format: "dd-MM-yyyy HH:mm",
199
- }
200
- );
201
-
202
- expect(attribute.readonlyvalue).toBe("12-21-2031 17:41");
203
- });
20
+ it("should be able to update", () => {
21
+ const attribute = new DatetimeAttributeModel(
22
+ {},
23
+ {
24
+ type: "datetime",
25
+ format: "dd-MM-yyyy HH:mm",
26
+ }
27
+ );
28
+
29
+ attribute.update("18-08-2016 13:45");
30
+ expect(attribute.getInputValue()).toBe("18-08-2016 13:45");
31
+ expect(attribute.getInitialInputValue("2016-08-18T13:45:23")).toBe(
32
+ "18-08-2016 13:45"
33
+ );
34
+
35
+ expect(attribute.readonlyvalue).toBe("18-08-2016 13:45");
36
+
37
+ attribute.update(null);
38
+ expect(attribute.getInputValue()).toBe("");
39
+
40
+ attribute.update("");
41
+ expect(attribute.value).toBeNull();
42
+
43
+ attribute.update("aaaa");
44
+ expect(attribute.value).toBe("Invalid Date");
45
+ });
46
+
47
+ it("should be able to handle min and max date in only date format and renders in format", () => {
48
+ const attribute = new DatetimeAttributeModel(
49
+ {},
50
+ {
51
+ type: "datetime",
52
+ format: "dd-MM-yyyy HH:mm",
53
+ mindate: "2010-10-01T00:00:00",
54
+ maxdate: "2010-10-31T23:59:59",
55
+ }
56
+ );
57
+
58
+ attribute.update("18-08-2016 13:45");
59
+
60
+ expect(attribute.isValid).toBe(false);
61
+ expect(attribute.formatValue(attribute.mindate)).toBe("01-10-2010 00:00");
62
+ expect(attribute.formatValue(attribute.maxdate)).toBe("31-10-2010 23:59");
63
+ });
64
+
65
+ it("should return AttributeWidth for dates", () => {
66
+ const attribute = new DatetimeAttributeModel(
67
+ {},
68
+ {
69
+ type: "date",
70
+ }
71
+ );
72
+ expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.SMALL);
73
+ });
74
+
75
+ it("should return AttributeWidth for times", () => {
76
+ const attribute = new DatetimeAttributeModel(
77
+ {},
78
+ {
79
+ type: "time",
80
+ }
81
+ );
82
+ expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.SMALL);
83
+ });
84
+
85
+ it("should return AttributeWidth for datetime", () => {
86
+ const attribute = new DatetimeAttributeModel(
87
+ {},
88
+ {
89
+ type: "datetime",
90
+ }
91
+ );
92
+ expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.MEDIUM);
93
+ });
94
+
95
+ it("can validate datetime with datetime format", () => {
96
+ const datetimeFormat = new DatetimeAttributeModel(
97
+ {},
98
+ {
99
+ type: "datetime",
100
+ format: "dd-MM-yyyy HH:mm",
101
+ }
102
+ );
103
+
104
+ expect(datetimeFormat.validate("19-10-2010 1:45")).toBe(true);
105
+ expect(datetimeFormat.validate("19-10-2010 13:45")).toBe(true);
106
+
107
+ expect(datetimeFormat.validate("19-10-2010")).toBe(false);
108
+ expect(datetimeFormat.validate("13:45")).toBe(false);
109
+ expect(datetimeFormat.validate("19-10-2010 1:45 am")).toBe(false);
110
+ });
111
+
112
+ it("can validate datetime with only date format", () => {
113
+ const dateFormat = new DatetimeAttributeModel(
114
+ {},
115
+ {
116
+ type: "datetime",
117
+ format: "dd-MM-yyyy",
118
+ }
119
+ );
120
+
121
+ expect(dateFormat.validate("19-10-2010")).toBe(true);
122
+
123
+ expect(dateFormat.validate("19-10-2010 1:45")).toBe(false);
124
+ expect(dateFormat.validate("13:45")).toBe(false);
125
+ expect(dateFormat.validate("19-10-2010 1:45 am")).toBe(false);
126
+ });
127
+
128
+ it("can validate datetime with datetime am/pm format", () => {
129
+ const datetimeAmPmFormat = new DatetimeAttributeModel(
130
+ {},
131
+ {
132
+ type: "datetime",
133
+ format: "dd-MM-yyyy hh:mm a",
134
+ }
135
+ );
136
+
137
+ expect(datetimeAmPmFormat.validate("19-10-2010 1:45 am")).toBe(true);
138
+ expect(datetimeAmPmFormat.validate("19-10-2010 1:45 pm")).toBe(true);
139
+
140
+ expect(datetimeAmPmFormat.validate("19-10-2010 1:45")).toBe(false);
141
+ expect(datetimeAmPmFormat.validate("19-10-2010 13:45")).toBe(false);
142
+ });
143
+
144
+ it("can handle old datetime format with ms", () => {
145
+ const attribute = new DatetimeAttributeModel(
146
+ { value: "2031-12-21T17:41:21.000" },
147
+ {
148
+ type: "datetime",
149
+ format: "dd-MM-yyyy HH:mm",
150
+ }
151
+ );
152
+
153
+ expect(attribute.readonlyvalue).toBe("21-12-2031 17:41");
204
154
  });
205
155
 
206
- describe("without date input and date readonly settings defined", () => {
207
- beforeAll(() => {
208
- // explicitly clear setting
209
- setSettings({ DATE_INPUT_FORMAT: "" });
210
- setSettings({ DATE_READONLY_FORMAT: "" });
211
- });
212
-
213
- it("returns date part of formatlabel as placeholder if attribute has date and time", () => {
214
- const attribute = new DatetimeAttributeModel(
215
- {},
216
- {
217
- type: "datetime",
218
- format: "dd-MM-yyyy HH:mm",
219
- formatlabel: "dd-MM-yyyy HH:mm",
220
- }
221
- );
222
-
223
- expect(attribute.placeholder).toBe("dd-MM-yyyy");
224
- });
156
+ it("returns date part of formatlabel as placeholder if attribute has date and time", () => {
157
+ const attribute = new DatetimeAttributeModel(
158
+ {},
159
+ {
160
+ type: "datetime",
161
+ format: "dd-MM-yyyy HH:mm",
162
+ formatlabel: "dd-MM-yyyy HH:mm",
163
+ }
164
+ );
165
+
166
+ expect(attribute.placeholder).toBe("dd-MM-yyyy");
225
167
  });
226
168
  });
@@ -1,10 +1,5 @@
1
1
  import DatetimeAttributeModel from "../DatetimeAttributeModel";
2
- import { setSettings } from "../../../constants/Settings";
3
-
4
2
  describe("timestampAttributeModel", () => {
5
- beforeAll(() => {
6
- setSettings({ DATE_INPUT_FORMAT: "dd-MM-yyyy" });
7
- });
8
3
  it("should be able to create an empty TimestampAttribute object", () => {
9
4
  const attribute = new DatetimeAttributeModel({}, { type: "timestamp" });
10
5
 
@@ -14,7 +14,7 @@ import type { Props as FallbackProps } from "../react/ErrorBoundaryFallback";
14
14
 
15
15
  export type Props = {
16
16
  +store: ReduxStore,
17
- +history: RouterHistory,
17
+ +routerHistory: RouterHistory,
18
18
  +contextPath: string,
19
19
  +theme?: Theme | Array<Theme>,
20
20
  +children: ?Node,
@@ -25,7 +25,7 @@ export type Props = {
25
25
  */
26
26
  const Init = ({
27
27
  store,
28
- history,
28
+ routerHistory,
29
29
  contextPath,
30
30
  theme,
31
31
  children,
@@ -35,7 +35,7 @@ const Init = ({
35
35
  <ThemeProvider theme={theme}>
36
36
  <HelmetProvider>
37
37
  <ErrorBoundary FallbackComponent={ErrorFallbackComponent}>
38
- <Router history={history} basename={contextPath}>
38
+ <Router history={routerHistory} basename={contextPath}>
39
39
  {children}
40
40
  </Router>
41
41
  </ErrorBoundary>