orc-shared 5.7.0-dev.0 → 5.7.0-dev.2

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 (34) hide show
  1. package/dist/components/MaterialUI/DataDisplay/Modal.js +3 -3
  2. package/dist/components/MaterialUI/DataDisplay/TransferList.js +2 -3
  3. package/dist/components/MaterialUI/Inputs/Checkbox.js +3 -4
  4. package/dist/components/MaterialUI/Inputs/CheckboxGroup.js +5 -6
  5. package/dist/components/MaterialUI/Inputs/InputBase.js +11 -0
  6. package/dist/components/MaterialUI/Inputs/Select.js +1 -2
  7. package/dist/components/MaterialUI/Inputs/StandaloneRadio.js +2 -3
  8. package/dist/components/MaterialUI/Inputs/createInput.js +3 -4
  9. package/dist/components/MaterialUI/muiThemes.js +10 -11
  10. package/dist/components/Routing/SubPage.js +5 -4
  11. package/dist/constants.js +53 -1
  12. package/dist/hocs/withToggle.js +1 -2
  13. package/dist/hooks/useDispatchWithErrorHandling.js +24 -9
  14. package/dist/reducers/authentication.js +3 -0
  15. package/dist/sharedMessages.js +8 -0
  16. package/dist/utils/modelValidationHelper.js +5 -6
  17. package/dist/utils/propertyBagHelper.js +265 -0
  18. package/dist/utils/responseProcessingHelper.js +17 -3
  19. package/package.json +1 -1
  20. package/src/components/MaterialUI/Inputs/InputBase.js +18 -0
  21. package/src/components/MaterialUI/Inputs/InputBase.test.js +156 -0
  22. package/src/components/Routing/SubPage.js +6 -5
  23. package/src/constants.js +48 -0
  24. package/src/hooks/useDispatchWithErrorHandling.js +16 -2
  25. package/src/hooks/useDispatchWithErrorHandling.test.js +15 -13
  26. package/src/reducers/authentication.js +5 -0
  27. package/src/reducers/authentication.test.js +81 -0
  28. package/src/sharedMessages.js +8 -0
  29. package/src/translations/en-US.json +2 -0
  30. package/src/translations/fr-CA.json +2 -0
  31. package/src/utils/propertyBagHelper.js +239 -0
  32. package/src/utils/propertyBagHelper.test.js +709 -0
  33. package/src/utils/responseProcessingHelper.js +28 -3
  34. package/src/utils/responseProcessingHelper.test.js +256 -12
@@ -0,0 +1,709 @@
1
+ import React from "react";
2
+ import { useIntl } from "react-intl";
3
+ import {
4
+ customDataType,
5
+ toJsonCargo,
6
+ formatNumber,
7
+ fixPropertyBagModifiedModel,
8
+ setRequiredBooleansDefault,
9
+ getPropertyBagFormattedPrimitiveValue,
10
+ isTieredAttribute,
11
+ } from "./propertyBagHelper";
12
+ import { createMuiTheme, extractMessages, TestWrapper } from "./testUtils";
13
+ import { mount } from "enzyme";
14
+ import Immutable from "immutable";
15
+ import sharedMessages from "~/sharedMessages";
16
+ import _ from "lodash";
17
+ import { attributeDataType } from "../constants";
18
+
19
+ const messages = extractMessages(sharedMessages);
20
+ const theme = createMuiTheme();
21
+
22
+ describe("toJsonCargo function", () => {
23
+ it("should throw if called with an unknown data type", () => {
24
+ const attribute = {
25
+ dataType: "aDataType",
26
+ };
27
+
28
+ expect(
29
+ () => expect(toJsonCargo, "when called with", [attribute, {}]),
30
+ "to throw",
31
+ "toJsonCargo: attribute.dataType aDataType is not implemented",
32
+ );
33
+ });
34
+
35
+ it("should throw if called with an unknown custom data type", () => {
36
+ const attribute = {
37
+ dataType: attributeDataType.customType,
38
+ customDataType: "aCustomDataType",
39
+ };
40
+
41
+ expect(
42
+ () => expect(toJsonCargo, "when called with", [attribute, {}]),
43
+ "to throw",
44
+ "toJsonCargo: attribute.customDataType aCustomDataType is not implemented",
45
+ );
46
+ });
47
+
48
+ it.each([
49
+ ["aTextValue", attributeDataType.text, null, "aTextValue"],
50
+ ["aPassword", attributeDataType.customType, customDataType.password, "aPassword"],
51
+ [
52
+ "aCarrierProviderSelector",
53
+ attributeDataType.customType,
54
+ customDataType.carrierProviderSelector,
55
+ "aCarrierProviderSelector",
56
+ ],
57
+ [
58
+ "aRoutingProviderSelector",
59
+ attributeDataType.customType,
60
+ customDataType.routingProviderSelector,
61
+ "aRoutingProviderSelector",
62
+ ],
63
+ [
64
+ "aMultipleCarrierProvidersSelector",
65
+ attributeDataType.customType,
66
+ customDataType.multipleCarrierProvidersSelector,
67
+ "aMultipleCarrierProvidersSelector",
68
+ ],
69
+ [true, attributeDataType.boolean, null, { __type: "ValueOfBoolean", value: true }],
70
+ [false, attributeDataType.boolean, null, { __type: "ValueOfBoolean", value: false }],
71
+ [5, attributeDataType.integer, null, { __type: "ValueOfInt32", value: 5 }],
72
+ [
73
+ "2021-04-26T04:00:00.0000000Z",
74
+ attributeDataType.dateTime,
75
+ null,
76
+ { __type: "ValueOfDateTime", value: "2021-04-26T04:00:00.0000000Z" },
77
+ ],
78
+ [15.4321, attributeDataType.decimal, null, { __type: "ValueOfDouble", value: 15.4321 }],
79
+ [15.4321, attributeDataType.customType, customDataType.money, { __type: "ValueOfDouble", value: 15.43 }],
80
+ [15.4285, attributeDataType.customType, customDataType.money, { __type: "ValueOfDouble", value: 15.43 }],
81
+ [
82
+ ["d22679f2-5807-4068-b17f-700742d97503"],
83
+ attributeDataType.entityReference,
84
+ null,
85
+ { __type: "ValueOfGuid[]", value: ["d22679f2-5807-4068-b17f-700742d97503"] },
86
+ ],
87
+ [
88
+ [
89
+ { min: "1.11", max: "2.22", rate: "1" },
90
+ { min: "2.22", rate: "2" },
91
+ ],
92
+ attributeDataType.customType,
93
+ customDataType.priceTieredRateTable,
94
+ {
95
+ __type: "Orckestra.Overture.Entities.Orders.TieredRateTable, Orckestra.Overture.Entities",
96
+ tiers: [
97
+ { min: "1.11", max: "2.22", rate: "1" },
98
+ { min: "2.22", rate: "2" },
99
+ ],
100
+ },
101
+ ],
102
+ [
103
+ [
104
+ { min: "1", max: "2", rate: "1" },
105
+ { min: "2", rate: "2" },
106
+ ],
107
+ attributeDataType.customType,
108
+ customDataType.quantityTieredRateTable,
109
+ {
110
+ __type: "Orckestra.Overture.Entities.Orders.TieredRateTable, Orckestra.Overture.Entities",
111
+ tiers: [
112
+ { min: "1", max: "2", rate: "1" },
113
+ { min: "2", rate: "2" },
114
+ ],
115
+ },
116
+ ],
117
+ [
118
+ [{ min: null, max: "2", rate: "1" }, null, { min: "2", rate: "2" }],
119
+ attributeDataType.customType,
120
+ customDataType.quantityTieredRateTable,
121
+ {
122
+ __type: "Orckestra.Overture.Entities.Orders.TieredRateTable, Orckestra.Overture.Entities",
123
+ tiers: [{ min: "2", rate: "2" }],
124
+ },
125
+ ],
126
+ ])("should return the proper json cargo with %s of type %s", (value, dataType, customType, expectedCargo) => {
127
+ const attribute = {
128
+ dataType: dataType,
129
+ customDataType: customType,
130
+ };
131
+
132
+ expect(toJsonCargo(attribute, value), "to equal", expectedCargo);
133
+ });
134
+ });
135
+
136
+ describe("formatNumber function", () => {
137
+ it.each([
138
+ ["16", 15.551, 0],
139
+ ["15.6", "15.551", 1],
140
+ ["15.55", "15.551", 2],
141
+ ["-16", -15.551, 0],
142
+ ["-15.6", "-15.551", 1],
143
+ ["-15.55", "-15.551", 2],
144
+ ["8.0", "8", 1],
145
+ ["4.00", 4, 2],
146
+ ["4.40", 4.4, 2],
147
+ ["-8.0", "-8", 1],
148
+ ["-4.00", -4, 2],
149
+ ["-4.40", -4.4, 2],
150
+ ])("should return %s with value %s and precision %s", (expected, value, precision) => {
151
+ expect(formatNumber(value, precision), "to equal", expected);
152
+ });
153
+ });
154
+
155
+ describe("fixPropertyBagModifiedModel", () => {
156
+ it.each([
157
+ [{ propertyBag: { name: "Name" } }, { propertyBag: { name: "Name" } }],
158
+ [{ propertyBag: { name: true } }, { propertyBag: { name: true } }],
159
+ [{ propertyBag: { name: false } }, { propertyBag: { name: false } }],
160
+ [{ propertyBag: { name: "" } }, { propertyBag: { name: null } }],
161
+ [{ propertyBag: { name: { value: "name" } } }, { propertyBag: { name: { value: "name" } } }],
162
+ [{ propertyBag: { name: { value: false } } }, { propertyBag: { name: { value: false } } }],
163
+ [{ propertyBag: { name: { value: "" } } }, { propertyBag: { name: null } }],
164
+ [{ profileOperations: {} }, { profileOperations: {} }],
165
+ [
166
+ { profileOperations: { profilesToAdd: { obj: { propertyBag: { name: "" } } }, profilesToUpdate: {} } },
167
+ { profileOperations: { profilesToAdd: { obj: { propertyBag: { name: null } } }, profilesToUpdate: {} } },
168
+ ],
169
+ [
170
+ { profileOperations: { profilesToAdd: [{ propertyBag: { name: "" } }], profilesToUpdate: {} } },
171
+ { profileOperations: { profilesToAdd: [{ propertyBag: { name: null } }], profilesToUpdate: {} } },
172
+ ],
173
+ [
174
+ { profileOperations: { profilesToAdd: {}, profilesToUpdate: { obj: { propertyBag: { name: "" } } } } },
175
+ { profileOperations: { profilesToAdd: {}, profilesToUpdate: { obj: { propertyBag: { name: null } } } } },
176
+ ],
177
+ [
178
+ { profileOperations: { profilesToAdd: {}, profilesToUpdate: [{ propertyBag: { name: "" } }] } },
179
+ { profileOperations: { profilesToAdd: {}, profilesToUpdate: [{ propertyBag: { name: null } }] } },
180
+ ],
181
+ ])("For model %s should return %s", (model, expected) => {
182
+ fixPropertyBagModifiedModel(model);
183
+ expect(model, "to equal", expected);
184
+ });
185
+
186
+ it("should fix propertyBag for specified Array Field", () => {
187
+ const model = {
188
+ propertyBag: {
189
+ name: { value: "Name" },
190
+ age: { value: "" },
191
+ },
192
+ addresses: {
193
+ value: [
194
+ { id: "1", propertyBag: { name: "Name" } },
195
+ { id: "2", propertyBag: { name: "" } },
196
+ { id: "3", propertyBag: { name: { value: "" } } },
197
+ { id: "4", propertyBag: { name: { value: "value" } } },
198
+ ],
199
+ },
200
+ };
201
+
202
+ const expected = {
203
+ propertyBag: {
204
+ name: { value: "Name" },
205
+ age: null,
206
+ },
207
+ addresses: {
208
+ value: [
209
+ { id: "1", propertyBag: { name: "Name" } },
210
+ { id: "2", propertyBag: { name: null } },
211
+ { id: "3", propertyBag: { name: null } },
212
+ { id: "4", propertyBag: { name: { value: "value" } } },
213
+ ],
214
+ },
215
+ };
216
+ fixPropertyBagModifiedModel(model, "addresses");
217
+ expect(model, "to equal", expected);
218
+ });
219
+
220
+ it("should fix propertyBag for specified object Field", () => {
221
+ const model = {
222
+ propertyBag: {
223
+ name: { value: "Name" },
224
+ age: { value: "" },
225
+ },
226
+ addresses: {
227
+ value: { id: "1", propertyBag: { name: "" } },
228
+ },
229
+ };
230
+
231
+ const expected = {
232
+ propertyBag: {
233
+ name: { value: "Name" },
234
+ age: null,
235
+ },
236
+ addresses: {
237
+ value: { id: "1", propertyBag: { name: null } },
238
+ },
239
+ };
240
+ fixPropertyBagModifiedModel(model, "addresses");
241
+ expect(model, "to equal", expected);
242
+ });
243
+
244
+ it("should fix propertyBag for unknown Array Field", () => {
245
+ const model = {
246
+ propertyBag: {
247
+ name: { value: "Name" },
248
+ age: { value: "" },
249
+ },
250
+ addresses: {
251
+ value: [
252
+ { id: "1", propertyBag: { name: "Name" } },
253
+ { id: "2", propertyBag: { name: "" } },
254
+ { id: "3", propertyBag: { name: { value: "" } } },
255
+ { id: "4", propertyBag: { name: { value: "value" } } },
256
+ ],
257
+ },
258
+ };
259
+
260
+ const expected = {
261
+ propertyBag: {
262
+ name: { value: "Name" },
263
+ age: null,
264
+ },
265
+ addresses: {
266
+ value: [
267
+ { id: "1", propertyBag: { name: "Name" } },
268
+ { id: "2", propertyBag: { name: "" } },
269
+ { id: "3", propertyBag: { name: { value: "" } } },
270
+ { id: "4", propertyBag: { name: { value: "value" } } },
271
+ ],
272
+ },
273
+ };
274
+ fixPropertyBagModifiedModel(model, "unknown");
275
+ expect(model, "to equal", expected);
276
+ });
277
+
278
+ it("should fix propertyBag for Array Field with null values", () => {
279
+ const model = {
280
+ propertyBag: {
281
+ name: { value: "Name" },
282
+ age: { value: "" },
283
+ },
284
+ addresses: {
285
+ value: null,
286
+ },
287
+ };
288
+
289
+ const expected = {
290
+ propertyBag: {
291
+ name: { value: "Name" },
292
+ age: null,
293
+ },
294
+ addresses: {
295
+ value: null,
296
+ },
297
+ };
298
+ fixPropertyBagModifiedModel(model, "addresses");
299
+ expect(model, "to equal", expected);
300
+ });
301
+
302
+ it("should not fail when result doesn't have propertyBag", () => {
303
+ let model = {};
304
+ fixPropertyBagModifiedModel(model);
305
+ expect(model, "to equal", {});
306
+ });
307
+ });
308
+
309
+ describe("setRequiredBooleansDefault", () => {
310
+ it("should set defaults values for required booleans only", () => {
311
+ const attributes = [
312
+ {
313
+ name: "anAttributeName1",
314
+ dataType: attributeDataType.boolean,
315
+ isRequired: true,
316
+ },
317
+ {
318
+ name: "anAttributeName2",
319
+ dataType: attributeDataType.boolean,
320
+ },
321
+ {
322
+ name: "anAttributeName3",
323
+ dataType: attributeDataType.integer,
324
+ isRequired: true,
325
+ },
326
+ ];
327
+
328
+ const propertyBag = {};
329
+
330
+ setRequiredBooleansDefault(attributes, propertyBag);
331
+
332
+ expect(Object.keys(propertyBag).length, "to equal", 1);
333
+ expect(propertyBag["anAttributeName1"], "to equal", { __type: "ValueOfBoolean", value: false });
334
+ });
335
+
336
+ it("should do nothing for known booleans", () => {
337
+ const attributes = [
338
+ {
339
+ name: "anAttributeName1",
340
+ dataType: attributeDataType.boolean,
341
+ isRequired: true,
342
+ },
343
+ {
344
+ name: "anAttributeName2",
345
+ dataType: attributeDataType.boolean,
346
+ },
347
+ {
348
+ name: "anAttributeName3",
349
+ dataType: attributeDataType.integer,
350
+ isRequired: true,
351
+ },
352
+ ];
353
+
354
+ const propertyBag = {
355
+ anAttributeName1: { __type: "ValueOfBoolean", value: true },
356
+ };
357
+
358
+ setRequiredBooleansDefault(attributes, propertyBag);
359
+
360
+ expect(Object.keys(propertyBag).length, "to equal", 1);
361
+ expect(propertyBag["anAttributeName1"], "to equal", { __type: "ValueOfBoolean", value: true });
362
+ });
363
+ });
364
+
365
+ const propertyBagValuesWithStandardValues = {
366
+ GuidValue: {
367
+ __type: "ValueOfGuid",
368
+ value: "414641705edb4f7f905ffeb06aacb8f2",
369
+ },
370
+ BooleanValue: {
371
+ __type: "ValueOfBoolean",
372
+ value: true,
373
+ },
374
+ BooleanValueFalse: {
375
+ __type: "ValueOfBoolean",
376
+ value: false,
377
+ },
378
+ ByteValue: {
379
+ __type: "ValueOfByte",
380
+ value: 4,
381
+ },
382
+ SByteValue: {
383
+ __type: "ValueOfSByte",
384
+ value: 85,
385
+ },
386
+ Int16Value: {
387
+ __type: "ValueOfInt16",
388
+ value: -16,
389
+ },
390
+ UInt16Value: {
391
+ __type: "ValueOfUInt16",
392
+ value: 16,
393
+ },
394
+ Int32Value: {
395
+ __type: "ValueOfInt32",
396
+ value: -32,
397
+ },
398
+ UInt32Value: {
399
+ __type: "ValueOfUInt32",
400
+ value: 32,
401
+ },
402
+ Int64Value: {
403
+ __type: "ValueOfInt64",
404
+ value: -64,
405
+ },
406
+ UInt64Value: {
407
+ __type: "ValueOfUInt64",
408
+ value: 64,
409
+ },
410
+ SingleValue: {
411
+ __type: "ValueOfSingle",
412
+ value: 12.344,
413
+ },
414
+ DoubleValue: {
415
+ __type: "ValueOfDouble",
416
+ value: 34.567,
417
+ },
418
+ DecimalValue: {
419
+ __type: "ValueOfDecimal",
420
+ value: 56.7,
421
+ },
422
+ DateTimeValue: {
423
+ __type: "ValueOfDateTime",
424
+ value: "2021-05-19T19:37:50.1805767Z",
425
+ },
426
+ CharValue: {
427
+ __type: "ValueOfChar",
428
+ value: "c",
429
+ },
430
+ StringValueOtherFormat: {
431
+ __type: "ValueOfString",
432
+ value: "str value other value",
433
+ },
434
+ NullStringValue: {
435
+ __type: "ValueOfString",
436
+ value: null,
437
+ },
438
+ UndefinedStringValue: {
439
+ __type: "ValueOfString",
440
+ value: undefined,
441
+ },
442
+ StringValue: "str value",
443
+ };
444
+
445
+ const propertyBagValuesWithValueContainer = {
446
+ GuidValue: {
447
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.Guid, mscorlib]], Orckestra.Overture.Entities",
448
+ value: "414641705edb4f7f905ffeb06aacb8f2",
449
+ },
450
+ BooleanValue: {
451
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.Boolean, mscorlib]], Orckestra.Overture.Entities",
452
+ value: true,
453
+ },
454
+ BooleanValueFalse: {
455
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.Boolean, mscorlib]], Orckestra.Overture.Entities",
456
+ value: false,
457
+ },
458
+ ByteValue: {
459
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.Byte, mscorlib]], Orckestra.Overture.Entities",
460
+ value: 4,
461
+ },
462
+ SByteValue: {
463
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.SByte, mscorlib]], Orckestra.Overture.Entities",
464
+ value: 85,
465
+ },
466
+ Int16Value: {
467
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.Int16, mscorlib]], Orckestra.Overture.Entities",
468
+ value: -16,
469
+ },
470
+ UInt16Value: {
471
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.UInt16, mscorlib]], Orckestra.Overture.Entities",
472
+ value: 16,
473
+ },
474
+ Int32Value: {
475
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.Int32, mscorlib]], Orckestra.Overture.Entities",
476
+ value: -32,
477
+ },
478
+ UInt32Value: {
479
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.UInt32, mscorlib]], Orckestra.Overture.Entities",
480
+ value: 32,
481
+ },
482
+ Int64Value: {
483
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.Int64, mscorlib]], Orckestra.Overture.Entities",
484
+ value: -64,
485
+ },
486
+ UInt64Value: {
487
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.UInt64, mscorlib]], Orckestra.Overture.Entities",
488
+ value: 64,
489
+ },
490
+ SingleValue: {
491
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.Single, mscorlib]], Orckestra.Overture.Entities",
492
+ value: 12.344,
493
+ },
494
+ DoubleValue: {
495
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.Double, mscorlib]], Orckestra.Overture.Entities",
496
+ value: 34.567,
497
+ },
498
+ DecimalValue: {
499
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.Decimal, mscorlib]], Orckestra.Overture.Entities",
500
+ value: 56.7,
501
+ },
502
+ DateTimeValue: {
503
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.DateTime, mscorlib]], Orckestra.Overture.Entities",
504
+ value: "2021-05-19T19:37:50.1805767Z",
505
+ },
506
+ CharValue: {
507
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.Char, mscorlib]], Orckestra.Overture.Entities",
508
+ value: "c",
509
+ },
510
+ StringValueOtherFormat: {
511
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.String, mscorlib]], Orckestra.Overture.Entities",
512
+ value: "str value other value",
513
+ },
514
+ NullStringValue: {
515
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.String, mscorlib]], Orckestra.Overture.Entities",
516
+ value: null,
517
+ },
518
+ UndefinedStringValue: {
519
+ __type: "Orckestra.Overture.Entities.ValueContainer`1[[System.String, mscorlib]], Orckestra.Overture.Entities",
520
+ value: undefined,
521
+ },
522
+ StringValue: "str value",
523
+ };
524
+
525
+ describe.each([
526
+ ["with standard values", propertyBagValuesWithStandardValues],
527
+ ["with ValueContainer", propertyBagValuesWithValueContainer],
528
+ ])("getPropertyBagFormattedPrimitiveValue %s", (title, propertyBagValues) => {
529
+ let state, store;
530
+ beforeEach(() => {
531
+ state = Immutable.fromJS({
532
+ locale: {
533
+ locale: "en-US",
534
+ },
535
+ });
536
+
537
+ store = {
538
+ getState: () => state,
539
+ subscribe: () => {},
540
+ dispatch: () => {},
541
+ };
542
+ });
543
+
544
+ it.each([
545
+ ["GuidValue", "41464170-5edb-4f7f-905f-feb06aacb8f2"],
546
+ ["BooleanValue", "True"],
547
+ ["BooleanValueFalse", "False"],
548
+ ["NullStringValue", null],
549
+ ["UndefinedStringValue", null],
550
+ ["ByteValue", "4"],
551
+ ["SByteValue", "85"],
552
+ ["Int16Value", "-16"],
553
+ ["UInt16Value", "16"],
554
+ ["Int32Value", "-32"],
555
+ ["UInt32Value", "32"],
556
+ ["Int64Value", "-64"],
557
+ ["UInt64Value", "64"],
558
+ ["SingleValue", "12.34"],
559
+ ["DoubleValue", "34.57"],
560
+ ["DecimalValue", "56.70"],
561
+ ["DateTimeValue", "5/19/2021 7:37 PM"],
562
+ ["CharValue", "c"],
563
+ ["StringValueOtherFormat", "str value other value"],
564
+ ["StringValue", "str value"],
565
+ ])("Formatting %s", (dataType, expectedFormattedValue) => {
566
+ let pbFormatter;
567
+
568
+ const TestComp = () => {
569
+ const { formatMessage, formatDate, formatTime } = useIntl();
570
+ pbFormatter = value => {
571
+ return getPropertyBagFormattedPrimitiveValue(value, formatMessage, formatDate, formatTime);
572
+ };
573
+ return null;
574
+ };
575
+
576
+ mount(
577
+ <TestWrapper provider={{ store }} intlProvider={{ messages }} stylesProvider muiThemeProvider={{ theme }}>
578
+ <TestComp />
579
+ </TestWrapper>,
580
+ );
581
+
582
+ const formattedValue = pbFormatter(propertyBagValues[dataType]);
583
+
584
+ expect(formattedValue, "to equal", expectedFormattedValue);
585
+ });
586
+
587
+ it.each([
588
+ ["ByteValue", "4.6", "5"],
589
+ ["SByteValue", "85.3", "85"],
590
+ ["Int16Value", "-16.3", "-16"],
591
+ ["UInt16Value", "16.3", "16"],
592
+ ["Int32Value", "-32.3", "-32"],
593
+ ["UInt32Value", "32.3", "32"],
594
+ ["Int64Value", "-64.3", "-64"],
595
+ ["UInt64Value", "64.3", "64"],
596
+ ])("Whole number should not have decimal data type %s %s", (dataType, value, expectedValue) => {
597
+ let pbFormatter;
598
+
599
+ const TestComp = () => {
600
+ const { formatMessage, formatDate, formatTime } = useIntl();
601
+ pbFormatter = value => {
602
+ return getPropertyBagFormattedPrimitiveValue(value, formatMessage, formatDate, formatTime);
603
+ };
604
+ return null;
605
+ };
606
+
607
+ mount(
608
+ <TestWrapper provider={{ store }} intlProvider={{ messages }} stylesProvider muiThemeProvider={{ theme }}>
609
+ <TestComp />
610
+ </TestWrapper>,
611
+ );
612
+
613
+ const pbValue = _.cloneDeep(propertyBagValues[dataType]);
614
+ pbValue.value = value;
615
+
616
+ const formattedValue = pbFormatter(pbValue);
617
+
618
+ expect(formattedValue, "to equal", expectedValue);
619
+ });
620
+
621
+ it.each([[null], [undefined], [0], [123], [""], [false], ["Some text"]])(
622
+ "Non object value %s is not formatted",
623
+ stringToFormat => {
624
+ let pbFormatter;
625
+
626
+ const TestComp = () => {
627
+ const { formatMessage, formatDate, formatTime } = useIntl();
628
+ pbFormatter = value => {
629
+ return getPropertyBagFormattedPrimitiveValue(value, formatMessage, formatDate, formatTime);
630
+ };
631
+ return null;
632
+ };
633
+
634
+ mount(
635
+ <TestWrapper provider={{ store }} intlProvider={{ messages }} stylesProvider muiThemeProvider={{ theme }}>
636
+ <TestComp />
637
+ </TestWrapper>,
638
+ );
639
+
640
+ const formattedValue = pbFormatter(stringToFormat);
641
+
642
+ expect(formattedValue, "to be", stringToFormat);
643
+ },
644
+ );
645
+
646
+ it("Null JsCargo value is not formatted", () => {
647
+ let pbFormatter;
648
+
649
+ const TestComp = () => {
650
+ const { formatMessage, formatDate, formatTime } = useIntl();
651
+ pbFormatter = value => {
652
+ return getPropertyBagFormattedPrimitiveValue(value, formatMessage, formatDate, formatTime);
653
+ };
654
+ return null;
655
+ };
656
+
657
+ mount(
658
+ <TestWrapper provider={{ store }} intlProvider={{ messages }} stylesProvider muiThemeProvider={{ theme }}>
659
+ <TestComp />
660
+ </TestWrapper>,
661
+ );
662
+
663
+ const formattedValue = pbFormatter({
664
+ __type: "ValueOfUInt16",
665
+ value: null,
666
+ });
667
+
668
+ expect(formattedValue, "to be", null);
669
+ });
670
+
671
+ it("Unknown datatype returns null", () => {
672
+ let pbFormatter;
673
+
674
+ const TestComp = () => {
675
+ const { formatMessage, formatDate, formatTime } = useIntl();
676
+ pbFormatter = value => {
677
+ return getPropertyBagFormattedPrimitiveValue(value, formatMessage, formatDate, formatTime);
678
+ };
679
+ return null;
680
+ };
681
+
682
+ mount(
683
+ <TestWrapper provider={{ store }} intlProvider={{ messages }} stylesProvider muiThemeProvider={{ theme }}>
684
+ <TestComp />
685
+ </TestWrapper>,
686
+ );
687
+
688
+ const formattedValue = pbFormatter({
689
+ __type: "ValueOfTheUnknown",
690
+ value: "SomeValue",
691
+ });
692
+
693
+ expect(formattedValue, "to be", null);
694
+ });
695
+ });
696
+
697
+ describe("isTieredAttribute", () => {
698
+ it("should return true if priceTieredRateTable", () => {
699
+ expect(isTieredAttribute({ customDataType: customDataType.priceTieredRateTable }), "to equal", true);
700
+ });
701
+
702
+ it("should return true if quantityTieredRateTable", () => {
703
+ expect(isTieredAttribute({ customDataType: customDataType.quantityTieredRateTable }), "to equal", true);
704
+ });
705
+
706
+ it("should return false if unknown value", () => {
707
+ expect(isTieredAttribute("unknown type"), "to equal", false);
708
+ });
709
+ });