@servicetitan/titan-chatbot-ui 3.1.0 → 3.1.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/CHANGELOG.md +12 -0
- package/dist/components/chatbot/__tests-cy__/chatbot-help-center.test.js +2 -156
- package/dist/components/chatbot/__tests-cy__/chatbot-help-center.test.js.map +1 -1
- package/dist/components/chatbot/__tests-cy__/chatbot-live.test.js +2 -94
- package/dist/components/chatbot/__tests-cy__/chatbot-live.test.js.map +1 -1
- package/dist/components/chatbot/__tests-cy__/chatbot-titan-chatbot.test.js +2 -151
- package/dist/components/chatbot/__tests-cy__/chatbot-titan-chatbot.test.js.map +1 -1
- package/dist/components/chatbot/__tests-cy__/chatbot.test.js +2 -151
- package/dist/components/chatbot/__tests-cy__/chatbot.test.js.map +1 -1
- package/dist/components/chatbot/chatbot.d.ts +2 -1
- package/dist/components/chatbot/chatbot.d.ts.map +1 -1
- package/dist/components/chatbot/chatbot.js +2 -2
- package/dist/components/chatbot/chatbot.js.map +1 -1
- package/dist/components/chatbot/dialog/__tests-cy__/chatbot-restart-dialog.test.d.ts +2 -0
- package/dist/components/chatbot/dialog/__tests-cy__/chatbot-restart-dialog.test.d.ts.map +1 -0
- package/dist/components/chatbot/dialog/__tests-cy__/chatbot-restart-dialog.test.js +6 -0
- package/dist/components/chatbot/dialog/__tests-cy__/chatbot-restart-dialog.test.js.map +1 -0
- package/dist/components/chatbot/dialog/__tests-cy__/chatbot-restart-link.test.d.ts +2 -0
- package/dist/components/chatbot/dialog/__tests-cy__/chatbot-restart-link.test.d.ts.map +1 -0
- package/dist/components/chatbot/dialog/__tests-cy__/chatbot-restart-link.test.js +6 -0
- package/dist/components/chatbot/dialog/__tests-cy__/chatbot-restart-link.test.js.map +1 -0
- package/dist/components/chatbot/dialog/chatbot-restart-dialog.d.ts.map +1 -1
- package/dist/components/chatbot/dialog/chatbot-restart-dialog.js +1 -1
- package/dist/components/chatbot/dialog/chatbot-restart-dialog.js.map +1 -1
- package/dist/components/chatbot/feedback/__tests-cy__/chatbot-message-feedback-form-guardrail.test.js +2 -61
- package/dist/components/chatbot/feedback/__tests-cy__/chatbot-message-feedback-form-guardrail.test.js.map +1 -1
- package/dist/components/chatbot/feedback/__tests-cy__/chatbot-message-feedback-form.test.js +2 -96
- package/dist/components/chatbot/feedback/__tests-cy__/chatbot-message-feedback-form.test.js.map +1 -1
- package/dist/components/chatbot/feedback/__tests-cy__/chatbot-message-feedback-popover.test.d.ts +2 -0
- package/dist/components/chatbot/feedback/__tests-cy__/chatbot-message-feedback-popover.test.d.ts.map +1 -0
- package/dist/components/chatbot/feedback/__tests-cy__/chatbot-message-feedback-popover.test.js +6 -0
- package/dist/components/chatbot/feedback/__tests-cy__/chatbot-message-feedback-popover.test.js.map +1 -0
- package/dist/components/chatbot/feedback/__tests-cy__/chatbot-session-feedback-modal.test.d.ts +2 -0
- package/dist/components/chatbot/feedback/__tests-cy__/chatbot-session-feedback-modal.test.d.ts.map +1 -0
- package/dist/components/chatbot/feedback/__tests-cy__/chatbot-session-feedback-modal.test.js +6 -0
- package/dist/components/chatbot/feedback/__tests-cy__/chatbot-session-feedback-modal.test.js.map +1 -0
- package/dist/components/chatbot/feedback/chatbot-message-feedback-form-guardrail.d.ts.map +1 -1
- package/dist/components/chatbot/feedback/chatbot-message-feedback-form-guardrail.js +1 -1
- package/dist/components/chatbot/feedback/chatbot-message-feedback-form-guardrail.js.map +1 -1
- package/dist/components/chatbot/feedback/chatbot-message-feedback-form.d.ts.map +1 -1
- package/dist/components/chatbot/feedback/chatbot-message-feedback-form.js +1 -1
- package/dist/components/chatbot/feedback/chatbot-message-feedback-form.js.map +1 -1
- package/dist/components/chatbot/feedback/chatbot-message-feedback-popover.d.ts.map +1 -1
- package/dist/components/chatbot/feedback/chatbot-message-feedback-popover.js +2 -4
- package/dist/components/chatbot/feedback/chatbot-message-feedback-popover.js.map +1 -1
- package/dist/components/chatbot/feedback/chatbot-session-feedback-modal.d.ts.map +1 -1
- package/dist/components/chatbot/feedback/chatbot-session-feedback-modal.js +1 -2
- package/dist/components/chatbot/feedback/chatbot-session-feedback-modal.js.map +1 -1
- package/dist/components/chatbot/filters/__tests-cy__/chatbot-filters.test.d.ts +2 -0
- package/dist/components/chatbot/filters/__tests-cy__/chatbot-filters.test.d.ts.map +1 -0
- package/dist/components/chatbot/filters/__tests-cy__/chatbot-filters.test.js +6 -0
- package/dist/components/chatbot/filters/__tests-cy__/chatbot-filters.test.js.map +1 -0
- package/dist/components/chatbot/filters/chatbot-filter.js +1 -1
- package/dist/components/chatbot/filters/chatbot-filter.js.map +1 -1
- package/dist/components/chatbot/messages/__tests-cy__/chatbot-links.test.d.ts +2 -0
- package/dist/components/chatbot/messages/__tests-cy__/chatbot-links.test.d.ts.map +1 -0
- package/dist/components/chatbot/messages/__tests-cy__/chatbot-links.test.js +6 -0
- package/dist/components/chatbot/messages/__tests-cy__/chatbot-links.test.js.map +1 -0
- package/dist/components/chatbot/messages/__tests-cy__/chatbot-message-answer-readonly.test.d.ts +2 -0
- package/dist/components/chatbot/messages/__tests-cy__/chatbot-message-answer-readonly.test.d.ts.map +1 -0
- package/dist/components/chatbot/messages/__tests-cy__/chatbot-message-answer-readonly.test.js +6 -0
- package/dist/components/chatbot/messages/__tests-cy__/chatbot-message-answer-readonly.test.js.map +1 -0
- package/dist/components/chatbot/messages/__tests-cy__/chatbot-message-answer.test.js +3 -82
- package/dist/components/chatbot/messages/__tests-cy__/chatbot-message-answer.test.js.map +1 -1
- package/dist/components/chatbot/messages/__tests-cy__/chatbot-message-typing.test.js +3 -54
- package/dist/components/chatbot/messages/__tests-cy__/chatbot-message-typing.test.js.map +1 -1
- package/package.json +6 -6
- package/src/components/chatbot/__tests-cy__/chatbot-help-center.test.tsx +2 -206
- package/src/components/chatbot/__tests-cy__/chatbot-live.test.tsx +2 -128
- package/src/components/chatbot/__tests-cy__/chatbot-titan-chatbot.test.tsx +2 -202
- package/src/components/chatbot/__tests-cy__/chatbot.test.tsx +2 -197
- package/src/components/chatbot/chatbot.tsx +66 -63
- package/src/components/chatbot/dialog/__tests-cy__/chatbot-restart-dialog.test.tsx +6 -0
- package/src/components/chatbot/dialog/__tests-cy__/chatbot-restart-link.test.tsx +6 -0
- package/src/components/chatbot/dialog/chatbot-restart-dialog.tsx +1 -0
- package/src/components/chatbot/feedback/__tests-cy__/chatbot-message-feedback-form-guardrail.test.tsx +2 -85
- package/src/components/chatbot/feedback/__tests-cy__/chatbot-message-feedback-form.test.tsx +2 -127
- package/src/components/chatbot/feedback/__tests-cy__/chatbot-message-feedback-popover.test.tsx +6 -0
- package/src/components/chatbot/feedback/__tests-cy__/chatbot-session-feedback-modal.test.tsx +6 -0
- package/src/components/chatbot/feedback/chatbot-message-feedback-form-guardrail.tsx +1 -1
- package/src/components/chatbot/feedback/chatbot-message-feedback-form.tsx +1 -1
- package/src/components/chatbot/feedback/chatbot-message-feedback-popover.tsx +8 -5
- package/src/components/chatbot/feedback/chatbot-session-feedback-modal.tsx +1 -2
- package/src/components/chatbot/filters/__tests-cy__/chatbot-filters.test.tsx +6 -0
- package/src/components/chatbot/filters/chatbot-filter.tsx +1 -1
- package/src/components/chatbot/messages/__tests-cy__/chatbot-links.test.tsx +6 -0
- package/src/components/chatbot/messages/__tests-cy__/chatbot-message-answer-readonly.test.tsx +6 -0
- package/src/components/chatbot/messages/__tests-cy__/chatbot-message-answer.test.tsx +3 -107
- package/src/components/chatbot/messages/__tests-cy__/chatbot-message-typing.test.tsx +3 -68
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/stores/__tests__/message-feedback-guardrail.store.test.d.ts +0 -2
- package/dist/stores/__tests__/message-feedback-guardrail.store.test.d.ts.map +0 -1
- package/dist/stores/__tests__/message-feedback-guardrail.store.test.js +0 -49
- package/dist/stores/__tests__/message-feedback-guardrail.store.test.js.map +0 -1
- package/dist/stores/__tests__/message-feedback.store.test.d.ts +0 -2
- package/dist/stores/__tests__/message-feedback.store.test.d.ts.map +0 -1
- package/dist/stores/__tests__/message-feedback.store.test.js +0 -114
- package/dist/stores/__tests__/message-feedback.store.test.js.map +0 -1
- package/dist/stores/__tests__/session-feedback.store.test.d.ts +0 -2
- package/dist/stores/__tests__/session-feedback.store.test.d.ts.map +0 -1
- package/dist/stores/__tests__/session-feedback.store.test.js +0 -39
- package/dist/stores/__tests__/session-feedback.store.test.js.map +0 -1
- package/dist/stores/message-feedback-base.store.d.ts +0 -8
- package/dist/stores/message-feedback-base.store.d.ts.map +0 -1
- package/dist/stores/message-feedback-base.store.js +0 -2
- package/dist/stores/message-feedback-base.store.js.map +0 -1
- package/dist/stores/message-feedback-guardrail.store.d.ts +0 -16
- package/dist/stores/message-feedback-guardrail.store.d.ts.map +0 -1
- package/dist/stores/message-feedback-guardrail.store.js +0 -85
- package/dist/stores/message-feedback-guardrail.store.js.map +0 -1
- package/dist/stores/message-feedback.store.d.ts +0 -23
- package/dist/stores/message-feedback.store.d.ts.map +0 -1
- package/dist/stores/message-feedback.store.js +0 -145
- package/dist/stores/message-feedback.store.js.map +0 -1
- package/dist/stores/session-feedback.store.d.ts +0 -15
- package/dist/stores/session-feedback.store.d.ts.map +0 -1
- package/dist/stores/session-feedback.store.js +0 -75
- package/dist/stores/session-feedback.store.js.map +0 -1
- package/dist/utils/__tests__/axios-utils.test.d.ts +0 -2
- package/dist/utils/__tests__/axios-utils.test.d.ts.map +0 -1
- package/dist/utils/__tests__/axios-utils.test.js +0 -33
- package/dist/utils/__tests__/axios-utils.test.js.map +0 -1
- package/dist/utils/axios-utils.d.ts +0 -5
- package/dist/utils/axios-utils.d.ts.map +0 -1
- package/dist/utils/axios-utils.js +0 -23
- package/dist/utils/axios-utils.js.map +0 -1
- package/dist/utils/test-utils.d.ts +0 -5
- package/dist/utils/test-utils.d.ts.map +0 -1
- package/dist/utils/test-utils.js +0 -17
- package/dist/utils/test-utils.js.map +0 -1
- package/src/stores/__tests__/message-feedback-guardrail.store.test.ts +0 -61
- package/src/stores/__tests__/message-feedback.store.test.ts +0 -121
- package/src/stores/__tests__/session-feedback.store.test.ts +0 -47
- package/src/stores/message-feedback-base.store.ts +0 -8
- package/src/stores/message-feedback-guardrail.store.ts +0 -60
- package/src/stores/message-feedback.store.ts +0 -113
- package/src/stores/session-feedback.store.ts +0 -44
- package/src/utils/__tests__/axios-utils.test.ts +0 -40
- package/src/utils/axios-utils.ts +0 -25
- package/src/utils/test-utils.ts +0 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
# v3.1.1 (Thu Aug 14 2025)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- SPA-7016: [Chatbot] Add Anvil2 support for chatbot NPM packages [#41](https://github.com/servicetitan/titan-chatbot-client/pull/41) ([@AlexYarmolchuk](https://github.com/AlexYarmolchuk))
|
|
6
|
+
|
|
7
|
+
#### Authors: 1
|
|
8
|
+
|
|
9
|
+
- Alexandr Yarmolchuk ([@AlexYarmolchuk](https://github.com/AlexYarmolchuk))
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
1
13
|
# v3.0.1 (Tue Jul 15 2025)
|
|
2
14
|
|
|
3
15
|
#### 🐛 Bug Fix
|
|
@@ -1,160 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Log } from '@servicetitan/log-service';
|
|
3
|
-
import { Container, Provider } from '@servicetitan/react-ioc';
|
|
4
|
-
import { ApiClientHelpCenter, CHATBOT_API_CLIENT, CHATBOT_CLIENT_SETTINGS, CHATBOT_UI_BACKEND_STORE_TOKEN, CHATBOT_UI_STORE_TOKEN, ChatbotUiBackendStore, ChatbotUiStore, Models, } from '@servicetitan/titan-chatbot-api';
|
|
5
|
-
import { ChatUiSelectors, CypressMocks } from '@servicetitan/titan-chatbot-ui-cypress';
|
|
6
|
-
import axios from 'axios';
|
|
7
|
-
import { mount } from 'cypress/react';
|
|
8
|
-
import { useMemo } from 'react';
|
|
1
|
+
import { runChatbotHelpCenterSharedTests } from '@servicetitan/titan-chatbot-ui-cypress';
|
|
9
2
|
import { Chatbot } from '../chatbot';
|
|
10
|
-
const ChatbotBaseUrl = 'https://chatbot-api.example.com/base/url';
|
|
11
|
-
const initContainer = () => {
|
|
12
|
-
const rootContainer = new Container();
|
|
13
|
-
const container = new Container();
|
|
14
|
-
container.parent = rootContainer;
|
|
15
|
-
container.bind(Log).to(CypressMocks.LogMock).inSingletonScope();
|
|
16
|
-
container.bind(CHATBOT_UI_STORE_TOKEN).to(ChatbotUiStore).inSingletonScope();
|
|
17
|
-
container
|
|
18
|
-
.bind(CHATBOT_UI_BACKEND_STORE_TOKEN)
|
|
19
|
-
.to(ChatbotUiBackendStore)
|
|
20
|
-
.inSingletonScope();
|
|
21
|
-
// Set up Helpcenter API client
|
|
22
|
-
const clientSettings = {
|
|
23
|
-
area: 'FloatingChat',
|
|
24
|
-
instance: 'STapp',
|
|
25
|
-
constructorParametersFactory: () => ({
|
|
26
|
-
baseUrl: ChatbotBaseUrl,
|
|
27
|
-
axiosInstance: axios.create(),
|
|
28
|
-
}),
|
|
29
|
-
};
|
|
30
|
-
container
|
|
31
|
-
.bind(CHATBOT_CLIENT_SETTINGS)
|
|
32
|
-
.toConstantValue(clientSettings);
|
|
33
|
-
container
|
|
34
|
-
.bind(CHATBOT_API_CLIENT)
|
|
35
|
-
.to(ApiClientHelpCenter.ChatbotApiClient)
|
|
36
|
-
.inSingletonScope();
|
|
37
|
-
return container;
|
|
38
|
-
};
|
|
39
3
|
describe('[Chatbot with Help Center API]', () => {
|
|
40
|
-
|
|
41
|
-
let log;
|
|
42
|
-
let apiClientSettings;
|
|
43
|
-
let apiClient;
|
|
44
|
-
let uiStore;
|
|
45
|
-
let uiBackendStore;
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
container = initContainer();
|
|
48
|
-
log = container.get(Log);
|
|
49
|
-
apiClientSettings =
|
|
50
|
-
container.get(CHATBOT_CLIENT_SETTINGS);
|
|
51
|
-
apiClient = container.get(CHATBOT_API_CLIENT);
|
|
52
|
-
uiStore = container.get(CHATBOT_UI_STORE_TOKEN);
|
|
53
|
-
uiBackendStore = container.get(CHATBOT_UI_BACKEND_STORE_TOKEN);
|
|
54
|
-
cy.viewport(550, 800);
|
|
55
|
-
cy.clock(Date.parse('2023-10-01T00:00:00Z'));
|
|
56
|
-
});
|
|
57
|
-
const render = () => {
|
|
58
|
-
const ChatbotWrapper = () => {
|
|
59
|
-
const customizationContext = useMemo(() => ({
|
|
60
|
-
filters: { enabled: true },
|
|
61
|
-
feedback: { title: 'TITLE' },
|
|
62
|
-
}), []);
|
|
63
|
-
return (_jsx(Provider, { singletons: [
|
|
64
|
-
{
|
|
65
|
-
provide: Log,
|
|
66
|
-
useValue: log,
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
provide: CHATBOT_CLIENT_SETTINGS,
|
|
70
|
-
useValue: apiClientSettings,
|
|
71
|
-
},
|
|
72
|
-
{ provide: CHATBOT_API_CLIENT, useValue: apiClient },
|
|
73
|
-
{
|
|
74
|
-
provide: CHATBOT_UI_STORE_TOKEN,
|
|
75
|
-
useValue: uiStore,
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
provide: CHATBOT_UI_BACKEND_STORE_TOKEN,
|
|
79
|
-
useValue: uiBackendStore,
|
|
80
|
-
},
|
|
81
|
-
], children: _jsx(Chatbot, { className: "h-100vh max-h-100vh of-x-hidden", customizations: customizationContext }) }));
|
|
82
|
-
};
|
|
83
|
-
cy.spy(uiStore, 'run').as('runSpy');
|
|
84
|
-
mount(_jsx(ChatbotWrapper, {}));
|
|
85
|
-
return cy.wrap(new Promise(resolve => {
|
|
86
|
-
cy.get('@runSpy')
|
|
87
|
-
.should('have.been.calledOnce')
|
|
88
|
-
.then((invocation) => {
|
|
89
|
-
const initPromise = invocation.firstCall.returnValue;
|
|
90
|
-
initPromise.then(resolve);
|
|
91
|
-
});
|
|
92
|
-
}));
|
|
93
|
-
};
|
|
94
|
-
it('should render the chatbot with help center API', () => {
|
|
95
|
-
const sessionMock = CypressMocks.HC.CreateSession;
|
|
96
|
-
const messageMock = CypressMocks.HC.SendUserMessage;
|
|
97
|
-
const messageFeedbackMock = CypressMocks.HC.MessageFeedback;
|
|
98
|
-
const sessionFeedbackMock = CypressMocks.HC.SessionFeedback;
|
|
99
|
-
const aliasFilterOptions = CypressMocks.HC.interceptFilterOptions(ChatbotBaseUrl);
|
|
100
|
-
const aliasCreateSession = sessionMock.intercept(ChatbotBaseUrl);
|
|
101
|
-
const aliasSendUserMessage = messageMock.intercept(ChatbotBaseUrl);
|
|
102
|
-
const aliasMessageFeedback = messageFeedbackMock.intercept(ChatbotBaseUrl);
|
|
103
|
-
const aliasSessionFeedback = sessionFeedbackMock.intercept(ChatbotBaseUrl);
|
|
104
|
-
render().then(() => {
|
|
105
|
-
// Expect filters were loaded using the Help Center API
|
|
106
|
-
cy.wait(aliasFilterOptions).then(interception => {
|
|
107
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
108
|
-
// Check options were loaded correctly
|
|
109
|
-
expect(interception.request.url).to.equal(`${ChatbotBaseUrl}/api/Chat/filter-options`);
|
|
110
|
-
expect((_a = interception.response) === null || _a === void 0 ? void 0 : _a.body).to.an('object');
|
|
111
|
-
expect((_c = (_b = interception.response) === null || _b === void 0 ? void 0 : _b.body) === null || _c === void 0 ? void 0 : _c.sources).to.an('array');
|
|
112
|
-
expect((_e = (_d = interception.response) === null || _d === void 0 ? void 0 : _d.body) === null || _e === void 0 ? void 0 : _e.contentTypes).to.an('array');
|
|
113
|
-
expect((_g = (_f = interception.response) === null || _f === void 0 ? void 0 : _f.body) === null || _g === void 0 ? void 0 : _g.productAreas).to.an('array');
|
|
114
|
-
expect((_h = interception.response) === null || _h === void 0 ? void 0 : _h.statusCode).to.equal(200);
|
|
115
|
-
});
|
|
116
|
-
// Ask the bot a question
|
|
117
|
-
cy.log('Sending message...');
|
|
118
|
-
ChatUiSelectors.chatInput.type(`${messageMock.request.text}{enter}`, { delay: 0 });
|
|
119
|
-
// Check that the session was created
|
|
120
|
-
cy.wait(aliasCreateSession).then(interception => {
|
|
121
|
-
var _a, _b;
|
|
122
|
-
expect(interception.request.url).to.equal(`${ChatbotBaseUrl}/api/Chat/create-session`);
|
|
123
|
-
expect(interception.request.body).to.deep.equal(sessionMock.request);
|
|
124
|
-
expect((_a = interception.response) === null || _a === void 0 ? void 0 : _a.body).to.deep.equal(sessionMock.response);
|
|
125
|
-
expect((_b = interception.response) === null || _b === void 0 ? void 0 : _b.statusCode).to.equal(200);
|
|
126
|
-
});
|
|
127
|
-
// Check the user message is sent
|
|
128
|
-
cy.wait(aliasSendUserMessage).then(interception => {
|
|
129
|
-
var _a, _b;
|
|
130
|
-
expect(interception.request.url).to.equal(`${ChatbotBaseUrl}/api/Chat/user-message`);
|
|
131
|
-
expect(interception.request.body).to.deep.equal(messageMock.request);
|
|
132
|
-
expect((_a = interception.response) === null || _a === void 0 ? void 0 : _a.body).to.deep.equal(messageMock.response);
|
|
133
|
-
expect((_b = interception.response) === null || _b === void 0 ? void 0 : _b.statusCode).to.equal(200);
|
|
134
|
-
});
|
|
135
|
-
// Send session feedback (manually)
|
|
136
|
-
cy.log('Sending session feedback...');
|
|
137
|
-
uiStore.sendSessionFeedback(new Models.Feedback({
|
|
138
|
-
sessionId: sessionMock.response.id,
|
|
139
|
-
description: 'Good answer!',
|
|
140
|
-
rating: Models.FeedbackRatings.ThumbsUp,
|
|
141
|
-
}));
|
|
142
|
-
cy.wait(aliasSessionFeedback).then(interception => {
|
|
143
|
-
var _a;
|
|
144
|
-
expect(interception.request.url).to.equal(`${ChatbotBaseUrl}/api/Chat/session-feedback?sessionId=${sessionMock.response.id}`);
|
|
145
|
-
expect(interception.request.body).to.deep.equal(sessionFeedbackMock.request);
|
|
146
|
-
expect((_a = interception.response) === null || _a === void 0 ? void 0 : _a.statusCode).to.equal(200);
|
|
147
|
-
});
|
|
148
|
-
// Check the feedback is sent with thumbs up
|
|
149
|
-
cy.log('Sending message feedback...');
|
|
150
|
-
ChatUiSelectors.chatbotMessageFeedbackThumbsUp.scrollIntoView().click({ force: true });
|
|
151
|
-
cy.wait(aliasMessageFeedback).then(interception => {
|
|
152
|
-
var _a;
|
|
153
|
-
expect(interception.request.url).to.equal(`${ChatbotBaseUrl}/api/Chat/bot-message-feedback?sessionId=${messageMock.response.sessionId}&botMessageId=${messageMock.response.id}`);
|
|
154
|
-
expect(interception.request.body).to.deep.equal(messageFeedbackMock.request);
|
|
155
|
-
expect((_a = interception.response) === null || _a === void 0 ? void 0 : _a.statusCode).to.equal(200);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
4
|
+
runChatbotHelpCenterSharedTests(Chatbot);
|
|
159
5
|
});
|
|
160
6
|
//# sourceMappingURL=chatbot-help-center.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatbot-help-center.test.js","sourceRoot":"","sources":["../../../../src/components/chatbot/__tests-cy__/chatbot-help-center.test.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chatbot-help-center.test.js","sourceRoot":"","sources":["../../../../src/components/chatbot/__tests-cy__/chatbot-help-center.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,wCAAwC,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC5C,+BAA+B,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC,CAAC,CAAC"}
|
|
@@ -1,101 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Log } from '@servicetitan/log-service';
|
|
3
|
-
import { Container, Provider } from '@servicetitan/react-ioc';
|
|
4
|
-
import { CHATBOT_API_CLIENT, CHATBOT_UI_BACKEND_STORE_TOKEN, CHATBOT_UI_STORE_TOKEN, ChatbotUiBackendStore, ChatbotUiStore, Models, ModelsMocks, } from '@servicetitan/titan-chatbot-api';
|
|
5
|
-
import { ChatUiSelectors, CypressMocks } from '@servicetitan/titan-chatbot-ui-cypress';
|
|
6
|
-
import { mount } from 'cypress/react';
|
|
7
|
-
import { useMemo } from 'react';
|
|
1
|
+
import { runChatbotLiveSharedTests } from '@servicetitan/titan-chatbot-ui-cypress';
|
|
8
2
|
import { Chatbot } from '../chatbot';
|
|
9
|
-
const initContainer = () => {
|
|
10
|
-
const rootContainer = new Container();
|
|
11
|
-
const container = new Container();
|
|
12
|
-
container.parent = rootContainer;
|
|
13
|
-
container.bind(Log).to(CypressMocks.LogMock).inSingletonScope();
|
|
14
|
-
container
|
|
15
|
-
.bind(CHATBOT_API_CLIENT)
|
|
16
|
-
.to(CypressMocks.ChatbotApiClientMock)
|
|
17
|
-
.inSingletonScope();
|
|
18
|
-
container.bind(CHATBOT_UI_STORE_TOKEN).to(ChatbotUiStore).inSingletonScope();
|
|
19
|
-
container
|
|
20
|
-
.bind(CHATBOT_UI_BACKEND_STORE_TOKEN)
|
|
21
|
-
.to(ChatbotUiBackendStore)
|
|
22
|
-
.inSingletonScope();
|
|
23
|
-
return container;
|
|
24
|
-
};
|
|
25
3
|
/**
|
|
26
4
|
* The test is for internal purposes only.
|
|
27
5
|
*/
|
|
28
6
|
describe('[Chatbot]', () => {
|
|
29
|
-
|
|
30
|
-
let log;
|
|
31
|
-
let api;
|
|
32
|
-
let uiStore;
|
|
33
|
-
let uiBackendStore;
|
|
34
|
-
const mockApi = () => {
|
|
35
|
-
api.postSession = cy.stub().resolves(ModelsMocks.mockSession());
|
|
36
|
-
api.getOptions = cy.stub().resolves(ModelsMocks.mockFrontendModel());
|
|
37
|
-
};
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
cy.intercept('GET', 'https://fonts.gstatic.com/**', {
|
|
40
|
-
statusCode: 200,
|
|
41
|
-
body: new ArrayBuffer(0),
|
|
42
|
-
headers: {
|
|
43
|
-
'Content-Type': 'font/woff2',
|
|
44
|
-
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
container = initContainer();
|
|
48
|
-
log = container.get(Log);
|
|
49
|
-
api = container.get(CHATBOT_API_CLIENT);
|
|
50
|
-
uiStore = container.get(CHATBOT_UI_STORE_TOKEN);
|
|
51
|
-
uiBackendStore = container.get(CHATBOT_UI_BACKEND_STORE_TOKEN);
|
|
52
|
-
mockApi();
|
|
53
|
-
cy.viewport(550, 800);
|
|
54
|
-
});
|
|
55
|
-
const mockAskBotApi = (answer) => {
|
|
56
|
-
api.postMessage = cy.stub().as('askBot').resolves(ModelsMocks.mockBotMessage({
|
|
57
|
-
answer,
|
|
58
|
-
}));
|
|
59
|
-
api.postFeedback = cy
|
|
60
|
-
.stub()
|
|
61
|
-
.as('askBotFeedback')
|
|
62
|
-
.resolves(ModelsMocks.mockFeedback({
|
|
63
|
-
rating: Models.FeedbackRatings.ThumbsUp,
|
|
64
|
-
}));
|
|
65
|
-
};
|
|
66
|
-
const render = () => {
|
|
67
|
-
const ChatbotWrapper = () => {
|
|
68
|
-
const customizationContext = useMemo(() => ({
|
|
69
|
-
filters: { enabled: true },
|
|
70
|
-
feedback: { title: 'TITLE' },
|
|
71
|
-
}), []);
|
|
72
|
-
return (_jsx(Provider, { singletons: [
|
|
73
|
-
{
|
|
74
|
-
provide: Log,
|
|
75
|
-
useValue: log,
|
|
76
|
-
},
|
|
77
|
-
{ provide: CHATBOT_API_CLIENT, useValue: api },
|
|
78
|
-
{
|
|
79
|
-
provide: CHATBOT_UI_STORE_TOKEN,
|
|
80
|
-
useValue: uiStore,
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
provide: CHATBOT_UI_BACKEND_STORE_TOKEN,
|
|
84
|
-
useValue: uiBackendStore,
|
|
85
|
-
},
|
|
86
|
-
], children: _jsx(Chatbot, { className: "h-100vh max-h-100vh of-x-hidden", customizations: customizationContext }) }));
|
|
87
|
-
};
|
|
88
|
-
mount(_jsx(ChatbotWrapper, {}));
|
|
89
|
-
};
|
|
90
|
-
const ask = (message) => {
|
|
91
|
-
ChatUiSelectors.chatInput.type(`${message}{enter}`, { delay: 0 });
|
|
92
|
-
};
|
|
93
|
-
it.skip('should render the chatbot component', () => {
|
|
94
|
-
mockAskBotApi("Hello! I'm chatbot mocked response!!!");
|
|
95
|
-
render();
|
|
96
|
-
ask('Hello!');
|
|
97
|
-
ChatUiSelectors.chatbotMessageFeedbackThumbsUp.should('be.visible').click();
|
|
98
|
-
cy.get('@askBotFeedback').should('have.been.calledOnce');
|
|
99
|
-
});
|
|
7
|
+
runChatbotLiveSharedTests(Chatbot);
|
|
100
8
|
});
|
|
101
9
|
//# sourceMappingURL=chatbot-live.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatbot-live.test.js","sourceRoot":"","sources":["../../../../src/components/chatbot/__tests-cy__/chatbot-live.test.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chatbot-live.test.js","sourceRoot":"","sources":["../../../../src/components/chatbot/__tests-cy__/chatbot-live.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC;;GAEG;AACH,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACvB,yBAAyB,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC,CAAC,CAAC"}
|
|
@@ -1,155 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Log } from '@servicetitan/log-service';
|
|
3
|
-
import { Container, Provider } from '@servicetitan/react-ioc';
|
|
4
|
-
import { ApiClientTitanChat, CHATBOT_API_CLIENT, CHATBOT_CLIENT_SETTINGS, CHATBOT_UI_BACKEND_STORE_TOKEN, CHATBOT_UI_STORE_TOKEN, ChatbotUiBackendStore, ChatbotUiStore, Models, } from '@servicetitan/titan-chatbot-api';
|
|
5
|
-
import { ChatUiSelectors, CypressMocks } from '@servicetitan/titan-chatbot-ui-cypress';
|
|
6
|
-
import { mount } from 'cypress/react';
|
|
7
|
-
import { useMemo } from 'react';
|
|
1
|
+
import { runChatbotTitanChatbotSharedTests } from '@servicetitan/titan-chatbot-ui-cypress';
|
|
8
2
|
import { Chatbot } from '../chatbot';
|
|
9
|
-
const ChatbotBaseUrl = 'https://chatbot-api.example.com/base/url';
|
|
10
|
-
const ChatbotVersion = 2;
|
|
11
|
-
const initContainer = () => {
|
|
12
|
-
const rootContainer = new Container();
|
|
13
|
-
const container = new Container();
|
|
14
|
-
container.parent = rootContainer;
|
|
15
|
-
container.bind(Log).to(CypressMocks.LogMock).inSingletonScope();
|
|
16
|
-
container.bind(CHATBOT_UI_STORE_TOKEN).to(ChatbotUiStore).inSingletonScope();
|
|
17
|
-
container
|
|
18
|
-
.bind(CHATBOT_UI_BACKEND_STORE_TOKEN)
|
|
19
|
-
.to(ChatbotUiBackendStore)
|
|
20
|
-
.inSingletonScope();
|
|
21
|
-
// Set up Helpcenter API client
|
|
22
|
-
const clientSettings = {
|
|
23
|
-
clientId: 'TitanChatClientId',
|
|
24
|
-
version: String(ChatbotVersion),
|
|
25
|
-
constructorParametersFactory: () => ({
|
|
26
|
-
baseUrl: ChatbotBaseUrl,
|
|
27
|
-
}),
|
|
28
|
-
};
|
|
29
|
-
container
|
|
30
|
-
.bind(CHATBOT_CLIENT_SETTINGS)
|
|
31
|
-
.toConstantValue(clientSettings);
|
|
32
|
-
container
|
|
33
|
-
.bind(CHATBOT_API_CLIENT)
|
|
34
|
-
.to(ApiClientTitanChat.ChatbotApiClient)
|
|
35
|
-
.inSingletonScope();
|
|
36
|
-
return container;
|
|
37
|
-
};
|
|
38
3
|
describe('[Chatbot with Titan Chat API]', () => {
|
|
39
|
-
|
|
40
|
-
let log;
|
|
41
|
-
let apiClientSettings;
|
|
42
|
-
let apiClient;
|
|
43
|
-
let uiStore;
|
|
44
|
-
let uiBackendStore;
|
|
45
|
-
beforeEach(() => {
|
|
46
|
-
container = initContainer();
|
|
47
|
-
log = container.get(Log);
|
|
48
|
-
apiClientSettings =
|
|
49
|
-
container.get(CHATBOT_CLIENT_SETTINGS);
|
|
50
|
-
apiClient = container.get(CHATBOT_API_CLIENT);
|
|
51
|
-
uiStore = container.get(CHATBOT_UI_STORE_TOKEN);
|
|
52
|
-
uiBackendStore = container.get(CHATBOT_UI_BACKEND_STORE_TOKEN);
|
|
53
|
-
cy.viewport(550, 800);
|
|
54
|
-
cy.clock(Date.parse('2023-10-01T00:00:00Z'));
|
|
55
|
-
});
|
|
56
|
-
const render = () => {
|
|
57
|
-
const ChatbotWrapper = () => {
|
|
58
|
-
const customizationContext = useMemo(() => ({
|
|
59
|
-
filters: { enabled: true },
|
|
60
|
-
feedback: { title: 'TITLE' },
|
|
61
|
-
}), []);
|
|
62
|
-
return (_jsx(Provider, { singletons: [
|
|
63
|
-
{
|
|
64
|
-
provide: Log,
|
|
65
|
-
useValue: log,
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
provide: CHATBOT_CLIENT_SETTINGS,
|
|
69
|
-
useValue: apiClientSettings,
|
|
70
|
-
},
|
|
71
|
-
{ provide: CHATBOT_API_CLIENT, useValue: apiClient },
|
|
72
|
-
{
|
|
73
|
-
provide: CHATBOT_UI_STORE_TOKEN,
|
|
74
|
-
useValue: uiStore,
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
provide: CHATBOT_UI_BACKEND_STORE_TOKEN,
|
|
78
|
-
useValue: uiBackendStore,
|
|
79
|
-
},
|
|
80
|
-
], children: _jsx(Chatbot, { className: "h-100vh max-h-100vh of-x-hidden", customizations: customizationContext }) }));
|
|
81
|
-
};
|
|
82
|
-
cy.spy(uiStore, 'run').as('runSpy');
|
|
83
|
-
mount(_jsx(ChatbotWrapper, {}));
|
|
84
|
-
return cy.wrap(new Promise(resolve => {
|
|
85
|
-
cy.get('@runSpy')
|
|
86
|
-
.should('have.been.calledOnce')
|
|
87
|
-
.then((invocation) => {
|
|
88
|
-
const initPromise = invocation.firstCall.returnValue;
|
|
89
|
-
initPromise.then(resolve);
|
|
90
|
-
});
|
|
91
|
-
}));
|
|
92
|
-
};
|
|
93
|
-
it('should render the chatbot with titan chat API', () => {
|
|
94
|
-
const optionsMock = CypressMocks.TC.Options;
|
|
95
|
-
const sessionMock = CypressMocks.TC.SessionPost;
|
|
96
|
-
const messageMock = CypressMocks.TC.MessagePost;
|
|
97
|
-
const messageFeedbackMock = CypressMocks.TC.MessageFeedbackPost;
|
|
98
|
-
const sessionFeedbackMock = CypressMocks.TC.SessionFeedbackPost;
|
|
99
|
-
const aliasOptions = optionsMock.intercept(ChatbotBaseUrl, ChatbotVersion);
|
|
100
|
-
const aliasSession = sessionMock.intercept(ChatbotBaseUrl, ChatbotVersion);
|
|
101
|
-
const aliasMessage = messageMock.intercept(ChatbotBaseUrl, ChatbotVersion);
|
|
102
|
-
const { aliasPostMessage, aliasPostSession } = CypressMocks.TC.interceptFeedback(ChatbotBaseUrl, ChatbotVersion);
|
|
103
|
-
render().then(() => {
|
|
104
|
-
cy.log('Getting options...');
|
|
105
|
-
cy.wait(aliasOptions).then(interception => {
|
|
106
|
-
var _a, _b;
|
|
107
|
-
expect(interception.request.url).to.equal(`${ChatbotBaseUrl}/api/v${ChatbotVersion}/options`);
|
|
108
|
-
expect((_a = interception.response) === null || _a === void 0 ? void 0 : _a.statusCode).to.equal(200);
|
|
109
|
-
expect((_b = interception.response) === null || _b === void 0 ? void 0 : _b.body).to.deep.equal(optionsMock.response);
|
|
110
|
-
});
|
|
111
|
-
// Ask the bot a question
|
|
112
|
-
cy.log('Sending message...');
|
|
113
|
-
ChatUiSelectors.chatInput.type(`${messageMock.request.question}{enter}`, { delay: 0 });
|
|
114
|
-
// Check that the session was created
|
|
115
|
-
cy.wait(aliasSession).then(interception => {
|
|
116
|
-
var _a, _b;
|
|
117
|
-
expect(interception.request.url).to.equal(`${ChatbotBaseUrl}/api/v${ChatbotVersion}/session`);
|
|
118
|
-
expect(interception.request.body).to.deep.equal(sessionMock.request);
|
|
119
|
-
expect((_a = interception.response) === null || _a === void 0 ? void 0 : _a.body).to.deep.equal(sessionMock.response);
|
|
120
|
-
expect((_b = interception.response) === null || _b === void 0 ? void 0 : _b.statusCode).to.equal(200);
|
|
121
|
-
});
|
|
122
|
-
// Check the user message is sent
|
|
123
|
-
cy.wait(aliasMessage).then(interception => {
|
|
124
|
-
var _a, _b;
|
|
125
|
-
expect(interception.request.url).to.equal(`${ChatbotBaseUrl}/api/v${ChatbotVersion}/message`);
|
|
126
|
-
expect(interception.request.body).to.deep.equal(messageMock.request);
|
|
127
|
-
expect((_a = interception.response) === null || _a === void 0 ? void 0 : _a.body).to.deep.equal(messageMock.response);
|
|
128
|
-
expect((_b = interception.response) === null || _b === void 0 ? void 0 : _b.statusCode).to.equal(200);
|
|
129
|
-
});
|
|
130
|
-
cy.tick(100);
|
|
131
|
-
// Send session feedback (manually)
|
|
132
|
-
cy.log('Sending session feedback...');
|
|
133
|
-
uiStore.sendSessionFeedback(new Models.Feedback(sessionFeedbackMock.request));
|
|
134
|
-
cy.wait(aliasPostSession).then(interception => {
|
|
135
|
-
var _a, _b;
|
|
136
|
-
expect(interception.request.url).to.equal(`${ChatbotBaseUrl}/api/v${ChatbotVersion}/feedback`);
|
|
137
|
-
expect(interception.request.body).to.deep.equal(sessionFeedbackMock.request);
|
|
138
|
-
expect((_a = interception.response) === null || _a === void 0 ? void 0 : _a.body).to.deep.equal(sessionFeedbackMock.response);
|
|
139
|
-
expect((_b = interception.response) === null || _b === void 0 ? void 0 : _b.statusCode).to.equal(200);
|
|
140
|
-
});
|
|
141
|
-
cy.tick(100);
|
|
142
|
-
// Check the feedback is sent with thumbs up
|
|
143
|
-
cy.log('Sending message feedback...');
|
|
144
|
-
ChatUiSelectors.chatbotMessageFeedbackThumbsUp.scrollIntoView().click({ force: true });
|
|
145
|
-
cy.wait(aliasPostMessage).then(interception => {
|
|
146
|
-
var _a, _b;
|
|
147
|
-
expect(interception.request.url).to.equal(`${ChatbotBaseUrl}/api/v${ChatbotVersion}/feedback`);
|
|
148
|
-
expect(interception.request.body).to.deep.equal(messageFeedbackMock.request);
|
|
149
|
-
expect((_a = interception.response) === null || _a === void 0 ? void 0 : _a.body).to.deep.equal(messageFeedbackMock.response);
|
|
150
|
-
expect((_b = interception.response) === null || _b === void 0 ? void 0 : _b.statusCode).to.equal(200);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
});
|
|
4
|
+
runChatbotTitanChatbotSharedTests(Chatbot);
|
|
154
5
|
});
|
|
155
6
|
//# sourceMappingURL=chatbot-titan-chatbot.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatbot-titan-chatbot.test.js","sourceRoot":"","sources":["../../../../src/components/chatbot/__tests-cy__/chatbot-titan-chatbot.test.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chatbot-titan-chatbot.test.js","sourceRoot":"","sources":["../../../../src/components/chatbot/__tests-cy__/chatbot-titan-chatbot.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC3C,iCAAiC,CAAC,OAAO,CAAC,CAAC;AAC/C,CAAC,CAAC,CAAC"}
|
|
@@ -1,155 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Log } from '@servicetitan/log-service';
|
|
3
|
-
import { Container, Provider } from '@servicetitan/react-ioc';
|
|
4
|
-
import { CHATBOT_API_CLIENT, CHATBOT_UI_BACKEND_STORE_TOKEN, CHATBOT_UI_STORE_TOKEN, ChatbotUiBackendStore, ChatbotUiStore, Models, ModelsMocks, } from '@servicetitan/titan-chatbot-api';
|
|
5
|
-
import { ChatUiSelectors, CypressMocks } from '@servicetitan/titan-chatbot-ui-cypress';
|
|
6
|
-
import { mount } from 'cypress/react';
|
|
7
|
-
import { useMemo } from 'react';
|
|
1
|
+
import { runChatbotSharedTests } from '@servicetitan/titan-chatbot-ui-cypress';
|
|
8
2
|
import { Chatbot } from '../chatbot';
|
|
9
|
-
const initContainer = () => {
|
|
10
|
-
const rootContainer = new Container();
|
|
11
|
-
const container = new Container();
|
|
12
|
-
container.parent = rootContainer;
|
|
13
|
-
container.bind(Log).to(CypressMocks.LogMock).inSingletonScope();
|
|
14
|
-
container
|
|
15
|
-
.bind(CHATBOT_API_CLIENT)
|
|
16
|
-
.to(CypressMocks.ChatbotApiClientMock)
|
|
17
|
-
.inSingletonScope();
|
|
18
|
-
container.bind(CHATBOT_UI_STORE_TOKEN).to(ChatbotUiStore).inSingletonScope();
|
|
19
|
-
container
|
|
20
|
-
.bind(CHATBOT_UI_BACKEND_STORE_TOKEN)
|
|
21
|
-
.to(ChatbotUiBackendStore)
|
|
22
|
-
.inSingletonScope();
|
|
23
|
-
return container;
|
|
24
|
-
};
|
|
25
3
|
describe('[Chatbot]', () => {
|
|
26
|
-
|
|
27
|
-
let log;
|
|
28
|
-
let api;
|
|
29
|
-
let uiStore;
|
|
30
|
-
let uiBackendStore;
|
|
31
|
-
const mockApi = () => {
|
|
32
|
-
api.postSession = cy.stub().resolves(ModelsMocks.mockSession());
|
|
33
|
-
api.getOptions = cy.stub().resolves(ModelsMocks.mockFrontendModel());
|
|
34
|
-
};
|
|
35
|
-
beforeEach(() => {
|
|
36
|
-
container = initContainer();
|
|
37
|
-
log = container.get(Log);
|
|
38
|
-
api = container.get(CHATBOT_API_CLIENT);
|
|
39
|
-
uiStore = container.get(CHATBOT_UI_STORE_TOKEN);
|
|
40
|
-
uiBackendStore = container.get(CHATBOT_UI_BACKEND_STORE_TOKEN);
|
|
41
|
-
mockApi();
|
|
42
|
-
cy.viewport(550, 800);
|
|
43
|
-
cy.clock(Date.parse('2023-10-01T00:00:00Z'));
|
|
44
|
-
});
|
|
45
|
-
const mockAskBotApi = (answer) => {
|
|
46
|
-
api.postMessage = cy.stub().as('askBot').resolves(ModelsMocks.mockBotMessage({
|
|
47
|
-
answer,
|
|
48
|
-
}));
|
|
49
|
-
api.postFeedback = cy
|
|
50
|
-
.stub()
|
|
51
|
-
.as('askBotFeedback')
|
|
52
|
-
.resolves(ModelsMocks.mockFeedback({
|
|
53
|
-
rating: Models.FeedbackRatings.ThumbsUp,
|
|
54
|
-
}));
|
|
55
|
-
};
|
|
56
|
-
const render = () => {
|
|
57
|
-
const ChatbotWrapper = () => {
|
|
58
|
-
const customizationContext = useMemo(() => ({
|
|
59
|
-
filters: { enabled: true },
|
|
60
|
-
feedback: { title: 'TITLE' },
|
|
61
|
-
}), []);
|
|
62
|
-
return (_jsx(Provider, { singletons: [
|
|
63
|
-
{
|
|
64
|
-
provide: Log,
|
|
65
|
-
useValue: log,
|
|
66
|
-
},
|
|
67
|
-
{ provide: CHATBOT_API_CLIENT, useValue: api },
|
|
68
|
-
{
|
|
69
|
-
provide: CHATBOT_UI_STORE_TOKEN,
|
|
70
|
-
useValue: uiStore,
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
provide: CHATBOT_UI_BACKEND_STORE_TOKEN,
|
|
74
|
-
useValue: uiBackendStore,
|
|
75
|
-
},
|
|
76
|
-
], children: _jsx(Chatbot, { className: "h-100vh max-h-100vh of-x-hidden", customizations: customizationContext }) }));
|
|
77
|
-
};
|
|
78
|
-
cy.spy(uiStore, 'run').as('runSpy');
|
|
79
|
-
mount(_jsx(ChatbotWrapper, {}));
|
|
80
|
-
return cy.wrap(new Promise(resolve => {
|
|
81
|
-
cy.get('@runSpy')
|
|
82
|
-
.should('have.been.calledOnce')
|
|
83
|
-
.then((invocation) => {
|
|
84
|
-
const initPromise = invocation.firstCall.returnValue;
|
|
85
|
-
initPromise.then(resolve);
|
|
86
|
-
});
|
|
87
|
-
}));
|
|
88
|
-
};
|
|
89
|
-
const ask = (message) => {
|
|
90
|
-
ChatUiSelectors.chatInput.type(`${message}{enter}`, { delay: 0 });
|
|
91
|
-
};
|
|
92
|
-
const triggerFile = () => {
|
|
93
|
-
uiStore.setFilePickerEnabled(true);
|
|
94
|
-
ChatUiSelectors.chatUploadFile.should('be.visible');
|
|
95
|
-
};
|
|
96
|
-
it('should render the chatbot component', () => {
|
|
97
|
-
mockAskBotApi("Hello! I'm chatbot mocked response!!!");
|
|
98
|
-
render().then(() => {
|
|
99
|
-
// Pick filter
|
|
100
|
-
ChatUiSelectors.chatbotFilterButton.first().click();
|
|
101
|
-
ChatUiSelectors.chatbotFilterOptions.find('label').first().click();
|
|
102
|
-
ChatUiSelectors.chatbotFilterButton.first().click();
|
|
103
|
-
// Ask chatbot
|
|
104
|
-
ask('Hello, Chatbot!');
|
|
105
|
-
ask('Hello, Chatbot! Hello, Chatbot! Hello, Chatbot! Hello, Chatbot! Hello, Chatbot!');
|
|
106
|
-
triggerFile();
|
|
107
|
-
// Check if the message is sent
|
|
108
|
-
cy.get('@askBot').should('have.been.calledTwice');
|
|
109
|
-
cy.tick(1000);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
describe('with error handling', () => {
|
|
113
|
-
const mockAskBotApiError = (errorMessage) => {
|
|
114
|
-
api.postMessage = cy.stub().as('askBot').rejects(new Error(errorMessage));
|
|
115
|
-
};
|
|
116
|
-
it('should react on send message API error', () => {
|
|
117
|
-
mockAskBotApiError('Chatbot API error');
|
|
118
|
-
render()
|
|
119
|
-
.then(() => {
|
|
120
|
-
ask('Hello, Chatbot!');
|
|
121
|
-
ChatUiSelectors.chatMessageFooter
|
|
122
|
-
.last()
|
|
123
|
-
.should('be.visible')
|
|
124
|
-
.should('contain.text', 'Message not delivered. Retry');
|
|
125
|
-
const errorBanner = ChatUiSelectors.chatError.should('be.visible');
|
|
126
|
-
errorBanner
|
|
127
|
-
.find('.Banner__text > .Banner__title')
|
|
128
|
-
.should('contain.text', 'Chat Error');
|
|
129
|
-
ChatUiSelectors.chatErrorText
|
|
130
|
-
.should('be.visible')
|
|
131
|
-
.should('contain.text', 'Failed to send message');
|
|
132
|
-
})
|
|
133
|
-
.then(() => {
|
|
134
|
-
mockAskBotApi("Hello! I'm chatbot mocked response!!!");
|
|
135
|
-
ChatUiSelectors.chatMessageErrorRetry.click();
|
|
136
|
-
ChatUiSelectors.chatMessageContentAgent
|
|
137
|
-
.should('be.visible')
|
|
138
|
-
.should('contain.text', "Hello! I'm chatbot mocked response!!!");
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
describe('with message feedback', () => {
|
|
143
|
-
it('should render the chatbot component', () => {
|
|
144
|
-
mockAskBotApi("Hello! I'm chatbot mocked response!!!");
|
|
145
|
-
render();
|
|
146
|
-
ask('Hello!');
|
|
147
|
-
ChatUiSelectors.chatbotMessageFeedbackThumbsUp.should('be.visible').click();
|
|
148
|
-
cy.get('@askBotFeedback').should('have.been.calledOnce');
|
|
149
|
-
ChatUiSelectors.chatbotMessageFeedbackSuccess
|
|
150
|
-
.should('be.visible')
|
|
151
|
-
.should('contain.text', 'Thanks for your feedback.');
|
|
152
|
-
});
|
|
153
|
-
});
|
|
4
|
+
runChatbotSharedTests(Chatbot);
|
|
154
5
|
});
|
|
155
6
|
//# sourceMappingURL=chatbot.test.js.map
|