@vitality-ds/components 4.4.3 → 4.5.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 (58) hide show
  1. package/dist/AuditTrail/components/AuditItem/index.js +4 -5
  2. package/dist/AuditTrail/components/AuditItem/index.spec.js +407 -0
  3. package/dist/AuditTrail/hooks/useAuditTrail.js +15 -2
  4. package/dist/AuditTrail/hooks/useAuditTrail.spec.js +141 -0
  5. package/dist/AuditTrail/index.spec.js +59 -37
  6. package/dist/AuditTrail/logic.js +12 -6
  7. package/dist/AuditTrail/logic.spec.js +125 -70
  8. package/dist/Input/RadioButtons/index.js +1 -1
  9. package/dist/components/src/AuditTrail/components/AuditItem/index.d.ts.map +1 -1
  10. package/dist/components/src/AuditTrail/components/AuditItem/index.js +3 -6
  11. package/dist/components/src/AuditTrail/components/AuditItem/index.js.map +1 -1
  12. package/dist/components/src/AuditTrail/components/AuditItem/index.spec.d.ts +2 -0
  13. package/dist/components/src/AuditTrail/components/AuditItem/index.spec.d.ts.map +1 -0
  14. package/dist/components/src/AuditTrail/components/AuditItem/index.spec.js +318 -0
  15. package/dist/components/src/AuditTrail/components/AuditItem/index.spec.js.map +1 -0
  16. package/dist/components/src/AuditTrail/components/IconAvatar/types.d.ts +1 -1
  17. package/dist/components/src/AuditTrail/components/IconAvatar/types.d.ts.map +1 -1
  18. package/dist/components/src/AuditTrail/hooks/useAuditTrail.d.ts +2 -2
  19. package/dist/components/src/AuditTrail/hooks/useAuditTrail.d.ts.map +1 -1
  20. package/dist/components/src/AuditTrail/hooks/useAuditTrail.js +31 -2
  21. package/dist/components/src/AuditTrail/hooks/useAuditTrail.js.map +1 -1
  22. package/dist/components/src/AuditTrail/hooks/useAuditTrail.spec.d.ts +2 -0
  23. package/dist/components/src/AuditTrail/hooks/useAuditTrail.spec.d.ts.map +1 -0
  24. package/dist/components/src/AuditTrail/hooks/useAuditTrail.spec.js +124 -0
  25. package/dist/components/src/AuditTrail/hooks/useAuditTrail.spec.js.map +1 -0
  26. package/dist/components/src/AuditTrail/index.spec.js +60 -29
  27. package/dist/components/src/AuditTrail/index.spec.js.map +1 -1
  28. package/dist/components/src/AuditTrail/logic.d.ts.map +1 -1
  29. package/dist/components/src/AuditTrail/logic.js +13 -9
  30. package/dist/components/src/AuditTrail/logic.js.map +1 -1
  31. package/dist/components/src/AuditTrail/logic.spec.js +109 -70
  32. package/dist/components/src/AuditTrail/logic.spec.js.map +1 -1
  33. package/dist/components/src/AuditTrail/types.d.ts +4 -3
  34. package/dist/components/src/AuditTrail/types.d.ts.map +1 -1
  35. package/dist/components/src/Input/RadioButtons/index.js +1 -1
  36. package/dist/components/src/Input/RadioButtons/index.js.map +1 -1
  37. package/dist/components/src/helpers/test/findSVGs.d.ts +9 -0
  38. package/dist/components/src/helpers/test/findSVGs.d.ts.map +1 -0
  39. package/dist/components/src/helpers/test/findSVGs.js +17 -0
  40. package/dist/components/src/helpers/test/findSVGs.js.map +1 -0
  41. package/dist/components/src/helpers/test/index.d.ts +2 -0
  42. package/dist/components/src/helpers/test/index.d.ts.map +1 -0
  43. package/dist/components/src/helpers/test/index.js +10 -0
  44. package/dist/components/src/helpers/test/index.js.map +1 -0
  45. package/dist/esm/AuditTrail/components/AuditItem/index.js +4 -5
  46. package/dist/esm/AuditTrail/components/AuditItem/index.spec.js +404 -0
  47. package/dist/esm/AuditTrail/hooks/useAuditTrail.js +12 -2
  48. package/dist/esm/AuditTrail/hooks/useAuditTrail.spec.js +138 -0
  49. package/dist/esm/AuditTrail/index.spec.js +60 -38
  50. package/dist/esm/AuditTrail/logic.js +12 -6
  51. package/dist/esm/AuditTrail/logic.spec.js +125 -70
  52. package/dist/esm/Input/RadioButtons/index.js +1 -1
  53. package/dist/esm/helpers/test/findSVGs.js +14 -0
  54. package/dist/esm/helpers/test/index.js +2 -0
  55. package/dist/helpers/test/findSVGs.js +20 -0
  56. package/dist/helpers/test/index.js +13 -0
  57. package/dist/tsconfig.tsbuildinfo +1 -1
  58. package/package.json +5 -5
@@ -10,7 +10,9 @@ export var getTimes = function getTimes(timestamp) {
10
10
  };
11
11
  }
12
12
  var dateTime = DateTime.fromISO(timestamp.replace(" ", "T"));
13
- var date = dateTime.toLocaleString();
13
+ // need to express date in dd/MM/yyyy format explicitly instead of relying on locale because windows 11 prevents luxon from reading language settings -> this becomes problematic because luxons default is US
14
+ var date = dateTime.toFormat("dd/MM/yyyy");
15
+ // needs to be 'en-US' format to show in AM/PM 12 hour time where 'en-GB' likes 24-hour time.
14
16
  var time = dateTime.toFormat("tt", {
15
17
  locale: "en-US"
16
18
  });
@@ -23,12 +25,16 @@ export var getTimes = function getTimes(timestamp) {
23
25
  };
24
26
  };
25
27
  export var getBrand = function getBrand(name) {
26
- var _name$split$filter$;
27
- var brand = name && ((_name$split$filter$ = name.split(" ").filter(function (word) {
28
- return APPLICATION_ICON_TRIGGERS.includes(word.toLowerCase());
29
- })[0]) === null || _name$split$filter$ === void 0 ? void 0 : _name$split$filter$.toLowerCase());
28
+ if (!name) return undefined;
29
+ var normalised = name.toLowerCase();
30
+ var brand = APPLICATION_ICON_TRIGGERS.find(function (trigger) {
31
+ return normalised.includes(trigger);
32
+ });
30
33
  return BRAND_ICONS[brand];
31
34
  };
35
+ var removeNonLettersFromInitials = function removeNonLettersFromInitials(initials) {
36
+ return initials.replace(/[^a-zA-Z]+/g, "");
37
+ };
32
38
  export var getInitials = function getInitials(name, forcedInitials) {
33
39
  if (forcedInitials) {
34
40
  return forcedInitials;
@@ -44,5 +50,5 @@ export var getInitials = function getInitials(name, forcedInitials) {
44
50
  if (initials.length > 2) {
45
51
  return null;
46
52
  }
47
- return initials;
53
+ return removeNonLettersFromInitials(initials);
48
54
  };
@@ -1,77 +1,132 @@
1
+ import { BRAND_ICONS } from "./constants";
1
2
  import { getBrand, getInitials, getTimes } from "./logic";
2
- describe("getTimes function", function () {
3
- test("should return null values when timestamp is empty", function () {
4
- var result = getTimes("");
5
- expect(result).toEqual({
6
- date: null,
7
- time: null,
8
- humanTime: null,
9
- invalidTime: null
3
+ describe("auditTrail logic", function () {
4
+ describe("getTimes function", function () {
5
+ test("should return null values when timestamp is empty", function () {
6
+ var result = getTimes("");
7
+ expect(result).toEqual({
8
+ date: null,
9
+ time: null,
10
+ humanTime: null,
11
+ invalidTime: null
12
+ });
13
+ });
14
+ test("should return formatted date, time, and human time for a valid timestamp", function () {
15
+ var timestamp = "2024-03-22T15:30:00Z";
16
+ var result = getTimes(timestamp);
17
+ expect(result.date).toBeDefined();
18
+ expect(result.time).toBeDefined();
19
+ expect(result.humanTime).toBeDefined();
20
+ expect(result.invalidTime).toBeDefined();
21
+ expect(result.invalidTime).toBe(false);
22
+ });
23
+ test("should return null for date, time, and human time and true for invalid when timestamp is invalid", function () {
24
+ var timestamp = "invalid_timestamp";
25
+ var result = getTimes(timestamp);
26
+ expect(result.date).toBe("Invalid DateTime");
27
+ expect(result.time).toBe("Invalid DateTime");
28
+ expect(result.humanTime).toBeNull();
29
+ expect(result.invalidTime).toBeTruthy();
10
30
  });
11
31
  });
12
- test("should return formatted date, time, and human time for a valid timestamp", function () {
13
- var timestamp = "2024-03-22T15:30:00Z";
14
- var result = getTimes(timestamp);
15
- expect(result.date).toBeDefined();
16
- expect(result.time).toBeDefined();
17
- expect(result.humanTime).toBeDefined();
18
- expect(result.invalidTime).toBeDefined();
19
- expect(result.invalidTime).toBe(false);
20
- });
21
- test("should return null for date, time, and human time and true for invalid when timestamp is invalid", function () {
22
- var timestamp = "invalid_timestamp";
23
- var result = getTimes(timestamp);
24
- expect(result.date).toBe("Invalid DateTime");
25
- expect(result.time).toBe("Invalid DateTime");
26
- expect(result.humanTime).toBeNull();
27
- expect(result.invalidTime).toBeTruthy();
28
- });
29
- });
30
- describe("getBrand function", function () {
31
- test("should return null when name is empty", function () {
32
- var result = getBrand("");
33
- expect(result).toBeUndefined();
34
- });
35
- test("should return the corresponding brand icon when name matches a known brand", function () {
36
- var name = "Gentu (automated)";
37
- var result = getBrand(name);
38
- expect(result).toBeDefined();
39
- });
40
- test("should return null when name does not match any known brand", function () {
41
- var name = "HealthLink ()";
42
- var result = getBrand(name);
43
- expect(result).toBeUndefined();
44
- });
45
- });
46
- describe("getInitials function", function () {
47
- test("should return null when name is empty and forcedInitials is not provided", function () {
48
- var result = getInitials("", "");
49
- expect(result).toBeNull();
50
- });
51
- test("should return forcedInitials when provided and not empty", function () {
52
- var name = "John Doe";
53
- var forcedInitials = "JD";
54
- var result = getInitials(name, forcedInitials);
55
- expect(result).toBe(forcedInitials);
56
- });
57
- test("should return Correct Initials when name contains titles to ignore and forcedInitials is not provided", function () {
58
- var name = "Dr. Jane Doe";
59
- var result = getInitials(name, "");
60
- expect(result).toBe("JD");
61
- });
62
- test("should return Correct Initials when name contains titles to ignore and forcedInitials is not provided and the name exceeds 2 characters", function () {
63
- var name = "Dr. Jane Doe and Mr. John Smith";
64
- var result = getInitials(name, "");
65
- expect(result).toBeNull();
32
+ describe("getBrand function", function () {
33
+ describe("when name is empty", function () {
34
+ var result = getBrand("");
35
+ it("should return undefined", function () {
36
+ expect(result).toBeUndefined();
37
+ });
38
+ });
39
+ describe("when the name is an exact match", function () {
40
+ var name = "gentu";
41
+ var result = getBrand(name);
42
+ it("should return the Gentu icon", function () {
43
+ expect(result).toBe(BRAND_ICONS.gentu);
44
+ });
45
+ });
46
+ describe("when the name is a partial or embedded match", function () {
47
+ var name = "gentu-support";
48
+ var result = getBrand(name);
49
+ it("should return the Gentu icon", function () {
50
+ expect(result).toBe(BRAND_ICONS.gentu);
51
+ });
52
+ });
53
+ describe("when the name is a case-insensitive match", function () {
54
+ var name = "GENTU";
55
+ var result = getBrand(name);
56
+ it("should return the Gentu icon", function () {
57
+ expect(result).toBe(BRAND_ICONS.gentu);
58
+ });
59
+ });
60
+ describe("when the name does not contain the word 'gentu'", function () {
61
+ var name = "HealthLink ()";
62
+ var result = getBrand(name);
63
+ it("should return undefined", function () {
64
+ expect(result).toBeUndefined();
65
+ });
66
+ });
66
67
  });
67
- test("should return initials when name is valid and forcedInitials is not provided", function () {
68
- var name = "John Doe";
69
- var result = getInitials(name, "");
70
- expect(result).toBe("JD");
68
+ describe("getInitials function", function () {
69
+ test("should return null when name is empty and forcedInitials is not provided", function () {
70
+ var result = getInitials("", "");
71
+ expect(result).toBeNull();
72
+ });
73
+ test("should return forcedInitials when provided and not empty", function () {
74
+ var name = "John Doe";
75
+ var forcedInitials = "JD";
76
+ var result = getInitials(name, forcedInitials);
77
+ expect(result).toBe(forcedInitials);
78
+ });
79
+ test("should return Correct Initials when name contains titles to ignore and forcedInitials is not provided", function () {
80
+ var name = "Dr. Jane Doe";
81
+ var result = getInitials(name, "");
82
+ expect(result).toBe("JD");
83
+ });
84
+ test("should return Correct Initials when name contains titles to ignore and forcedInitials is not provided and the name exceeds 2 characters", function () {
85
+ var name = "Dr. Jane Doe and Mr. John Smith";
86
+ var result = getInitials(name, "");
87
+ expect(result).toBeNull();
88
+ });
89
+ test("should return initials when name is valid and forcedInitials is not provided", function () {
90
+ var name = "John Doe";
91
+ var result = getInitials(name, "");
92
+ expect(result).toBe("JD");
93
+ });
94
+ test("should return null when generated initials exceed two characters and forcedInitials is not provided", function () {
95
+ var name = "John Michael Doe";
96
+ var result = getInitials(name, "");
97
+ expect(result).toBeNull();
98
+ });
71
99
  });
72
- test("should return null when generated initials exceed two characters and forcedInitials is not provided", function () {
73
- var name = "John Michael Doe";
74
- var result = getInitials(name, "");
75
- expect(result).toBeNull();
100
+ describe("when checking for restricted non letter characters", function () {
101
+ it.each([{
102
+ name: "John Doe",
103
+ expectedInitials: "JD"
104
+ }, {
105
+ name: "John",
106
+ expectedInitials: "J"
107
+ }, {
108
+ name: "John (Anesthetist)",
109
+ expectedInitials: "J"
110
+ }, {
111
+ name: "John Stranger(Anesthetist)",
112
+ expectedInitials: "JS"
113
+ }, {
114
+ name: "John Smith-Brown",
115
+ expectedInitials: "JS"
116
+ }, {
117
+ name: "John O'Leary",
118
+ expectedInitials: "JO"
119
+ }, {
120
+ name: "",
121
+ expectedInitials: null
122
+ }, {
123
+ name: "John Stranger (Anesthetist)",
124
+ expectedInitials: null
125
+ }])("should return $expectedInitials when name is $name and forcedInitials is provided", function (_ref) {
126
+ var name = _ref.name,
127
+ expectedInitials = _ref.expectedInitials;
128
+ var result = getInitials(name, "");
129
+ expect(result).toBe(expectedInitials);
130
+ });
76
131
  });
77
132
  });
@@ -21,7 +21,7 @@ var RadioButtons = /*#__PURE__*/React.forwardRef(function (_ref, forwardedRef) {
21
21
  return /*#__PURE__*/React.createElement(BaseRadioButtonsContainer, _extends({
22
22
  onValueChange: onChange,
23
23
  orientation: direction,
24
- defaultValue: value,
24
+ value: value,
25
25
  name: name,
26
26
  ref: forwardedRef
27
27
  }, props), options === null || options === void 0 ? void 0 : options.map(function (_ref2) {
@@ -0,0 +1,14 @@
1
+ /**
2
+ * RTL doesn't let you search directly though a component because it only considers what is rendered. because of this we can either apply a test id 🤮
3
+ * @param container
4
+ * @param IconFunctionComponent
5
+ * @returns an array of all matching elements within that test container
6
+ */
7
+ var findSVGs = function findSVGs(container, IconFunctionComponent) {
8
+ var pathChildren = IconFunctionComponent({}).props.children;
9
+ if (Array.isArray(pathChildren)) {
10
+ return container.querySelectorAll("path[d=\"".concat(pathChildren[0].props.d, "\"]"));
11
+ }
12
+ return container.querySelectorAll("path[d=\"".concat(pathChildren.props.d, "\"]"));
13
+ };
14
+ export default findSVGs;
@@ -0,0 +1,2 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ export { default as findSVGs } from "./findSVGs";
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ /**
8
+ * RTL doesn't let you search directly though a component because it only considers what is rendered. because of this we can either apply a test id 🤮
9
+ * @param container
10
+ * @param IconFunctionComponent
11
+ * @returns an array of all matching elements within that test container
12
+ */
13
+ var findSVGs = function findSVGs(container, IconFunctionComponent) {
14
+ var pathChildren = IconFunctionComponent({}).props.children;
15
+ if (Array.isArray(pathChildren)) {
16
+ return container.querySelectorAll("path[d=\"".concat(pathChildren[0].props.d, "\"]"));
17
+ }
18
+ return container.querySelectorAll("path[d=\"".concat(pathChildren.props.d, "\"]"));
19
+ };
20
+ var _default = exports["default"] = findSVGs;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "findSVGs", {
8
+ enumerable: true,
9
+ get: function get() {
10
+ return _findSVGs["default"];
11
+ }
12
+ });
13
+ var _findSVGs = _interopRequireDefault(require("./findSVGs"));