@microsoft/omnichannel-chat-widget 1.5.1-main.ee4453c → 1.6.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 (47) hide show
  1. package/lib/cjs/common/Constants.js +18 -2
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +2 -0
  3. package/lib/cjs/components/livechatwidget/common/endChat.js +25 -3
  4. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +8 -4
  5. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +23 -8
  6. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +39 -0
  7. package/lib/cjs/components/startchaterrorpanestateful/StartChatErrorPaneStateful.js +20 -6
  8. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +37 -36
  9. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +3 -1
  10. package/lib/cjs/contexts/common/StartChatFailureType.js +13 -0
  11. package/lib/cjs/contexts/createReducer.js +8 -0
  12. package/lib/esm/common/Constants.js +16 -1
  13. package/lib/esm/common/telemetry/TelemetryConstants.js +2 -0
  14. package/lib/esm/components/livechatwidget/common/endChat.js +26 -4
  15. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +8 -4
  16. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +24 -9
  17. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +40 -1
  18. package/lib/esm/components/startchaterrorpanestateful/StartChatErrorPaneStateful.js +20 -6
  19. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +37 -36
  20. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +3 -1
  21. package/lib/esm/contexts/common/StartChatFailureType.js +6 -0
  22. package/lib/esm/contexts/createReducer.js +8 -0
  23. package/lib/types/common/Constants.d.ts +16 -0
  24. package/lib/types/common/telemetry/TelemetryConstants.d.ts +1 -0
  25. package/lib/types/components/startchaterrorpanestateful/interfaces/IStartChatErrorPaneControlProps.d.ts +4 -0
  26. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -0
  27. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +37 -36
  28. package/lib/types/contexts/common/StartChatFailureType.d.ts +5 -0
  29. package/package.json +3 -3
  30. package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.js +0 -71
  31. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.js +0 -56
  32. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.spec.js +0 -282
  33. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +0 -190
  34. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +0 -82
  35. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +0 -342
  36. package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.js +0 -69
  37. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.js +0 -54
  38. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.spec.js +0 -280
  39. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +0 -188
  40. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +0 -80
  41. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +0 -338
  42. package/lib/types/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.d.ts +0 -1
  43. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.d.ts +0 -1
  44. package/lib/types/components/livechatwidget/common/startChatErrorHandler.spec.d.ts +0 -1
  45. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.d.ts +0 -1
  46. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +0 -1
  47. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.d.ts +0 -1
@@ -1,82 +0,0 @@
1
- "use strict";
2
-
3
- require("@testing-library/jest-dom/extend-expect");
4
- var _cardActionMiddleware = require("./cardActionMiddleware");
5
- describe("cardActionMiddleware test", () => {
6
- it("createCardActionMiddleware() with undefined botMagicCodeConfig should not change the sign in card url", () => {
7
- const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
8
- const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
9
- const args = {
10
- cardAction: {
11
- type: "signin",
12
- value: signInUrl
13
- }
14
- };
15
- const results = (0, _cardActionMiddleware.createCardActionMiddleware)(undefined)()(next)(args);
16
- expect(signInUrl).toEqual(results.cardAction.value);
17
- });
18
- it("createCardActionMiddleware() with botMagicCode enabled should not change the sign in card url", () => {
19
- const botMagicCodeConfig = {
20
- disabled: false
21
- };
22
- const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
23
- const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
24
- const args = {
25
- cardAction: {
26
- type: "signin",
27
- value: signInUrl
28
- }
29
- };
30
- const results = (0, _cardActionMiddleware.createCardActionMiddleware)(botMagicCodeConfig)()(next)(args);
31
- expect(args.cardAction.value).toEqual(results.cardAction.value);
32
- });
33
- it("createCardActionMiddleware() with botMagicCode disabled & no fwdUrl should not change the sign in card url", () => {
34
- const botMagicCodeConfig = {
35
- disabled: true
36
- };
37
- const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
38
- const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
39
- const args = {
40
- cardAction: {
41
- type: "signin",
42
- value: signInUrl
43
- }
44
- };
45
- const results = (0, _cardActionMiddleware.createCardActionMiddleware)(botMagicCodeConfig)()(next)(args);
46
- expect(args.cardAction.value).toEqual(results.cardAction.value);
47
- });
48
- it("createCardActionMiddleware() with botMagicCode disabled & fwdUrl should append the fwdUrl in the sign in card url", () => {
49
- const botMagicCodeConfig = {
50
- disabled: true,
51
- fwdUrl: "http://localhost/forwarder.html"
52
- };
53
- const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
54
- const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
55
- const args = {
56
- cardAction: {
57
- type: "signin",
58
- value: signInUrl
59
- }
60
- };
61
- const results = (0, _cardActionMiddleware.createCardActionMiddleware)(botMagicCodeConfig)()(next)(args);
62
- expect(signInUrl === results.cardAction.value).toBe(false);
63
- expect(results.cardAction.value === `${signInUrl}&fwdUrl=${botMagicCodeConfig.fwdUrl}`).toBe(true);
64
- });
65
- it("createCardActionMiddleware() should not append fwdUrl if fwdUrl & sign in card url are not in the same domain", () => {
66
- const botMagicCodeConfig = {
67
- disabled: true,
68
- fwdUrl: "https://localhost/forwarder.html"
69
- };
70
- const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
71
- const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
72
- const args = {
73
- cardAction: {
74
- type: "signin",
75
- value: signInUrl
76
- }
77
- };
78
- const results = (0, _cardActionMiddleware.createCardActionMiddleware)(botMagicCodeConfig)()(next)(args);
79
- expect(signInUrl === results.cardAction.value).toBe(true);
80
- expect(results.cardAction.value === `${signInUrl}&fwdUrl=${botMagicCodeConfig.fwdUrl}`).toBe(false);
81
- });
82
- });
@@ -1,342 +0,0 @@
1
- "use strict";
2
-
3
- var _Constants = require("../../../../../common/Constants");
4
- var _WebChatActionType = require("../../enums/WebChatActionType");
5
- var _messageSequenceIdOverrideMiddleware = _interopRequireDefault(require("./messageSequenceIdOverrideMiddleware"));
6
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
- /* eslint-disable @typescript-eslint/no-explicit-any */
8
-
9
- describe("messageSequenceIdOverrideMiddleware", () => {
10
- it("sequenceId is overrided", () => {
11
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
- const next = args => args;
13
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
- const dispatch = () => {
15
- return 1;
16
- };
17
- const action = {
18
- type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
19
- payload: {
20
- text: "test-text",
21
- activity: {
22
- channelId: "ACS_CHANNEL",
23
- from: {
24
- role: "user"
25
- },
26
- channelData: {
27
- metadata: {
28
- "OriginalMessageId": "1683742135918"
29
- },
30
- "webchat:sequence-id": 12345
31
- }
32
- }
33
- }
34
- };
35
- const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
36
- let resultValue;
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
38
- const channelData = middleware.payload.activity.channelData;
39
- Object.keys(channelData).forEach(function (key) {
40
- if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
41
- resultValue = channelData[key];
42
- }
43
- });
44
- expect(resultValue).toEqual(1683742135918);
45
- });
46
- it("sequenceId is not overrided due to empty string for originalID", () => {
47
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
- const next = args => args;
49
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
- const dispatch = () => {
51
- return 1;
52
- };
53
- const action = {
54
- type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
55
- payload: {
56
- text: "test-text",
57
- activity: {
58
- channelId: "ACS_CHANNEL",
59
- from: {
60
- role: "user"
61
- },
62
- channelData: {
63
- metadata: {
64
- "OriginalMessageId": ""
65
- },
66
- "webchat:sequence-id": 12345
67
- }
68
- }
69
- }
70
- };
71
- const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
72
- let resultValue;
73
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
74
- const channelData = middleware.payload.activity.channelData;
75
- Object.keys(channelData).forEach(function (key) {
76
- if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
77
- resultValue = channelData[key];
78
- }
79
- });
80
- expect(resultValue).toEqual(12345);
81
- });
82
- it("sequenceId is not overrided, due to OriginalMessageId being not a string of numbers ", () => {
83
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
- const next = args => args;
85
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
- const dispatch = () => {
87
- return 1;
88
- };
89
- const action = {
90
- type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
91
- payload: {
92
- text: "test-text",
93
- activity: {
94
- channelId: "ACS_CHANNEL",
95
- from: {
96
- role: "user"
97
- },
98
- channelData: {
99
- metadata: {
100
- "OriginalMessageId": "abcdf"
101
- },
102
- "webchat:sequence-id": 12345
103
- }
104
- }
105
- }
106
- };
107
- const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
108
- let resultValue;
109
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
110
- const channelData = middleware.payload.activity.channelData;
111
- Object.keys(channelData).forEach(function (key) {
112
- if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
113
- resultValue = channelData[key];
114
- }
115
- });
116
- expect(resultValue).toEqual(12345);
117
- });
118
- it("no changes since webchat id is not present", () => {
119
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
- const next = args => args;
121
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
122
- const dispatch = () => {
123
- return 1;
124
- };
125
- const payloadExpected = {
126
- payload: {
127
- text: "test-text",
128
- activity: {
129
- channelId: "ACS_CHANNEL",
130
- from: {
131
- role: "user"
132
- },
133
- channelData: {
134
- metadata: {
135
- "OriginalMessageId": "123456789"
136
- }
137
- }
138
- }
139
- }
140
- };
141
- const action = {
142
- type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
143
- payload: {
144
- text: "test-text",
145
- activity: {
146
- channelId: "ACS_CHANNEL",
147
- from: {
148
- role: "user"
149
- },
150
- channelData: {
151
- metadata: {
152
- "OriginalMessageId": "123456789"
153
- }
154
- }
155
- }
156
- }
157
- };
158
- const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
159
- expect(middleware.payload).toEqual(payloadExpected.payload);
160
- });
161
- it("no changes since OriginalMessageId is not present", () => {
162
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
163
- const next = args => args;
164
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
165
- const dispatch = () => {
166
- return 1;
167
- };
168
- const payloadExpected = {
169
- payload: {
170
- text: "test-text",
171
- activity: {
172
- channelId: "ACS_CHANNEL",
173
- from: {
174
- role: "user"
175
- },
176
- channelData: {
177
- metadata: {},
178
- "webchat:sequence-id": 12345
179
- }
180
- }
181
- }
182
- };
183
- const action = {
184
- type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
185
- payload: {
186
- text: "test-text",
187
- activity: {
188
- channelId: "ACS_CHANNEL",
189
- from: {
190
- role: "user"
191
- },
192
- channelData: {
193
- metadata: {},
194
- "webchat:sequence-id": 12345
195
- }
196
- }
197
- }
198
- };
199
- const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
200
- expect(middleware.payload).toEqual(payloadExpected.payload);
201
- });
202
- it("no override, since the type of message is not incoming activity", () => {
203
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
204
- const next = args => args;
205
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
206
- const dispatch = () => {
207
- return 1;
208
- };
209
- const action = {
210
- type: "something else",
211
- payload: {
212
- text: "test-text",
213
- activity: {
214
- channelId: "ACS_CHANNEL",
215
- from: {
216
- role: "user"
217
- },
218
- channelData: {
219
- metadata: {
220
- "OriginalMessageId": "1683742135918"
221
- },
222
- "webchat:sequence-id": 12345
223
- }
224
- }
225
- }
226
- };
227
- const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
228
- let resultValue;
229
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
230
- const channelData = middleware.payload.activity.channelData;
231
- Object.keys(channelData).forEach(function (key) {
232
- if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
233
- resultValue = channelData[key];
234
- }
235
- });
236
- expect(resultValue).toEqual(12345);
237
- });
238
- it("no override, since the channel is not ACS", () => {
239
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
240
- const next = args => args;
241
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
242
- const dispatch = () => {
243
- return 1;
244
- };
245
- const action = {
246
- type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
247
- payload: {
248
- text: "test-text",
249
- activity: {
250
- channelId: "something_else",
251
- from: {
252
- role: "user"
253
- },
254
- channelData: {
255
- metadata: {
256
- "OriginalMessageId": "1683742135918"
257
- },
258
- "webchat:sequence-id": 12345
259
- }
260
- }
261
- }
262
- };
263
- const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
264
- let resultValue;
265
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
266
- const channelData = middleware.payload.activity.channelData;
267
- Object.keys(channelData).forEach(function (key) {
268
- if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
269
- resultValue = channelData[key];
270
- }
271
- });
272
- expect(resultValue).toEqual(12345);
273
- });
274
- it("no override, since the channel channelData is not present", () => {
275
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
276
- const next = args => args;
277
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
278
- const dispatch = () => {
279
- return 1;
280
- };
281
- const action = {
282
- type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
283
- payload: {
284
- text: "test-text channel data is not present",
285
- activity: {
286
- channelId: "ACS_CHANNEL",
287
- from: {
288
- role: "user"
289
- }
290
- }
291
- }
292
- };
293
- const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
294
- expect(middleware.payload).toEqual(action.payload);
295
- });
296
- it("no override, since channelData is empty object", () => {
297
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
298
- const next = args => args;
299
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
300
- const dispatch = () => {
301
- return 1;
302
- };
303
- const action = {
304
- type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
305
- payload: {
306
- text: "test-text channel data empty",
307
- activity: {
308
- channelId: "ACS_CHANNEL",
309
- from: {
310
- role: "user"
311
- },
312
- channelData: {}
313
- }
314
- }
315
- };
316
- const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
317
- expect(middleware.payload).toEqual(action.payload);
318
- });
319
- it("no override, since channelData null", () => {
320
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
321
- const next = args => args;
322
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
323
- const dispatch = () => {
324
- return 1;
325
- };
326
- const action = {
327
- type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
328
- payload: {
329
- text: "test-channel Data null",
330
- activity: {
331
- channelId: "ACS_CHANNEL",
332
- from: {
333
- role: "user"
334
- },
335
- channelData: null
336
- }
337
- }
338
- };
339
- const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
340
- expect(middleware.payload).toEqual(action.payload);
341
- });
342
- });
@@ -1,69 +0,0 @@
1
- import { OmnichannelChatSDK } from "@microsoft/omnichannel-chat-sdk";
2
- import { cleanup } from "@testing-library/react";
3
- jest.mock("@microsoft/omnichannel-chat-sdk");
4
- describe("EmailTranscriptPaneStateful unit test", () => {
5
- afterEach(() => {
6
- cleanup;
7
- jest.resetAllMocks();
8
- });
9
- it("Method emailLiveChatTranscript is called", async () => {
10
- const omnichannelConfig = {
11
- orgUrl: "",
12
- orgId: "",
13
- widgetId: ""
14
- };
15
- const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
16
- jest.spyOn(chatSDK, "emailLiveChatTranscript").mockResolvedValue(Promise.resolve());
17
- const chatTranscriptBody = {
18
- emailAddress: "sample@microsoft.com",
19
- attachmentMessage: "sample",
20
- locale: "sample"
21
- };
22
- try {
23
- await chatSDK.emailLiveChatTranscript(chatTranscriptBody);
24
- expect(chatSDK.emailLiveChatTranscript).toHaveBeenCalledTimes(1);
25
- // eslint-disable-next-line no-empty
26
- } catch (ex) {}
27
- });
28
- it("Method emailLiveChatTranscript throws exception", async () => {
29
- const errorMessage = "Error";
30
- const omnichannelConfig = {
31
- orgUrl: "",
32
- orgId: "",
33
- widgetId: ""
34
- };
35
- const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
36
- jest.spyOn(chatSDK, "emailLiveChatTranscript").mockRejectedValue(new Error(errorMessage));
37
- const chatTranscriptBody = {
38
- emailAddress: "sample@microsoft.com",
39
- attachmentMessage: "sample",
40
- locale: "sample"
41
- };
42
- try {
43
- await chatSDK.emailLiveChatTranscript(chatTranscriptBody);
44
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
- } catch (ex) {
46
- expect(ex.message).toEqual(errorMessage);
47
- }
48
- });
49
- it("Method emailLiveChatTranscript undefined throws exception", async () => {
50
- const errorMessage = "Error";
51
- const omnichannelConfig = {
52
- orgUrl: "",
53
- orgId: "",
54
- widgetId: ""
55
- };
56
- const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
57
- const chatTranscriptBody = {
58
- emailAddress: "sample@microsoft.com",
59
- attachmentMessage: "sample",
60
- locale: "sample"
61
- };
62
- try {
63
- await chatSDK.emailLiveChatTranscript(chatTranscriptBody);
64
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
- } catch (ex) {
66
- expect(ex.message).toEqual(errorMessage);
67
- }
68
- });
69
- });
@@ -1,54 +0,0 @@
1
- import { OmnichannelChatSDK } from "@microsoft/omnichannel-chat-sdk";
2
- import { cleanup } from "@testing-library/react";
3
- jest.mock("@microsoft/omnichannel-chat-sdk");
4
- describe("DownloadTranscriptStateful unit test", () => {
5
- afterEach(() => {
6
- cleanup;
7
- jest.resetAllMocks();
8
- });
9
- it("Method getLiveChatTranscript is called", async () => {
10
- const omnichannelConfig = {
11
- orgUrl: "",
12
- orgId: "",
13
- widgetId: ""
14
- };
15
- const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
16
- jest.spyOn(chatSDK, "getLiveChatTranscript").mockResolvedValue(Promise.resolve());
17
- try {
18
- await chatSDK.getLiveChatTranscript();
19
- expect(chatSDK.getLiveChatTranscript).toHaveBeenCalledTimes(1);
20
- // eslint-disable-next-line no-empty
21
- } catch (ex) {}
22
- });
23
- it("Method getLiveChatTranscript throws exception", async () => {
24
- const errorMessage = "Error";
25
- const omnichannelConfig = {
26
- orgUrl: "",
27
- orgId: "",
28
- widgetId: ""
29
- };
30
- const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
31
- jest.spyOn(chatSDK, "getLiveChatTranscript").mockRejectedValue(new Error(errorMessage));
32
- try {
33
- await chatSDK.getLiveChatTranscript();
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- } catch (ex) {
36
- expect(ex.message).toEqual(errorMessage);
37
- }
38
- });
39
- it("Method getLiveChatTranscript undefined throws exception", async () => {
40
- const errorMessage = "Error";
41
- const omnichannelConfig = {
42
- orgUrl: "",
43
- orgId: "",
44
- widgetId: ""
45
- };
46
- const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
47
- try {
48
- await chatSDK.getLiveChatTranscript();
49
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
- } catch (ex) {
51
- expect(ex.message).toEqual(errorMessage);
52
- }
53
- });
54
- });