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