@vitality-ds/components 4.4.4 → 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
@@ -0,0 +1,404 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import { render, screen } from "@testing-library/react";
3
+ import { Add, Contact, GentuLogo, Link } from "@vitality-ds/icons";
4
+ import React from "react";
5
+ import { findSVGs } from "../../../helpers/test";
6
+ import AuditItem from "./index";
7
+ describe("<AuditItem />", function () {
8
+ beforeEach(function () {
9
+ jest.useFakeTimers("modern");
10
+ jest.setSystemTime(new Date("2024-03-22T17:30:00"));
11
+ });
12
+ describe("when action is a preset", function () {
13
+ describe("and name is given", function () {
14
+ describe("and does not contain the word gentu", function () {
15
+ describe("and name is more than 3 words", function () {
16
+ var item = {
17
+ action: "create",
18
+ name: "Dr. Jane Doe and Mr. John Smith",
19
+ dateTime: "2024-03-22T15:30:00"
20
+ };
21
+ it("renders the fallback icon", function () {
22
+ var _render = render( /*#__PURE__*/React.createElement(AuditItem, {
23
+ item: item
24
+ })),
25
+ container = _render.container;
26
+ expect(findSVGs(container, Add)).toHaveLength(1);
27
+ });
28
+ it("renders the name and preposition", function () {
29
+ render( /*#__PURE__*/React.createElement(AuditItem, {
30
+ item: item
31
+ }));
32
+ expect(screen.getAllByText(/Created by/)).toHaveLength(1);
33
+ expect(screen.getAllByText(/Dr. Jane Doe and Mr. John Smith/)).toHaveLength(1);
34
+ });
35
+ });
36
+ describe("and name is 3 words", function () {
37
+ describe("the first word is one of the approved list of prefixes", function () {
38
+ var item = {
39
+ action: "create",
40
+ name: "Dr. Jane Doe"
41
+ };
42
+ it("renders the correct initials", function () {
43
+ render( /*#__PURE__*/React.createElement(AuditItem, {
44
+ item: item
45
+ }));
46
+ expect(screen.getAllByText(/JD/)).toHaveLength(1);
47
+ });
48
+ it("renders the name and preposition", function () {
49
+ render( /*#__PURE__*/React.createElement(AuditItem, {
50
+ item: item
51
+ }));
52
+ expect(screen.getAllByText(/Created by/)).toHaveLength(1);
53
+ expect(screen.getAllByText(/Dr. Jane Doe/)).toHaveLength(1);
54
+ });
55
+ });
56
+ describe("the first word is not an approved prefix", function () {
57
+ var item = {
58
+ action: "create",
59
+ name: "hello Jane Doe"
60
+ };
61
+ it("renders the fallback icon", function () {
62
+ var _render2 = render( /*#__PURE__*/React.createElement(AuditItem, {
63
+ item: item
64
+ })),
65
+ container = _render2.container;
66
+ expect(findSVGs(container, Add)).toHaveLength(1);
67
+ });
68
+ it("renders the name and preposition", function () {
69
+ render( /*#__PURE__*/React.createElement(AuditItem, {
70
+ item: item
71
+ }));
72
+ expect(screen.getAllByText(/Created by/)).toHaveLength(1);
73
+ expect(screen.getAllByText(/hello Jane Doe/)).toHaveLength(1);
74
+ });
75
+ });
76
+ });
77
+ describe("and name is 2 words", function () {
78
+ var item = {
79
+ action: "create",
80
+ name: "Jane Doe"
81
+ };
82
+ it("renders the correct initials", function () {
83
+ render( /*#__PURE__*/React.createElement(AuditItem, {
84
+ item: item
85
+ }));
86
+ expect(screen.getAllByText(/JD/)).toHaveLength(1);
87
+ });
88
+ it("renders the name and preposition", function () {
89
+ render( /*#__PURE__*/React.createElement(AuditItem, {
90
+ item: item
91
+ }));
92
+ expect(screen.getAllByText(/Created by/)).toHaveLength(1);
93
+ expect(screen.getAllByText(/Jane Doe/)).toHaveLength(1);
94
+ });
95
+ });
96
+ describe("and name is 1 word", function () {
97
+ var item = {
98
+ action: "create",
99
+ name: "Jane"
100
+ };
101
+ it("renders the name and preposition", function () {
102
+ render( /*#__PURE__*/React.createElement(AuditItem, {
103
+ item: item
104
+ }));
105
+ expect(screen.getAllByText(/Created by/)).toHaveLength(1);
106
+ expect(screen.getAllByText(/Jane/)).toHaveLength(1);
107
+ });
108
+ it("renders the initial of that one word", function () {
109
+ var _render3 = render( /*#__PURE__*/React.createElement(AuditItem, {
110
+ item: item
111
+ })),
112
+ container = _render3.container;
113
+ expect(container.querySelector("span").textContent).toBe("J");
114
+ });
115
+ });
116
+ describe("and name is given", function () {
117
+ var item = {
118
+ action: "create",
119
+ name: "Jane"
120
+ };
121
+ describe("and source is given", function () {
122
+ it("renders the name", function () {
123
+ render( /*#__PURE__*/React.createElement(AuditItem, {
124
+ item: item
125
+ }));
126
+ expect(screen.getAllByText(/Jane/)).toHaveLength(1);
127
+ });
128
+ it("renders the source in brackets", function () {
129
+ render( /*#__PURE__*/React.createElement(AuditItem, {
130
+ item: _extends({}, item, {
131
+ source: "ThirdPartyApp"
132
+ })
133
+ }));
134
+ expect(screen.getAllByText(/(using ThirdPartyApp)/)).toHaveLength(1);
135
+ });
136
+ });
137
+ describe("and source is not given", function () {
138
+ it("renders the name", function () {
139
+ render( /*#__PURE__*/React.createElement(AuditItem, {
140
+ item: item
141
+ }));
142
+ expect(screen.getAllByText(/Jane/)).toHaveLength(1);
143
+ });
144
+ it("does not render the source", function () {
145
+ render( /*#__PURE__*/React.createElement(AuditItem, {
146
+ item: item
147
+ }));
148
+
149
+ // this regex should match the word `using`
150
+ expect(screen.queryAllByText(/\busing\b/i)).toHaveLength(0);
151
+ });
152
+ });
153
+ });
154
+ });
155
+ describe("and does contain the word gentu", function () {
156
+ var item = {
157
+ action: "create",
158
+ name: "Gentu (Automated)"
159
+ };
160
+ it("renders gentu brand icon", function () {
161
+ var _render4 = render( /*#__PURE__*/React.createElement(AuditItem, {
162
+ item: item
163
+ })),
164
+ container = _render4.container;
165
+ expect(findSVGs(container, GentuLogo)).toHaveLength(1);
166
+ });
167
+ it("renders the name and preposition", function () {
168
+ render( /*#__PURE__*/React.createElement(AuditItem, {
169
+ item: item
170
+ }));
171
+ expect(screen.getAllByText(/Created by/)).toHaveLength(1);
172
+ expect(screen.getAllByText(/Gentu \(Automated\)/)).toHaveLength(1);
173
+ });
174
+ });
175
+ });
176
+ describe("and name is not given", function () {
177
+ var item = {
178
+ action: "create"
179
+ };
180
+ it("uses the actions fallback icon instead of initials", function () {
181
+ var _render5 = render( /*#__PURE__*/React.createElement(AuditItem, {
182
+ item: item
183
+ })),
184
+ container = _render5.container;
185
+ expect(findSVGs(container, Add)).toHaveLength(1);
186
+ });
187
+ it("does not render the name or preposition", function () {
188
+ render( /*#__PURE__*/React.createElement(AuditItem, {
189
+ item: item
190
+ }));
191
+
192
+ // this regex should match any word that isn't Created
193
+ expect(screen.queryAllByText(/\b(?!Created)\w+\b/)).toHaveLength(0);
194
+ });
195
+ describe("and source is given", function () {
196
+ var itemWithSource = {
197
+ action: "create",
198
+ source: "ThirdPartyApp"
199
+ };
200
+ it("renders the source not in brackets", function () {
201
+ render( /*#__PURE__*/React.createElement(AuditItem, {
202
+ item: itemWithSource
203
+ }));
204
+ expect(screen.getAllByText(/using ThirdPartyApp/)).toHaveLength(1);
205
+ expect(screen.queryAllByText(/\(using ThirdPartyApp\)/)).toHaveLength(0);
206
+ });
207
+ it("does not render a preposition", function () {
208
+ render( /*#__PURE__*/React.createElement(AuditItem, {
209
+ item: itemWithSource
210
+ }));
211
+ expect(screen.queryAllByText(/by/)).toHaveLength(0);
212
+ });
213
+ });
214
+ describe("and source is not given", function () {
215
+ var itemWithNoSource = {
216
+ action: "create"
217
+ };
218
+ it("does not render the name or the source", function () {
219
+ render( /*#__PURE__*/React.createElement(AuditItem, {
220
+ item: itemWithNoSource
221
+ }));
222
+
223
+ // this regex should match any word that isn't Created
224
+ expect(screen.queryAllByText(/\b(?!Created)\w+\b/)).toHaveLength(0);
225
+ });
226
+ });
227
+ });
228
+ describe("and dateTime is given", function () {
229
+ describe("and dateTime is valid", function () {
230
+ describe("and dateTime is in ISO with a 'T'", function () {
231
+ var item = {
232
+ action: "create",
233
+ dateTime: "2024-03-22T15:30:00"
234
+ };
235
+ it("renders dateTime correctly", function () {
236
+ render( /*#__PURE__*/React.createElement(AuditItem, {
237
+ item: item
238
+ }));
239
+ expect(screen.getAllByText(/on 22\/03\/2024 at 3:30:00 PM \(2 hours ago\)/)).toHaveLength(1);
240
+ });
241
+ });
242
+ describe("and dateTime is in ISO with a space", function () {
243
+ var item = {
244
+ action: "create",
245
+ dateTime: "2024-03-22 15:30:00"
246
+ };
247
+ it("renders dateTime correctly", function () {
248
+ render( /*#__PURE__*/React.createElement(AuditItem, {
249
+ item: item
250
+ }));
251
+ expect(screen.getAllByText(/on 22\/03\/2024 at 3:30:00 PM \(2 hours ago\)/)).toHaveLength(1);
252
+ });
253
+ });
254
+ });
255
+ describe("and dateTime is invalid because date is impossible", function () {
256
+ var item = {
257
+ action: "create",
258
+ dateTime: "2024-22-22 15:30:00"
259
+ };
260
+ it("does not render the date time or leading text", function () {
261
+ render( /*#__PURE__*/React.createElement(AuditItem, {
262
+ item: item
263
+ }));
264
+
265
+ // this regex should match any word that isn't Created
266
+ expect(screen.queryAllByText(/\b(?!Created)\w+\b/)).toHaveLength(0);
267
+ });
268
+ });
269
+ });
270
+ describe("and dateTime is invalid because not resembling a date", function () {
271
+ var item = {
272
+ action: "create",
273
+ dateTime: "string"
274
+ };
275
+ it("does not render the date time or leading text", function () {
276
+ render( /*#__PURE__*/React.createElement(AuditItem, {
277
+ item: item
278
+ }));
279
+
280
+ // this regex should match any word that isn't Created
281
+ expect(screen.queryAllByText(/\b(?!Created)\w+\b/)).toHaveLength(0);
282
+ });
283
+ });
284
+ describe("and dateTime is not given", function () {
285
+ var item = {
286
+ action: "create",
287
+ dateTime: "2024-22-22 15:30:00"
288
+ };
289
+ it("does not render the date time or leading text", function () {
290
+ render( /*#__PURE__*/React.createElement(AuditItem, {
291
+ item: item
292
+ }));
293
+
294
+ // this regex should match any word that isn't Created
295
+ expect(screen.queryAllByText(/\b(?!Created)\w+\b/)).toHaveLength(0);
296
+ });
297
+ });
298
+ });
299
+ describe("when action is custom", function () {
300
+ var defaultActionProps = {
301
+ actionName: "Actioned",
302
+ preposition: "from",
303
+ fallbackIcon: Contact,
304
+ forceIcon: false
305
+ };
306
+ var createItemProps = function createItemProps() {
307
+ var actionProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
308
+ return {
309
+ action: "custom",
310
+ actionProps: actionProps || defaultActionProps,
311
+ name: "Joe Bloggs",
312
+ dateTime: "2024-03-22T15:30:00"
313
+ };
314
+ };
315
+ it("renders the given preposition with the name", function () {
316
+ render( /*#__PURE__*/React.createElement(AuditItem, {
317
+ item: createItemProps()
318
+ }));
319
+ expect(screen.getByText(/Joe Bloggs/)).toBeDefined();
320
+ expect(screen.getByText(/from/)).toBeDefined();
321
+ });
322
+ it("renders the given actionName", function () {
323
+ render( /*#__PURE__*/React.createElement(AuditItem, {
324
+ item: createItemProps()
325
+ }));
326
+ expect(screen.getByText(/Actioned/)).toBeDefined();
327
+ });
328
+ describe("and when forceIcon is true", function () {
329
+ describe("and when fallbackIcon is given", function () {
330
+ var forceIconActionProps = _extends({}, defaultActionProps, {
331
+ forceIcon: true,
332
+ fallbackIcon: Link
333
+ });
334
+ it("renders the fallbackIcon", function () {
335
+ var _render6 = render( /*#__PURE__*/React.createElement(AuditItem, {
336
+ item: createItemProps(forceIconActionProps)
337
+ })),
338
+ container = _render6.container;
339
+ expect(findSVGs(container, Link)).toHaveLength(1);
340
+ });
341
+ });
342
+ describe("and fallbackIcon is not given", function () {
343
+ var forceIconActionProps = _extends({}, defaultActionProps, {
344
+ fallbackIcon: null,
345
+ forceIcon: true
346
+ });
347
+ it("renders the <Contact /> icon", function () {
348
+ var _render7 = render( /*#__PURE__*/React.createElement(AuditItem, {
349
+ item: createItemProps(forceIconActionProps)
350
+ })),
351
+ container = _render7.container;
352
+ expect(findSVGs(container, Contact)).toHaveLength(1);
353
+ });
354
+ });
355
+ });
356
+ describe("and forceIcon is false", function () {
357
+ var dontForceIconActionProps = _extends({}, defaultActionProps, {
358
+ forceIcon: false,
359
+ fallbackIcon: Link
360
+ });
361
+ describe("and initials can be generated", function () {
362
+ var item = _extends({}, createItemProps(dontForceIconActionProps), {
363
+ name: "Joe Bloggs"
364
+ });
365
+ it("renders the initials", function () {
366
+ render( /*#__PURE__*/React.createElement(AuditItem, {
367
+ item: item
368
+ }));
369
+ expect(screen.getAllByText(/JB/)).toHaveLength(1);
370
+ });
371
+ });
372
+ describe("and initials cannot be generated", function () {
373
+ describe("and fallbackIcon is given", function () {
374
+ var item = _extends({}, createItemProps(_extends({}, dontForceIconActionProps, {
375
+ fallbackIcon: Link
376
+ })), {
377
+ name: "Joe shmo the third"
378
+ });
379
+ it("renders the fallbackIcon", function () {
380
+ var _render8 = render( /*#__PURE__*/React.createElement(AuditItem, {
381
+ item: item
382
+ })),
383
+ container = _render8.container;
384
+ expect(findSVGs(container, Link)).toHaveLength(1);
385
+ });
386
+ });
387
+ describe("and fallbackIcon is not given", function () {
388
+ var item = _extends({}, createItemProps(_extends({}, dontForceIconActionProps, {
389
+ fallbackIcon: null
390
+ })), {
391
+ name: "Joe shmo the third"
392
+ });
393
+ it("renders the <Contact /> icon", function () {
394
+ var _render9 = render( /*#__PURE__*/React.createElement(AuditItem, {
395
+ item: item
396
+ })),
397
+ container = _render9.container;
398
+ expect(findSVGs(container, Contact)).toHaveLength(1);
399
+ });
400
+ });
401
+ });
402
+ });
403
+ });
404
+ });
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { useMemo } from "react";
2
2
  import { Avatar } from "../../Avatar";
3
3
  import IconAvatar from "../components/IconAvatar";
4
4
  import { ACTIONS } from "../constants";
@@ -12,6 +12,16 @@ var useAuditTrail = function useAuditTrail(item) {
12
12
  fallbackIcon = _ref.fallbackIcon,
13
13
  forceIcon = _ref.forceIcon;
14
14
  var brandIcon = getBrand(item.name);
15
+ var auditHistory = useMemo(function () {
16
+ var result = actionName || "";
17
+ if (item.name) {
18
+ result += " ".concat(preposition, " ").concat(item.name);
19
+ }
20
+ if (item.source) {
21
+ result += item.name ? " (using ".concat(item.source, ")") : " using ".concat(item.source);
22
+ }
23
+ return result;
24
+ }, [item, preposition, actionName]);
15
25
  function AvatarComponent() {
16
26
  return !initials || forceIcon || brandIcon ? /*#__PURE__*/React.createElement(IconAvatar, {
17
27
  icon: brandIcon || fallbackIcon
@@ -20,6 +30,6 @@ var useAuditTrail = function useAuditTrail(item) {
20
30
  initials: initials
21
31
  });
22
32
  }
23
- return [time, actionName, preposition, AvatarComponent];
33
+ return [time, auditHistory, AvatarComponent];
24
34
  };
25
35
  export default useAuditTrail;
@@ -0,0 +1,138 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import { renderHook } from "@testing-library/react-hooks";
3
+ import useAuditTrail from "./useAuditTrail";
4
+ describe("useAuditTrail", function () {
5
+ beforeEach(function () {
6
+ jest.clearAllMocks();
7
+ });
8
+ describe("auditHistory", function () {
9
+ describe("when item contains a custom action", function () {
10
+ var customActionItem = {
11
+ action: "custom",
12
+ actionProps: {
13
+ actionName: "Assigned",
14
+ preposition: "to",
15
+ forceIcon: true
16
+ }
17
+ };
18
+ describe("and the item contains a name and source", function () {
19
+ it("should return the audit history with the name and source", function () {
20
+ var _renderHook = renderHook(function () {
21
+ return useAuditTrail(_extends({}, customActionItem, {
22
+ name: "Olga Campbell",
23
+ source: "ThirdPartyApp"
24
+ }));
25
+ }),
26
+ result = _renderHook.result;
27
+ var auditHistory = result.current[1];
28
+ expect(auditHistory).toEqual("Assigned to Olga Campbell (using ThirdPartyApp)");
29
+ });
30
+ });
31
+ describe("and the item contains a source but no name", function () {
32
+ describe("and it does not contain an actionName", function () {
33
+ it("should return the audit history with the source", function () {
34
+ var _renderHook2 = renderHook(function () {
35
+ return useAuditTrail(_extends({}, customActionItem, {
36
+ actionProps: {},
37
+ source: "ThirdPartyApp"
38
+ }));
39
+ }),
40
+ result = _renderHook2.result;
41
+ var auditHistory = result.current[1];
42
+ expect(auditHistory).toEqual(" using ThirdPartyApp");
43
+ });
44
+ });
45
+ describe("and it contains an actionName", function () {
46
+ it("should return the audit history with the source", function () {
47
+ var _renderHook3 = renderHook(function () {
48
+ return useAuditTrail(_extends({}, customActionItem, {
49
+ source: "ThirdPartyApp"
50
+ }));
51
+ }),
52
+ result = _renderHook3.result;
53
+ var auditHistory = result.current[1];
54
+ expect(auditHistory).toEqual("Assigned using ThirdPartyApp");
55
+ });
56
+ });
57
+ });
58
+ describe("and the item contains a name but no source", function () {
59
+ it("should return the audit history with the name", function () {
60
+ var _renderHook4 = renderHook(function () {
61
+ return useAuditTrail(_extends({}, customActionItem, {
62
+ name: "Olga Campbell"
63
+ }));
64
+ }),
65
+ result = _renderHook4.result;
66
+ var auditHistory = result.current[1];
67
+ expect(auditHistory).toEqual("Assigned to Olga Campbell");
68
+ });
69
+ });
70
+ describe("and the item contains neither a name or a source or actionName", function () {
71
+ it("should return the audit history as a blank string", function () {
72
+ var _renderHook5 = renderHook(function () {
73
+ return useAuditTrail(_extends({}, customActionItem, {
74
+ actionProps: {}
75
+ }));
76
+ }),
77
+ result = _renderHook5.result;
78
+ var auditHistory = result.current[1];
79
+ expect(auditHistory).toEqual("");
80
+ });
81
+ });
82
+ });
83
+ describe("when item is not a custom action", function () {
84
+ var item = {
85
+ action: "create",
86
+ name: "",
87
+ source: ""
88
+ };
89
+ describe("and the item contains a name and source", function () {
90
+ it("should return the audit history with the name and source", function () {
91
+ var _renderHook6 = renderHook(function () {
92
+ return useAuditTrail(_extends({}, item, {
93
+ name: "Olga Campbell",
94
+ source: "ThirdPartyApp"
95
+ }));
96
+ }),
97
+ result = _renderHook6.result;
98
+ var auditHistory = result.current[1];
99
+ expect(auditHistory).toEqual("Created by Olga Campbell (using ThirdPartyApp)");
100
+ });
101
+ });
102
+ describe("and the item contains a name but no source", function () {
103
+ it("should return the audit history with the name and no source", function () {
104
+ var _renderHook7 = renderHook(function () {
105
+ return useAuditTrail(_extends({}, item, {
106
+ name: "Olga Campbell"
107
+ }));
108
+ }),
109
+ result = _renderHook7.result;
110
+ var auditHistory = result.current[1];
111
+ expect(auditHistory).toEqual("Created by Olga Campbell");
112
+ });
113
+ });
114
+ describe("and the item contains no name but a source", function () {
115
+ it("should return the audit history with the source", function () {
116
+ var _renderHook8 = renderHook(function () {
117
+ return useAuditTrail(_extends({}, item, {
118
+ source: "ThirdPartyApp"
119
+ }));
120
+ }),
121
+ result = _renderHook8.result;
122
+ var auditHistory = result.current[1];
123
+ expect(auditHistory).toEqual("Created using ThirdPartyApp");
124
+ });
125
+ });
126
+ describe("and the item contains neither a name or a source", function () {
127
+ it("should return the audit history with no name or source", function () {
128
+ var _renderHook9 = renderHook(function () {
129
+ return useAuditTrail(item);
130
+ }),
131
+ result = _renderHook9.result;
132
+ var auditHistory = result.current[1];
133
+ expect(auditHistory).toEqual("Created");
134
+ });
135
+ });
136
+ });
137
+ });
138
+ });
@@ -1,45 +1,67 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- import { render } from "@testing-library/react";
1
+ import { render, screen } from "@testing-library/react";
3
2
  import React from "react";
4
3
  import AuditTrail from "./index";
5
4
  describe("AuditTrail", function () {
6
- var defaultItem = {
7
- action: "create",
8
- name: "My Name",
9
- dateTime: "2023-05-12T12:00:00Z"
10
- };
11
- it("should render Initial's when name is valid", function () {
12
- var _render = render( /*#__PURE__*/React.createElement(AuditTrail, {
13
- items: [defaultItem]
14
- })),
15
- getByText = _render.getByText;
16
- expect(getByText("MN")).toBeDefined();
5
+ describe("when there is one item", function () {
6
+ var items = [{
7
+ action: "create",
8
+ name: "Joe Bloggs",
9
+ dateTime: "2024-03-22T15:30:00Z"
10
+ }];
11
+ it("renders one audit item", function () {
12
+ render( /*#__PURE__*/React.createElement(AuditTrail, {
13
+ items: items
14
+ }));
15
+ expect(screen.getAllByText(/Joe Bloggs/).length).toBe(1);
16
+ });
17
17
  });
18
- it("should render icon when name is invalid", function () {
19
- var _render2 = render( /*#__PURE__*/React.createElement(AuditTrail, {
20
- items: [_extends({}, defaultItem, {
21
- name: "My Name Things"
22
- })]
23
- })),
24
- container = _render2.container;
25
- expect(container.querySelectorAll("svg")).toHaveLength(1);
18
+ describe("when there are multiple items", function () {
19
+ describe("two items", function () {
20
+ var items = [{
21
+ action: "create",
22
+ name: "Joe Bloggs",
23
+ dateTime: "2024-03-22T15:30:00Z"
24
+ }, {
25
+ action: "edit",
26
+ name: "Joe Bloggs",
27
+ dateTime: "2024-03-22T15:30:00Z"
28
+ }];
29
+ it("renders the correct number of audit items", function () {
30
+ render( /*#__PURE__*/React.createElement(AuditTrail, {
31
+ items: items
32
+ }));
33
+ expect(screen.getAllByText(/Joe Bloggs/).length).toBe(2);
34
+ });
35
+ });
36
+ describe("three items", function () {
37
+ var items = [{
38
+ action: "create",
39
+ name: "Joe Bloggs",
40
+ dateTime: "2024-03-22T15:30:00Z"
41
+ }, {
42
+ action: "edit",
43
+ name: "Joe Bloggs",
44
+ dateTime: "2024-03-22T15:30:00Z"
45
+ }, {
46
+ action: "void",
47
+ name: "Joe Bloggs",
48
+ dateTime: "2024-03-22T15:30:00Z"
49
+ }];
50
+ it("renders the correct number of audit items", function () {
51
+ render( /*#__PURE__*/React.createElement(AuditTrail, {
52
+ items: items
53
+ }));
54
+ expect(screen.getAllByText(/Joe Bloggs/).length).toBe(3);
55
+ });
56
+ });
26
57
  });
27
- it("should render Initial's when name is invalid but forcedInitials is defined", function () {
28
- var _render3 = render( /*#__PURE__*/React.createElement(AuditTrail, {
29
- items: [_extends({}, defaultItem, {
30
- forcedInitials: "MN"
31
- })]
32
- })),
33
- getByText = _render3.getByText;
34
- expect(getByText("MN")).toBeDefined();
35
- });
36
- it("should render an icon when branch icon is triggered", function () {
37
- var _render4 = render( /*#__PURE__*/React.createElement(AuditTrail, {
38
- items: [_extends({}, defaultItem, {
39
- name: "Gentu"
40
- })]
41
- })),
42
- container = _render4.container;
43
- expect(container.querySelectorAll("svg")).toHaveLength(1);
58
+ describe("when there are no items", function () {
59
+ var items = [];
60
+ it("does not render any audit items", function () {
61
+ render( /*#__PURE__*/React.createElement(AuditTrail, {
62
+ items: items
63
+ }));
64
+ expect(screen.queryAllByText(/Joe Bloggs/).length).toBe(0);
65
+ });
44
66
  });
45
67
  });