@servicetitan/titan-chatbot-ui-cypress 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/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/tests/index.d.ts +30 -0
- package/dist/tests/index.d.ts.map +1 -0
- package/dist/tests/index.js +30 -0
- package/dist/tests/index.js.map +1 -0
- package/dist/tests/titan-chat-ui/chat-error.shared-tests.d.ts +3 -0
- package/dist/tests/titan-chat-ui/chat-error.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chat-ui/chat-error.shared-tests.js +138 -0
- package/dist/tests/titan-chat-ui/chat-error.shared-tests.js.map +1 -0
- package/dist/tests/titan-chat-ui/chat-input-file.shared-tests.d.ts +7 -0
- package/dist/tests/titan-chat-ui/chat-input-file.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chat-ui/chat-input-file.shared-tests.js +123 -0
- package/dist/tests/titan-chat-ui/chat-input-file.shared-tests.js.map +1 -0
- package/dist/tests/titan-chat-ui/chat-input.shared-tests.d.ts +3 -0
- package/dist/tests/titan-chat-ui/chat-input.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chat-ui/chat-input.shared-tests.js +71 -0
- package/dist/tests/titan-chat-ui/chat-input.shared-tests.js.map +1 -0
- package/dist/tests/titan-chat-ui/chat-log.shared-tests.d.ts +9 -0
- package/dist/tests/titan-chat-ui/chat-log.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chat-ui/chat-log.shared-tests.js +73 -0
- package/dist/tests/titan-chat-ui/chat-log.shared-tests.js.map +1 -0
- package/dist/tests/titan-chat-ui/chat-messages.shared-tests.d.ts +8 -0
- package/dist/tests/titan-chat-ui/chat-messages.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chat-ui/chat-messages.shared-tests.js +118 -0
- package/dist/tests/titan-chat-ui/chat-messages.shared-tests.js.map +1 -0
- package/dist/tests/titan-chat-ui/chat-notifications.shared-tests.d.ts +3 -0
- package/dist/tests/titan-chat-ui/chat-notifications.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chat-ui/chat-notifications.shared-tests.js +110 -0
- package/dist/tests/titan-chat-ui/chat-notifications.shared-tests.js.map +1 -0
- package/dist/tests/titan-chat-ui/chat-timer.shared-tests.d.ts +3 -0
- package/dist/tests/titan-chat-ui/chat-timer.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chat-ui/chat-timer.shared-tests.js +76 -0
- package/dist/tests/titan-chat-ui/chat-timer.shared-tests.js.map +1 -0
- package/dist/tests/titan-chat-ui/chat.shared-tests.d.ts +9 -0
- package/dist/tests/titan-chat-ui/chat.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chat-ui/chat.shared-tests.js +111 -0
- package/dist/tests/titan-chat-ui/chat.shared-tests.js.map +1 -0
- package/dist/tests/titan-chat-ui/message-agent.shared-tests.d.ts +27 -0
- package/dist/tests/titan-chat-ui/message-agent.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chat-ui/message-agent.shared-tests.js +67 -0
- package/dist/tests/titan-chat-ui/message-agent.shared-tests.js.map +1 -0
- package/dist/tests/titan-chat-ui/message-content-file.shared-tests.d.ts +10 -0
- package/dist/tests/titan-chat-ui/message-content-file.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chat-ui/message-content-file.shared-tests.js +88 -0
- package/dist/tests/titan-chat-ui/message-content-file.shared-tests.js.map +1 -0
- package/dist/tests/titan-chat-ui/message-system.shared-tests.d.ts +16 -0
- package/dist/tests/titan-chat-ui/message-system.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chat-ui/message-system.shared-tests.js +65 -0
- package/dist/tests/titan-chat-ui/message-system.shared-tests.js.map +1 -0
- package/dist/tests/titan-chat-ui/message-timeout.shared-tests.d.ts +8 -0
- package/dist/tests/titan-chat-ui/message-timeout.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chat-ui/message-timeout.shared-tests.js +63 -0
- package/dist/tests/titan-chat-ui/message-timeout.shared-tests.js.map +1 -0
- package/dist/tests/titan-chat-ui/message-typing.shared-tests.d.ts +12 -0
- package/dist/tests/titan-chat-ui/message-typing.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chat-ui/message-typing.shared-tests.js +46 -0
- package/dist/tests/titan-chat-ui/message-typing.shared-tests.js.map +1 -0
- package/dist/tests/titan-chat-ui/message-user.shared-tests.d.ts +10 -0
- package/dist/tests/titan-chat-ui/message-user.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chat-ui/message-user.shared-tests.js +64 -0
- package/dist/tests/titan-chat-ui/message-user.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-filters.shared-tests.d.ts +7 -0
- package/dist/tests/titan-chatbot-ui/chatbot-filters.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-filters.shared-tests.js +118 -0
- package/dist/tests/titan-chatbot-ui/chatbot-filters.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.d.ts +9 -0
- package/dist/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.js +162 -0
- package/dist/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-links.shared-tests.d.ts +15 -0
- package/dist/tests/titan-chatbot-ui/chatbot-links.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-links.shared-tests.js +123 -0
- package/dist/tests/titan-chatbot-ui/chatbot-links.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-live.shared-tests.d.ts +9 -0
- package/dist/tests/titan-chatbot-ui/chatbot-live.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-live.shared-tests.js +84 -0
- package/dist/tests/titan-chatbot-ui/chatbot-live.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.d.ts +8 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.js +142 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.d.ts +8 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.js +105 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.d.ts +3 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.js +86 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.d.ts +3 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.js +143 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.d.ts +8 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.js +200 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.d.ts +11 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.js +81 -0
- package/dist/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.d.ts +8 -0
- package/dist/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.js +60 -0
- package/dist/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.d.ts +8 -0
- package/dist/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.js +77 -0
- package/dist/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.d.ts +7 -0
- package/dist/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.js +130 -0
- package/dist/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.d.ts +9 -0
- package/dist/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.js +157 -0
- package/dist/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.js.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot.shared-tests.d.ts +9 -0
- package/dist/tests/titan-chatbot-ui/chatbot.shared-tests.d.ts.map +1 -0
- package/dist/tests/titan-chatbot-ui/chatbot.shared-tests.js +114 -0
- package/dist/tests/titan-chatbot-ui/chatbot.shared-tests.js.map +1 -0
- package/dist/utils/chat-ui-selectors.d.ts +12 -0
- package/dist/utils/chat-ui-selectors.d.ts.map +1 -1
- package/dist/utils/chat-ui-selectors.js +24 -0
- package/dist/utils/chat-ui-selectors.js.map +1 -1
- package/dist/utils/test-utils-chatbot.d.ts +5 -0
- package/dist/utils/test-utils-chatbot.d.ts.map +1 -0
- package/dist/utils/test-utils-chatbot.js +55 -0
- package/dist/utils/test-utils-chatbot.js.map +1 -0
- package/dist/utils/test-utils.d.ts +6 -0
- package/dist/utils/test-utils.d.ts.map +1 -0
- package/dist/utils/test-utils.js +38 -0
- package/dist/utils/test-utils.js.map +1 -0
- package/package.json +10 -5
- package/src/index.ts +3 -0
- package/src/tests/index.ts +30 -0
- package/src/tests/titan-chat-ui/chat-error.shared-tests.tsx +185 -0
- package/src/tests/titan-chat-ui/chat-input-file.shared-tests.tsx +182 -0
- package/src/tests/titan-chat-ui/chat-input.shared-tests.tsx +99 -0
- package/src/tests/titan-chat-ui/chat-log.shared-tests.tsx +117 -0
- package/src/tests/titan-chat-ui/chat-messages.shared-tests.tsx +156 -0
- package/src/tests/titan-chat-ui/chat-notifications.shared-tests.tsx +153 -0
- package/src/tests/titan-chat-ui/chat-timer.shared-tests.tsx +106 -0
- package/src/tests/titan-chat-ui/chat.shared-tests.tsx +158 -0
- package/src/tests/titan-chat-ui/message-agent.shared-tests.tsx +170 -0
- package/src/tests/titan-chat-ui/message-content-file.shared-tests.tsx +139 -0
- package/src/tests/titan-chat-ui/message-system.shared-tests.tsx +147 -0
- package/src/tests/titan-chat-ui/message-timeout.shared-tests.tsx +117 -0
- package/src/tests/titan-chat-ui/message-typing.shared-tests.tsx +92 -0
- package/src/tests/titan-chat-ui/message-user.shared-tests.tsx +138 -0
- package/src/tests/titan-chatbot-ui/chatbot-filters.shared-tests.tsx +164 -0
- package/src/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.tsx +225 -0
- package/src/tests/titan-chatbot-ui/chatbot-links.shared-tests.tsx +189 -0
- package/src/tests/titan-chatbot-ui/chatbot-live.shared-tests.tsx +127 -0
- package/src/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.tsx +187 -0
- package/src/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.tsx +144 -0
- package/src/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.tsx +127 -0
- package/src/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.tsx +198 -0
- package/src/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.tsx +285 -0
- package/src/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.tsx +112 -0
- package/src/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.tsx +91 -0
- package/src/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.tsx +116 -0
- package/src/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.tsx +182 -0
- package/src/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.tsx +221 -0
- package/src/tests/titan-chatbot-ui/chatbot.shared-tests.tsx +158 -0
- package/src/utils/chat-ui-selectors.ts +24 -0
- package/src/utils/test-utils-chatbot.tsx +73 -0
- package/src/utils/test-utils.tsx +52 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Container } from '@servicetitan/react-ioc';
|
|
2
|
+
import { ChatParticipantIcon } from '@servicetitan/titan-chat-ui-common';
|
|
3
|
+
import { CHATBOT_API_CLIENT, ModelsMocks } from '@servicetitan/titan-chatbot-api';
|
|
4
|
+
import { FC, ReactElement } from 'react';
|
|
5
|
+
import { CypressMocks, testInitContainerChatbot, testRenderWrapperChatbot } from '../..';
|
|
6
|
+
import { ChatUiSelectors } from '../../utils/chat-ui-selectors';
|
|
7
|
+
|
|
8
|
+
interface IChatbotMessageTypingProps {
|
|
9
|
+
avatar: {
|
|
10
|
+
name: string;
|
|
11
|
+
icon: ChatParticipantIcon;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function runChatbotMessageTypingSharedTests(
|
|
16
|
+
ChatbotMessageTypingComponent: FC<IChatbotMessageTypingProps>,
|
|
17
|
+
wrapperComponent?: (component: ReactElement) => ReactElement
|
|
18
|
+
) {
|
|
19
|
+
let container: Container;
|
|
20
|
+
let api: CypressMocks.ChatbotApiClientMock;
|
|
21
|
+
|
|
22
|
+
const mockApiClient = () => {
|
|
23
|
+
api.postSession = cy.stub().resolves(ModelsMocks.mockSession());
|
|
24
|
+
api.getOptions = cy.stub().resolves(ModelsMocks.mockFrontendModel());
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
container = testInitContainerChatbot();
|
|
29
|
+
api = container.get<CypressMocks.ChatbotApiClientMock>(CHATBOT_API_CLIENT);
|
|
30
|
+
mockApiClient();
|
|
31
|
+
cy.viewport(550, 800);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const render = (icon: ChatParticipantIcon, onAfterInit?: () => void) => {
|
|
35
|
+
const avatar = {
|
|
36
|
+
name: 'Test User Name',
|
|
37
|
+
icon,
|
|
38
|
+
};
|
|
39
|
+
return cy.wrap(null).then(() => {
|
|
40
|
+
const component = <ChatbotMessageTypingComponent avatar={avatar} />;
|
|
41
|
+
const wrappedComponent = wrapperComponent ? wrapperComponent(component) : component;
|
|
42
|
+
|
|
43
|
+
return testRenderWrapperChatbot(container, wrappedComponent, onAfterInit);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
it('should render message with bot icon', () => {
|
|
48
|
+
render(ChatParticipantIcon.Bot);
|
|
49
|
+
ChatUiSelectors.chatMessageTyping.should('be.visible');
|
|
50
|
+
ChatUiSelectors.chatMessageTypingDots.should('be.visible');
|
|
51
|
+
ChatUiSelectors.chatAvatarBot
|
|
52
|
+
.should('be.visible')
|
|
53
|
+
.invoke('css', 'background-image')
|
|
54
|
+
.then(bgColor => {
|
|
55
|
+
const isSvg = Boolean(
|
|
56
|
+
(bgColor as any as string).indexOf('data:image/svg+xml;base64') >= 0
|
|
57
|
+
);
|
|
58
|
+
expect(isSvg).to.eq(true);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should render message with empty icon', () => {
|
|
63
|
+
render(ChatParticipantIcon.Empty);
|
|
64
|
+
ChatUiSelectors.chatMessageTyping.should('be.visible');
|
|
65
|
+
ChatUiSelectors.chatMessageTypingDots.should('be.visible');
|
|
66
|
+
ChatUiSelectors.chatAvatarBot.should('not.exist');
|
|
67
|
+
ChatUiSelectors.chatAvatarInitials.should('not.exist');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should render message with initials', () => {
|
|
71
|
+
render(ChatParticipantIcon.Initials);
|
|
72
|
+
ChatUiSelectors.chatMessageTyping.should('be.visible');
|
|
73
|
+
ChatUiSelectors.chatMessageTypingDots.should('be.visible');
|
|
74
|
+
ChatUiSelectors.chatAvatarInitials.should('be.visible').should('contain.text', 'TU');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should show different messages during the time', () => {
|
|
78
|
+
cy.clock(Date.parse('2023-10-01T00:00:00Z'));
|
|
79
|
+
render(ChatParticipantIcon.Bot);
|
|
80
|
+
|
|
81
|
+
// Verify the rendered component shows typing dots initially
|
|
82
|
+
ChatUiSelectors.chatMessageTyping.should('be.visible');
|
|
83
|
+
ChatUiSelectors.chatMessageTypingDots.should('be.visible');
|
|
84
|
+
|
|
85
|
+
// After 10 seconds, should show first message
|
|
86
|
+
cy.tick(10000);
|
|
87
|
+
ChatUiSelectors.chatMessageContentAgent
|
|
88
|
+
.should('be.visible')
|
|
89
|
+
.should('contain.text', 'Looking for the final details');
|
|
90
|
+
ChatUiSelectors.chatMessageTypingDots.should('not.exist');
|
|
91
|
+
|
|
92
|
+
// After 20 seconds total, should show second message
|
|
93
|
+
cy.tick(10000);
|
|
94
|
+
ChatUiSelectors.chatMessageContentAgent
|
|
95
|
+
.should('be.visible')
|
|
96
|
+
.should(
|
|
97
|
+
'contain.text',
|
|
98
|
+
'This is taking longer than usual, please give me a little bit more time'
|
|
99
|
+
);
|
|
100
|
+
ChatUiSelectors.chatMessageTypingDots.should('not.exist');
|
|
101
|
+
|
|
102
|
+
// After additional time, should still show the same message
|
|
103
|
+
cy.tick(60000);
|
|
104
|
+
ChatUiSelectors.chatMessageContentAgent
|
|
105
|
+
.should('be.visible')
|
|
106
|
+
.should(
|
|
107
|
+
'contain.text',
|
|
108
|
+
'This is taking longer than usual, please give me a little bit more time'
|
|
109
|
+
);
|
|
110
|
+
ChatUiSelectors.chatMessageTypingDots.should('not.exist');
|
|
111
|
+
});
|
|
112
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Container } from '@servicetitan/react-ioc';
|
|
2
|
+
import {
|
|
3
|
+
CHATBOT_API_CLIENT,
|
|
4
|
+
CHATBOT_UI_STORE_TOKEN,
|
|
5
|
+
ChatbotUiStore,
|
|
6
|
+
IChatbotUiStore,
|
|
7
|
+
ModelsMocks,
|
|
8
|
+
} from '@servicetitan/titan-chatbot-api';
|
|
9
|
+
import { FC, ReactElement } from 'react';
|
|
10
|
+
import { CypressMocks } from '../..';
|
|
11
|
+
import { ChatUiSelectors } from '../../utils/chat-ui-selectors';
|
|
12
|
+
import { testInitContainerChatbot, testRenderWrapperChatbot } from '../../utils/test-utils-chatbot';
|
|
13
|
+
|
|
14
|
+
interface IChatbotRestartDialogProps {
|
|
15
|
+
confirmText: string;
|
|
16
|
+
onClose: () => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function runChatbotRestartDialogSharedTests(
|
|
20
|
+
ChatbotRestartDialogComponent: FC<IChatbotRestartDialogProps>,
|
|
21
|
+
wrapperComponent?: (component: ReactElement) => ReactElement
|
|
22
|
+
) {
|
|
23
|
+
let container: Container;
|
|
24
|
+
let api: CypressMocks.ChatbotApiClientMock;
|
|
25
|
+
let chatbotUiStore: IChatbotUiStore;
|
|
26
|
+
|
|
27
|
+
const mockApiClient = () => {
|
|
28
|
+
api.postSession = cy.stub().resolves(ModelsMocks.mockSession());
|
|
29
|
+
api.getOptions = cy.stub().resolves(ModelsMocks.mockFrontendModel());
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
container = testInitContainerChatbot();
|
|
34
|
+
api = container.get<CypressMocks.ChatbotApiClientMock>(CHATBOT_API_CLIENT);
|
|
35
|
+
chatbotUiStore = container.get<ChatbotUiStore>(CHATBOT_UI_STORE_TOKEN);
|
|
36
|
+
mockApiClient();
|
|
37
|
+
cy.viewport(550, 800);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const render = (confirmText: string, onClose: () => void, onAfterInit?: () => void) => {
|
|
41
|
+
return cy.wrap(null).then(() => {
|
|
42
|
+
const component = (
|
|
43
|
+
<ChatbotRestartDialogComponent confirmText={confirmText} onClose={onClose} />
|
|
44
|
+
);
|
|
45
|
+
const wrappedComponent = wrapperComponent ? wrapperComponent(component) : component;
|
|
46
|
+
|
|
47
|
+
return testRenderWrapperChatbot(container, wrappedComponent, onAfterInit);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
it('should render restart dialog with confirm text', () => {
|
|
52
|
+
const onClose = cy.stub();
|
|
53
|
+
const confirmText = 'Are you sure you want to restart the conversation?';
|
|
54
|
+
|
|
55
|
+
render(confirmText, onClose);
|
|
56
|
+
|
|
57
|
+
ChatUiSelectors.chatbotRestartDialog.should('be.visible').within(() => {
|
|
58
|
+
cy.contains(confirmText).should('be.visible');
|
|
59
|
+
cy.get('button').contains('Restart').should('be.visible');
|
|
60
|
+
cy.get('button').contains('Cancel').should('be.visible');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should call onClose when Cancel button is clicked', () => {
|
|
65
|
+
const onClose = cy.stub().as('onClose');
|
|
66
|
+
const confirmText = 'Test confirmation text';
|
|
67
|
+
|
|
68
|
+
render(confirmText, onClose);
|
|
69
|
+
|
|
70
|
+
ChatUiSelectors.chatbotRestartDialog.should('be.visible').within(() => {
|
|
71
|
+
cy.get('button').contains('Cancel').closest('button').click();
|
|
72
|
+
});
|
|
73
|
+
cy.get('@onClose').should('have.been.called');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should call restart and onClose when Restart button is clicked', () => {
|
|
77
|
+
const onClose = cy.stub().as('onClose');
|
|
78
|
+
const confirmText = 'Test confirmation text';
|
|
79
|
+
|
|
80
|
+
render(confirmText, onClose).then(() => {
|
|
81
|
+
cy.spy(chatbotUiStore, 'restart').as('restart');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
ChatUiSelectors.chatbotRestartDialog.should('be.visible').within(() => {
|
|
85
|
+
cy.get('button').contains('Restart').closest('button').click();
|
|
86
|
+
});
|
|
87
|
+
cy.wait(1);
|
|
88
|
+
cy.get('@onClose').should('have.been.called');
|
|
89
|
+
cy.get('@restart').should('have.been.called');
|
|
90
|
+
});
|
|
91
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Container } from '@servicetitan/react-ioc';
|
|
2
|
+
import {
|
|
3
|
+
CHATBOT_API_CLIENT,
|
|
4
|
+
CHATBOT_UI_STORE_TOKEN,
|
|
5
|
+
ChatbotUiStore,
|
|
6
|
+
IChatbotUiStore,
|
|
7
|
+
ModelsMocks,
|
|
8
|
+
} from '@servicetitan/titan-chatbot-api';
|
|
9
|
+
import { FC, ReactElement } from 'react';
|
|
10
|
+
import { CypressMocks, testInitContainerChatbot, testRenderWrapperChatbot } from '../..';
|
|
11
|
+
import { ChatUiSelectors } from '../../utils/chat-ui-selectors';
|
|
12
|
+
|
|
13
|
+
interface ILinkProps {
|
|
14
|
+
className?: string;
|
|
15
|
+
onClick?: (...args: any[]) => any;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function runChatbotRestartLinkSharedTests(
|
|
19
|
+
ChatbotRestartLinkComponent: FC<ILinkProps>,
|
|
20
|
+
wrapperComponent?: (component: ReactElement) => ReactElement
|
|
21
|
+
) {
|
|
22
|
+
let container: Container;
|
|
23
|
+
let api: CypressMocks.ChatbotApiClientMock;
|
|
24
|
+
let chatbotUiStore: IChatbotUiStore;
|
|
25
|
+
|
|
26
|
+
const mockApiClient = () => {
|
|
27
|
+
api.postSession = cy.stub().resolves(ModelsMocks.mockSession());
|
|
28
|
+
api.getOptions = cy.stub().resolves(ModelsMocks.mockFrontendModel());
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
container = testInitContainerChatbot();
|
|
33
|
+
api = container.get<CypressMocks.ChatbotApiClientMock>(CHATBOT_API_CLIENT);
|
|
34
|
+
chatbotUiStore = container.get<ChatbotUiStore>(CHATBOT_UI_STORE_TOKEN);
|
|
35
|
+
mockApiClient();
|
|
36
|
+
cy.viewport(550, 800);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const render = (props: ILinkProps = {}, onAfterInit?: () => void) => {
|
|
40
|
+
return cy.wrap(null).then(() => {
|
|
41
|
+
const component = (
|
|
42
|
+
<ChatbotRestartLinkComponent {...props}>
|
|
43
|
+
Restart Session
|
|
44
|
+
</ChatbotRestartLinkComponent>
|
|
45
|
+
);
|
|
46
|
+
const wrappedComponent = wrapperComponent ? wrapperComponent(component) : component;
|
|
47
|
+
|
|
48
|
+
return testRenderWrapperChatbot(container, wrappedComponent, onAfterInit);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
it('should render restart link with children', () => {
|
|
53
|
+
render();
|
|
54
|
+
|
|
55
|
+
ChatUiSelectors.chatbotRestartLink.should('be.visible');
|
|
56
|
+
cy.contains('Restart Session').should('be.visible');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should open restart dialog when link is clicked', () => {
|
|
60
|
+
render();
|
|
61
|
+
|
|
62
|
+
ChatUiSelectors.chatbotRestartLink.click();
|
|
63
|
+
|
|
64
|
+
ChatUiSelectors.chatbotRestartDialog.should('be.visible').within(() => {
|
|
65
|
+
cy.contains('Restart Titan session?').should('be.visible');
|
|
66
|
+
cy.get('button').contains('Restart').should('be.visible');
|
|
67
|
+
cy.get('button').contains('Cancel').should('be.visible');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should call onClick prop when link is clicked', () => {
|
|
72
|
+
const onClick = cy.stub().as('onClick');
|
|
73
|
+
|
|
74
|
+
render({ onClick });
|
|
75
|
+
|
|
76
|
+
ChatUiSelectors.chatbotRestartLink.click();
|
|
77
|
+
|
|
78
|
+
cy.get('@onClick').should('have.been.called');
|
|
79
|
+
ChatUiSelectors.chatbotRestartDialog.should('be.visible');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should close dialog when Cancel button is clicked', () => {
|
|
83
|
+
render();
|
|
84
|
+
|
|
85
|
+
ChatUiSelectors.chatbotRestartLink.click();
|
|
86
|
+
ChatUiSelectors.chatbotRestartDialog.should('be.visible').within(() => {
|
|
87
|
+
cy.get('button').contains('Cancel').closest('button').click();
|
|
88
|
+
});
|
|
89
|
+
ChatUiSelectors.chatbotRestartDialog.should('not.exist');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should close dialog and restart session when Restart button is clicked', () => {
|
|
93
|
+
render().then(() => {
|
|
94
|
+
cy.spy(chatbotUiStore, 'restart').as('restart');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
ChatUiSelectors.chatbotRestartLink.click();
|
|
98
|
+
ChatUiSelectors.chatbotRestartDialog.should('be.visible').within(() => {
|
|
99
|
+
cy.get('button').contains('Restart').closest('button').click();
|
|
100
|
+
});
|
|
101
|
+
cy.wait(1).then(() => {
|
|
102
|
+
cy.get('@restart').should('have.been.called');
|
|
103
|
+
});
|
|
104
|
+
ChatUiSelectors.chatbotRestartDialog.should('not.exist');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should pass through additional Link props', () => {
|
|
108
|
+
const customClassName = 'custom-restart-link';
|
|
109
|
+
|
|
110
|
+
render({ className: customClassName });
|
|
111
|
+
|
|
112
|
+
ChatUiSelectors.chatbotRestartLink
|
|
113
|
+
.should('be.visible')
|
|
114
|
+
.should('have.class', customClassName);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { Container } from '@servicetitan/react-ioc';
|
|
2
|
+
import {
|
|
3
|
+
CHATBOT_API_CLIENT,
|
|
4
|
+
CHATBOT_UI_STORE_TOKEN,
|
|
5
|
+
ChatbotUiStore,
|
|
6
|
+
IChatbotUiStore,
|
|
7
|
+
Models,
|
|
8
|
+
ModelsMocks,
|
|
9
|
+
} from '@servicetitan/titan-chatbot-api';
|
|
10
|
+
import { FC, ReactElement } from 'react';
|
|
11
|
+
import { CypressMocks, testInitContainerChatbot, testRenderWrapperChatbot } from '../..';
|
|
12
|
+
import { ChatUiSelectors } from '../../utils/chat-ui-selectors';
|
|
13
|
+
|
|
14
|
+
interface IChatbotSessionFeedbackModalProps {
|
|
15
|
+
onClose: () => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function runChatbotSessionFeedbackModalSharedTests(
|
|
19
|
+
ChatbotSessionFeedbackModalComponent: FC<IChatbotSessionFeedbackModalProps>,
|
|
20
|
+
wrapperComponent?: (component: ReactElement) => ReactElement
|
|
21
|
+
) {
|
|
22
|
+
let container: Container;
|
|
23
|
+
let api: CypressMocks.ChatbotApiClientMock;
|
|
24
|
+
let chatbotUiStore: IChatbotUiStore;
|
|
25
|
+
|
|
26
|
+
const mockApiClient = () => {
|
|
27
|
+
api.postSession = cy.stub().resolves(ModelsMocks.mockSession());
|
|
28
|
+
api.getOptions = cy.stub().resolves(ModelsMocks.mockFrontendModel());
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
container = testInitContainerChatbot();
|
|
33
|
+
api = container.get<CypressMocks.ChatbotApiClientMock>(CHATBOT_API_CLIENT);
|
|
34
|
+
chatbotUiStore = container.get<ChatbotUiStore>(CHATBOT_UI_STORE_TOKEN);
|
|
35
|
+
mockApiClient();
|
|
36
|
+
cy.viewport(550, 800);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const assertButtonSelection = (element: Cypress.Chainable<JQuery>, selected: boolean) => {
|
|
40
|
+
element.should($el => {
|
|
41
|
+
const hasClass = $el.hasClass('Button--selected');
|
|
42
|
+
const hasAttr = $el.attr('aria-pressed') === 'true';
|
|
43
|
+
expect(hasClass || hasAttr).to.equal(selected);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const render = (onAfterInit?: () => void, onClose = cy.stub()) => {
|
|
48
|
+
return cy.wrap(null).then(() => {
|
|
49
|
+
const TestComponent: FC = () => {
|
|
50
|
+
const component = <ChatbotSessionFeedbackModalComponent onClose={onClose} />;
|
|
51
|
+
return wrapperComponent ? wrapperComponent(component) : component;
|
|
52
|
+
};
|
|
53
|
+
return testRenderWrapperChatbot(container, <TestComponent />, onAfterInit);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
it('should render the feedback modal with all elements', () => {
|
|
58
|
+
render();
|
|
59
|
+
|
|
60
|
+
ChatUiSelectors.chatbotSessionFeedbackModal.should('be.visible');
|
|
61
|
+
ChatUiSelectors.chatbotSessionFeedbackThumbsUp.should('be.visible');
|
|
62
|
+
ChatUiSelectors.chatbotSessionFeedbackThumbsDown.should('be.visible');
|
|
63
|
+
ChatUiSelectors.chatbotSessionFeedbackComment.should('be.visible');
|
|
64
|
+
ChatUiSelectors.chatbotSessionFeedbackCancel.should('be.visible');
|
|
65
|
+
ChatUiSelectors.chatbotSessionFeedbackSubmit.should('be.visible');
|
|
66
|
+
ChatUiSelectors.chatbotSessionFeedbackSubmit.should('be.disabled');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should enable submit button when thumbs up is selected', () => {
|
|
70
|
+
render();
|
|
71
|
+
|
|
72
|
+
ChatUiSelectors.chatbotSessionFeedbackThumbsUp.click();
|
|
73
|
+
ChatUiSelectors.chatbotSessionFeedbackSubmit.should('not.be.disabled');
|
|
74
|
+
assertButtonSelection(ChatUiSelectors.chatbotSessionFeedbackThumbsUp, true);
|
|
75
|
+
assertButtonSelection(ChatUiSelectors.chatbotSessionFeedbackThumbsDown, false);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should enable submit button when thumbs down is selected', () => {
|
|
79
|
+
render();
|
|
80
|
+
|
|
81
|
+
ChatUiSelectors.chatbotSessionFeedbackThumbsDown.click();
|
|
82
|
+
ChatUiSelectors.chatbotSessionFeedbackSubmit.should('not.be.disabled');
|
|
83
|
+
assertButtonSelection(ChatUiSelectors.chatbotSessionFeedbackThumbsDown, true);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should allow switching between thumbs up and thumbs down', () => {
|
|
87
|
+
render();
|
|
88
|
+
|
|
89
|
+
ChatUiSelectors.chatbotSessionFeedbackThumbsUp.click();
|
|
90
|
+
assertButtonSelection(ChatUiSelectors.chatbotSessionFeedbackThumbsUp, true);
|
|
91
|
+
assertButtonSelection(ChatUiSelectors.chatbotSessionFeedbackThumbsDown, false);
|
|
92
|
+
|
|
93
|
+
ChatUiSelectors.chatbotSessionFeedbackThumbsDown.click();
|
|
94
|
+
assertButtonSelection(ChatUiSelectors.chatbotSessionFeedbackThumbsDown, true);
|
|
95
|
+
assertButtonSelection(ChatUiSelectors.chatbotSessionFeedbackThumbsUp, false);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should allow entering a comment', () => {
|
|
99
|
+
render();
|
|
100
|
+
|
|
101
|
+
const testComment = 'This is my feedback comment';
|
|
102
|
+
ChatUiSelectors.chatbotSessionFeedbackComment.type(testComment);
|
|
103
|
+
ChatUiSelectors.chatbotSessionFeedbackComment.should('have.value', testComment);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('should call onClose when cancel button is clicked', () => {
|
|
107
|
+
const onClose = cy.stub().as('onClose');
|
|
108
|
+
render(undefined, onClose);
|
|
109
|
+
|
|
110
|
+
ChatUiSelectors.chatbotSessionFeedbackCancel.click();
|
|
111
|
+
cy.then(() => {
|
|
112
|
+
cy.get('@onClose').should('have.been.called');
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should submit feedback with thumbs up and close modal', () => {
|
|
117
|
+
const onClose = cy.stub().as('onClose');
|
|
118
|
+
render(undefined, onClose);
|
|
119
|
+
|
|
120
|
+
ChatUiSelectors.chatbotSessionFeedbackThumbsUp.click();
|
|
121
|
+
ChatUiSelectors.chatbotSessionFeedbackSubmit.click();
|
|
122
|
+
|
|
123
|
+
cy.wait(1).then(() => {
|
|
124
|
+
cy.get('@onClose').should('have.been.called');
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should submit feedback with thumbs down, comment and close modal', () => {
|
|
129
|
+
const onClose = cy.stub().as('onClose');
|
|
130
|
+
render(undefined, onClose);
|
|
131
|
+
|
|
132
|
+
const testComment = 'This did not help me at all';
|
|
133
|
+
ChatUiSelectors.chatbotSessionFeedbackThumbsDown.click();
|
|
134
|
+
ChatUiSelectors.chatbotSessionFeedbackComment.type(testComment);
|
|
135
|
+
ChatUiSelectors.chatbotSessionFeedbackSubmit.click();
|
|
136
|
+
|
|
137
|
+
cy.wait(1).then(() => {
|
|
138
|
+
cy.get('@onClose').should('have.been.called');
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should send session feedback to the store when submitting', () => {
|
|
143
|
+
const onClose = cy.stub();
|
|
144
|
+
render(undefined, onClose);
|
|
145
|
+
|
|
146
|
+
cy.spy(chatbotUiStore, 'sendSessionFeedback').as('sendSessionFeedback');
|
|
147
|
+
|
|
148
|
+
ChatUiSelectors.chatbotSessionFeedbackThumbsUp.click();
|
|
149
|
+
ChatUiSelectors.chatbotSessionFeedbackSubmit.click();
|
|
150
|
+
|
|
151
|
+
cy.get('@sendSessionFeedback').should('have.been.called');
|
|
152
|
+
cy.get('@sendSessionFeedback').should(
|
|
153
|
+
'have.been.calledWith',
|
|
154
|
+
new Models.Feedback({
|
|
155
|
+
sessionId: ModelsMocks.mockSession().id,
|
|
156
|
+
rating: Models.FeedbackRatings.ThumbsUp,
|
|
157
|
+
})
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('should send session feedback with comment when submitting', () => {
|
|
162
|
+
const onClose = cy.stub();
|
|
163
|
+
render(undefined, onClose);
|
|
164
|
+
|
|
165
|
+
cy.spy(chatbotUiStore, 'sendSessionFeedback').as('sendSessionFeedback');
|
|
166
|
+
|
|
167
|
+
const testComment = 'Great experience!';
|
|
168
|
+
ChatUiSelectors.chatbotSessionFeedbackThumbsUp.click();
|
|
169
|
+
ChatUiSelectors.chatbotSessionFeedbackComment.type(testComment);
|
|
170
|
+
ChatUiSelectors.chatbotSessionFeedbackSubmit.click();
|
|
171
|
+
|
|
172
|
+
cy.get('@sendSessionFeedback').should('have.been.called');
|
|
173
|
+
cy.get('@sendSessionFeedback').should(
|
|
174
|
+
'have.been.calledWithMatch',
|
|
175
|
+
new Models.Feedback({
|
|
176
|
+
sessionId: ModelsMocks.mockSession().id,
|
|
177
|
+
rating: Models.FeedbackRatings.ThumbsUp,
|
|
178
|
+
description: testComment,
|
|
179
|
+
})
|
|
180
|
+
);
|
|
181
|
+
});
|
|
182
|
+
}
|