@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,189 @@
|
|
|
1
|
+
import { Container } from '@servicetitan/react-ioc';
|
|
2
|
+
import { CHATBOT_API_CLIENT, Models, ModelsMocks } from '@servicetitan/titan-chatbot-api';
|
|
3
|
+
import { FC, ReactElement } from 'react';
|
|
4
|
+
import { CypressMocks, testInitContainerChatbot, testRenderWrapperChatbot } from '../..';
|
|
5
|
+
import { ChatUiSelectors } from '../../utils/chat-ui-selectors';
|
|
6
|
+
|
|
7
|
+
interface IChatbotLinksProps {
|
|
8
|
+
seeMoreLabel?: string;
|
|
9
|
+
seeLessLabel?: string;
|
|
10
|
+
links?: Models.ScoredUrl[];
|
|
11
|
+
onToggle?: () => void;
|
|
12
|
+
linkProps?: {
|
|
13
|
+
primary?: boolean;
|
|
14
|
+
className?: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function runChatbotLinksSharedTests(
|
|
19
|
+
ChatbotLinksComponent: FC<IChatbotLinksProps>,
|
|
20
|
+
wrapperComponent?: (component: ReactElement) => ReactElement
|
|
21
|
+
) {
|
|
22
|
+
let container: Container;
|
|
23
|
+
let api: CypressMocks.ChatbotApiClientMock;
|
|
24
|
+
|
|
25
|
+
const mockApiClient = () => {
|
|
26
|
+
api.postSession = cy.stub().resolves(ModelsMocks.mockSession());
|
|
27
|
+
api.getOptions = cy.stub().resolves(ModelsMocks.mockFrontendModel());
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
container = testInitContainerChatbot();
|
|
32
|
+
api = container.get<CypressMocks.ChatbotApiClientMock>(CHATBOT_API_CLIENT);
|
|
33
|
+
mockApiClient();
|
|
34
|
+
cy.viewport(550, 800);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const render = (
|
|
38
|
+
props: {
|
|
39
|
+
seeMoreLabel?: string;
|
|
40
|
+
seeLessLabel?: string;
|
|
41
|
+
links?: Models.ScoredUrl[];
|
|
42
|
+
onToggle?: () => void;
|
|
43
|
+
linkProps?: {
|
|
44
|
+
primary?: boolean;
|
|
45
|
+
className?: string;
|
|
46
|
+
};
|
|
47
|
+
} = {},
|
|
48
|
+
onAfterInit?: () => void
|
|
49
|
+
) => {
|
|
50
|
+
const defaultProps = {
|
|
51
|
+
seeMoreLabel: 'See more',
|
|
52
|
+
seeLessLabel: 'See less',
|
|
53
|
+
links: ModelsMocks.mockScoredUrls(),
|
|
54
|
+
...props,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return cy.wrap(null).then(() => {
|
|
58
|
+
const component = <ChatbotLinksComponent {...defaultProps} />;
|
|
59
|
+
const wrappedComponent = wrapperComponent ? wrapperComponent(component) : component;
|
|
60
|
+
|
|
61
|
+
return testRenderWrapperChatbot(container, wrappedComponent, onAfterInit);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
it('should render component with links when links are provided', () => {
|
|
66
|
+
render();
|
|
67
|
+
|
|
68
|
+
ChatUiSelectors.chatbotLinksMore.should('be.visible');
|
|
69
|
+
ChatUiSelectors.chatbotLinksMore.should('contain.text', 'See more');
|
|
70
|
+
ChatUiSelectors.chatbotLinksLink.should('not.be.visible');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should not render anything when no links are provided', () => {
|
|
74
|
+
render({ links: [] });
|
|
75
|
+
|
|
76
|
+
ChatUiSelectors.chatbotLinksMore.should('not.exist');
|
|
77
|
+
ChatUiSelectors.chatbotLinksCollapsible.should('not.exist');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should toggle collapsible when clicking the toggle button', () => {
|
|
81
|
+
render();
|
|
82
|
+
|
|
83
|
+
// Initially collapsed
|
|
84
|
+
ChatUiSelectors.chatbotLinksMore.should('contain.text', 'See more');
|
|
85
|
+
ChatUiSelectors.chatbotLinksLink.should('not.be.visible');
|
|
86
|
+
|
|
87
|
+
// Click to expand
|
|
88
|
+
ChatUiSelectors.chatbotLinksMore.click();
|
|
89
|
+
|
|
90
|
+
ChatUiSelectors.chatbotLinksMore.should('contain.text', 'See less');
|
|
91
|
+
ChatUiSelectors.chatbotLinksLink.should('be.visible');
|
|
92
|
+
|
|
93
|
+
// Click to collapse
|
|
94
|
+
ChatUiSelectors.chatbotLinksMore.click();
|
|
95
|
+
|
|
96
|
+
ChatUiSelectors.chatbotLinksMore.should('contain.text', 'See more');
|
|
97
|
+
ChatUiSelectors.chatbotLinksLink.should('not.be.visible');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should render all links when expanded', () => {
|
|
101
|
+
const testLinks = [
|
|
102
|
+
ModelsMocks.mockScoredUrl({ url: 'https://test1.com', title: 'Test Link 1' }),
|
|
103
|
+
ModelsMocks.mockScoredUrl({ url: 'https://test2.com', title: 'Test Link 2' }),
|
|
104
|
+
ModelsMocks.mockScoredUrl({ url: 'https://test3.com', title: 'Test Link 3' }),
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
render({ links: testLinks });
|
|
108
|
+
|
|
109
|
+
// Expand the links
|
|
110
|
+
ChatUiSelectors.chatbotLinksMore.click();
|
|
111
|
+
|
|
112
|
+
// Check that all links are rendered
|
|
113
|
+
ChatUiSelectors.chatbotLinksLink.should('have.length', 3);
|
|
114
|
+
ChatUiSelectors.chatbotLinksLink.eq(0).should('contain.text', 'Test Link 1');
|
|
115
|
+
ChatUiSelectors.chatbotLinksLink.eq(1).should('contain.text', 'Test Link 2');
|
|
116
|
+
ChatUiSelectors.chatbotLinksLink.eq(2).should('contain.text', 'Test Link 3');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('should render link with url as text when title is not provided', () => {
|
|
120
|
+
const testLinks = [
|
|
121
|
+
ModelsMocks.mockScoredUrl({ url: 'https://test-no-title.com', title: undefined }),
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
render({ links: testLinks });
|
|
125
|
+
|
|
126
|
+
// Expand the links
|
|
127
|
+
ChatUiSelectors.chatbotLinksMore.click();
|
|
128
|
+
|
|
129
|
+
ChatUiSelectors.chatbotLinksLink.should('contain.text', 'https://test-no-title.com');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should set correct href and target attributes on links', () => {
|
|
133
|
+
const testLinks = [
|
|
134
|
+
ModelsMocks.mockScoredUrl({ url: 'https://external-link.com', title: 'External Link' }),
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
render({ links: testLinks });
|
|
138
|
+
|
|
139
|
+
// Expand the links
|
|
140
|
+
ChatUiSelectors.chatbotLinksMore.click();
|
|
141
|
+
|
|
142
|
+
ChatUiSelectors.chatbotLinksLink
|
|
143
|
+
.should('have.attr', 'href', 'https://external-link.com')
|
|
144
|
+
.and('have.attr', 'target', '_blank');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('should call onToggle callback with delay when toggling', () => {
|
|
148
|
+
const onToggleSpy = cy.stub().as('onToggle');
|
|
149
|
+
|
|
150
|
+
render({ onToggle: onToggleSpy });
|
|
151
|
+
|
|
152
|
+
ChatUiSelectors.chatbotLinksMore.click();
|
|
153
|
+
|
|
154
|
+
// Callback should not be called immediately
|
|
155
|
+
cy.get('@onToggle').should('not.have.been.called');
|
|
156
|
+
|
|
157
|
+
// Wait for the 200ms delay
|
|
158
|
+
cy.wait(250);
|
|
159
|
+
cy.get('@onToggle').should('have.been.calledOnce');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('should use custom labels when provided', () => {
|
|
163
|
+
render({
|
|
164
|
+
seeMoreLabel: 'Show links',
|
|
165
|
+
seeLessLabel: 'Hide links',
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
ChatUiSelectors.chatbotLinksMore.should('contain.text', 'Show links');
|
|
169
|
+
|
|
170
|
+
ChatUiSelectors.chatbotLinksMore.click();
|
|
171
|
+
ChatUiSelectors.chatbotLinksMore.should('contain.text', 'Hide links');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('should apply custom link props when provided', () => {
|
|
175
|
+
const testLinks = [ModelsMocks.mockScoredUrl({ url: 'https://test.com', title: 'Test' })];
|
|
176
|
+
|
|
177
|
+
render({
|
|
178
|
+
links: testLinks,
|
|
179
|
+
linkProps: {
|
|
180
|
+
className: 'custom-link-class',
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// Expand the links
|
|
185
|
+
ChatUiSelectors.chatbotLinksMore.click();
|
|
186
|
+
|
|
187
|
+
ChatUiSelectors.chatbotLinksLink.should('have.class', 'custom-link-class');
|
|
188
|
+
});
|
|
189
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Log } from '@servicetitan/log-service';
|
|
2
|
+
import { Container, Provider } from '@servicetitan/react-ioc';
|
|
3
|
+
import {
|
|
4
|
+
CHATBOT_API_CLIENT,
|
|
5
|
+
CHATBOT_UI_BACKEND_STORE_TOKEN,
|
|
6
|
+
CHATBOT_UI_STORE_TOKEN,
|
|
7
|
+
ChatbotCustomizations,
|
|
8
|
+
ChatbotUiBackendStore,
|
|
9
|
+
ChatbotUiStore,
|
|
10
|
+
Models,
|
|
11
|
+
ModelsMocks,
|
|
12
|
+
} from '@servicetitan/titan-chatbot-api';
|
|
13
|
+
import { mount } from 'cypress/react';
|
|
14
|
+
import { FC, ReactElement, useMemo } from 'react';
|
|
15
|
+
import { CypressMocks, testInitContainerChatbot } from '../..';
|
|
16
|
+
import { ChatUiSelectors } from '../../utils/chat-ui-selectors';
|
|
17
|
+
|
|
18
|
+
interface IChatbotProps {
|
|
19
|
+
className?: string;
|
|
20
|
+
customizations?: ChatbotCustomizations;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function runChatbotLiveSharedTests(
|
|
24
|
+
ChatbotComponent: FC<IChatbotProps>,
|
|
25
|
+
wrapperComponent?: (component: ReactElement) => ReactElement
|
|
26
|
+
) {
|
|
27
|
+
let container: Container;
|
|
28
|
+
let log: CypressMocks.LogMock;
|
|
29
|
+
let api: CypressMocks.ChatbotApiClientMock;
|
|
30
|
+
let uiStore: ChatbotUiStore;
|
|
31
|
+
let uiBackendStore: ChatbotUiBackendStore;
|
|
32
|
+
|
|
33
|
+
const mockApi = () => {
|
|
34
|
+
api.postSession = cy.stub().resolves(ModelsMocks.mockSession());
|
|
35
|
+
api.getOptions = cy.stub().resolves(ModelsMocks.mockFrontendModel());
|
|
36
|
+
};
|
|
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 = testInitContainerChatbot();
|
|
48
|
+
log = container.get<CypressMocks.LogMock>(Log);
|
|
49
|
+
api = container.get<CypressMocks.ChatbotApiClientMock>(CHATBOT_API_CLIENT);
|
|
50
|
+
uiStore = container.get<ChatbotUiStore>(CHATBOT_UI_STORE_TOKEN);
|
|
51
|
+
uiBackendStore = container.get<ChatbotUiBackendStore>(CHATBOT_UI_BACKEND_STORE_TOKEN);
|
|
52
|
+
mockApi();
|
|
53
|
+
cy.viewport(550, 800);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const mockAskBotApi = (answer: string) => {
|
|
57
|
+
api.postMessage = cy.stub().as('askBot').resolves(
|
|
58
|
+
ModelsMocks.mockBotMessage({
|
|
59
|
+
answer,
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
api.postFeedback = cy
|
|
63
|
+
.stub()
|
|
64
|
+
.as('askBotFeedback')
|
|
65
|
+
.resolves(
|
|
66
|
+
ModelsMocks.mockFeedback({
|
|
67
|
+
rating: Models.FeedbackRatings.ThumbsUp,
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const render = () => {
|
|
73
|
+
const ChatbotWrapper: FC = () => {
|
|
74
|
+
const customizationContext = useMemo<ChatbotCustomizations>(
|
|
75
|
+
() => ({
|
|
76
|
+
filters: { enabled: true },
|
|
77
|
+
feedback: { title: 'TITLE' },
|
|
78
|
+
}),
|
|
79
|
+
[]
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const component = (
|
|
83
|
+
<ChatbotComponent
|
|
84
|
+
className="h-100vh max-h-100vh of-x-hidden"
|
|
85
|
+
customizations={customizationContext}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const wrappedComponent = wrapperComponent ? wrapperComponent(component) : component;
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<Provider
|
|
93
|
+
singletons={[
|
|
94
|
+
{
|
|
95
|
+
provide: Log,
|
|
96
|
+
useValue: log,
|
|
97
|
+
},
|
|
98
|
+
{ provide: CHATBOT_API_CLIENT, useValue: api },
|
|
99
|
+
{
|
|
100
|
+
provide: CHATBOT_UI_STORE_TOKEN,
|
|
101
|
+
useValue: uiStore,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
provide: CHATBOT_UI_BACKEND_STORE_TOKEN,
|
|
105
|
+
useValue: uiBackendStore,
|
|
106
|
+
},
|
|
107
|
+
]}
|
|
108
|
+
>
|
|
109
|
+
{wrappedComponent}
|
|
110
|
+
</Provider>
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
mount(<ChatbotWrapper />);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const ask = (message: string) => {
|
|
117
|
+
ChatUiSelectors.chatInput.type(`${message}{enter}`, { delay: 0 });
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
it.skip('should render the chatbot component', () => {
|
|
121
|
+
mockAskBotApi("Hello! I'm chatbot mocked response!!!");
|
|
122
|
+
render();
|
|
123
|
+
ask('Hello!');
|
|
124
|
+
ChatUiSelectors.chatbotMessageFeedbackThumbsUp.should('be.visible').click();
|
|
125
|
+
cy.get('@askBotFeedback').should('have.been.calledOnce');
|
|
126
|
+
});
|
|
127
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { Container } from '@servicetitan/react-ioc';
|
|
2
|
+
import { ChatMessageModelText, mockChatMessageModelText } from '@servicetitan/titan-chat-ui-common';
|
|
3
|
+
import { CHATBOT_API_CLIENT, Models, 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 IChatbotMessageAnswerReadonlyProps {
|
|
9
|
+
message: ChatMessageModelText;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function runChatbotMessageAnswerReadonlySharedTests(
|
|
13
|
+
ChatbotMessageAnswerReadonlyComponent: FC<IChatbotMessageAnswerReadonlyProps>,
|
|
14
|
+
wrapperComponent?: (component: ReactElement) => ReactElement
|
|
15
|
+
) {
|
|
16
|
+
let container: Container;
|
|
17
|
+
let api: CypressMocks.ChatbotApiClientMock;
|
|
18
|
+
|
|
19
|
+
const mockApiClient = () => {
|
|
20
|
+
api.postSession = cy.stub().resolves(ModelsMocks.mockSession());
|
|
21
|
+
api.getOptions = cy.stub().resolves(ModelsMocks.mockFrontendModel());
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
container = testInitContainerChatbot();
|
|
26
|
+
api = container.get<CypressMocks.ChatbotApiClientMock>(CHATBOT_API_CLIENT);
|
|
27
|
+
mockApiClient();
|
|
28
|
+
cy.viewport(550, 800);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const render = (message: ChatMessageModelText, onAfterInit?: () => void) => {
|
|
32
|
+
return cy.wrap(null).then(() => {
|
|
33
|
+
const component = <ChatbotMessageAnswerReadonlyComponent message={message} />;
|
|
34
|
+
const wrappedComponent = wrapperComponent ? wrapperComponent(component) : component;
|
|
35
|
+
|
|
36
|
+
return testRenderWrapperChatbot(container, wrappedComponent, onAfterInit);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
it('should render basic readonly message answer', () => {
|
|
41
|
+
const message = mockChatMessageModelText(false, {
|
|
42
|
+
message: 'This is a readonly answer from the chatbot',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
render(message);
|
|
46
|
+
|
|
47
|
+
cy.contains('This is a readonly answer from the chatbot').should('be.visible');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should render multiline text correctly', () => {
|
|
51
|
+
const multilineMessage = 'Line 1\nLine 2\nLine 3';
|
|
52
|
+
const message = mockChatMessageModelText(false, {
|
|
53
|
+
message: multilineMessage,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
render(message);
|
|
57
|
+
|
|
58
|
+
cy.contains('Line 1').should('be.visible');
|
|
59
|
+
cy.contains('Line 2').should('be.visible');
|
|
60
|
+
cy.contains('Line 3').should('be.visible');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should render readonly message without bot message data', () => {
|
|
64
|
+
const message = mockChatMessageModelText(false, {
|
|
65
|
+
message: 'Simple readonly answer',
|
|
66
|
+
data: undefined,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
render(message);
|
|
70
|
+
|
|
71
|
+
cy.contains('Simple readonly answer').should('be.visible');
|
|
72
|
+
|
|
73
|
+
// Should not render links when no bot message data
|
|
74
|
+
ChatUiSelectors.chatbotLinksLink.should('not.exist');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should render readonly message with bot message data but no links', () => {
|
|
78
|
+
const botMessageWithoutLinks: Models.IBotMessageWithFeedback = {
|
|
79
|
+
...ModelsMocks.mockBotMessage({ answer: 'Answer without links' }),
|
|
80
|
+
scoredUrls: [],
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const message = mockChatMessageModelText(false, {
|
|
84
|
+
message: 'Answer without links',
|
|
85
|
+
data: botMessageWithoutLinks,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
render(message);
|
|
89
|
+
|
|
90
|
+
cy.contains('Answer without links').should('be.visible');
|
|
91
|
+
|
|
92
|
+
// Should not render links when scoredUrls is empty
|
|
93
|
+
ChatUiSelectors.chatbotLinksCollapsible.should('not.exist');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should render readonly message with bot message data and links', () => {
|
|
97
|
+
const botMessageWithFeedback: Models.IBotMessageWithFeedback = {
|
|
98
|
+
...ModelsMocks.mockBotMessage({ answer: 'Readonly answer with links' }),
|
|
99
|
+
scoredUrls: [
|
|
100
|
+
ModelsMocks.mockScoredUrl({
|
|
101
|
+
url: 'https://example.com/article1',
|
|
102
|
+
title: 'Example Article 1',
|
|
103
|
+
score: 0.9,
|
|
104
|
+
}),
|
|
105
|
+
ModelsMocks.mockScoredUrl({
|
|
106
|
+
url: 'https://example.com/article2',
|
|
107
|
+
title: 'Example Article 2',
|
|
108
|
+
score: 0.8,
|
|
109
|
+
}),
|
|
110
|
+
ModelsMocks.mockScoredUrl({
|
|
111
|
+
url: 'https://example.com/article3',
|
|
112
|
+
title: 'Example Article 3',
|
|
113
|
+
score: 0.7,
|
|
114
|
+
}),
|
|
115
|
+
],
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const message = mockChatMessageModelText(false, {
|
|
119
|
+
message: 'Readonly answer with links',
|
|
120
|
+
data: botMessageWithFeedback,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
render(message);
|
|
124
|
+
|
|
125
|
+
cy.contains('Readonly answer with links').should('be.visible');
|
|
126
|
+
|
|
127
|
+
// Check that links are rendered with correct labels
|
|
128
|
+
ChatUiSelectors.chatbotLinksMore.should('contain.text', 'Learn more').click();
|
|
129
|
+
ChatUiSelectors.chatbotLinksLink.should('be.visible');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should render readonly message with bot message data and single link', () => {
|
|
133
|
+
const botMessageWithSingleLink: Models.IBotMessageWithFeedback = {
|
|
134
|
+
...ModelsMocks.mockBotMessage({ answer: 'Answer with single link' }),
|
|
135
|
+
scoredUrls: [
|
|
136
|
+
ModelsMocks.mockScoredUrl({
|
|
137
|
+
url: 'https://example.com/single-article',
|
|
138
|
+
title: 'Single Article',
|
|
139
|
+
score: 0.95,
|
|
140
|
+
}),
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const message = mockChatMessageModelText(false, {
|
|
145
|
+
message: 'Answer with single link',
|
|
146
|
+
data: botMessageWithSingleLink,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
render(message);
|
|
150
|
+
|
|
151
|
+
cy.contains('Answer with single link').should('be.visible');
|
|
152
|
+
|
|
153
|
+
// Check that single link is rendered
|
|
154
|
+
ChatUiSelectors.chatbotLinksMore.should('be.visible').click();
|
|
155
|
+
ChatUiSelectors.chatbotLinksLink.should('have.length', 1);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('should handle null/undefined scoredUrls gracefully', () => {
|
|
159
|
+
const botMessageWithNullUrls: Models.IBotMessageWithFeedback = {
|
|
160
|
+
...ModelsMocks.mockBotMessage({ answer: 'Answer with null URLs' }),
|
|
161
|
+
scoredUrls: null as any,
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const message = mockChatMessageModelText(false, {
|
|
165
|
+
message: 'Answer with null URLs',
|
|
166
|
+
data: botMessageWithNullUrls,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
render(message);
|
|
170
|
+
|
|
171
|
+
cy.contains('Answer with null URLs').should('be.visible');
|
|
172
|
+
|
|
173
|
+
// Should not render links when scoredUrls is null
|
|
174
|
+
ChatUiSelectors.chatbotLinksCollapsible.should('not.exist');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('should render empty message gracefully', () => {
|
|
178
|
+
const message = mockChatMessageModelText(false, {
|
|
179
|
+
message: '',
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
render(message);
|
|
183
|
+
|
|
184
|
+
// Component should still render even with empty message
|
|
185
|
+
cy.get('body').should('be.visible');
|
|
186
|
+
});
|
|
187
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Container } from '@servicetitan/react-ioc';
|
|
2
|
+
import { ChatMessageModelText, mockChatMessageModelText } from '@servicetitan/titan-chat-ui-common';
|
|
3
|
+
import {
|
|
4
|
+
CHATBOT_API_CLIENT,
|
|
5
|
+
CHATBOT_UI_STORE_TOKEN,
|
|
6
|
+
ChatbotUiStore,
|
|
7
|
+
IChatbotUiStore,
|
|
8
|
+
Models,
|
|
9
|
+
ModelsMocks,
|
|
10
|
+
} from '@servicetitan/titan-chatbot-api';
|
|
11
|
+
import { FC, ReactElement } from 'react';
|
|
12
|
+
import { CypressMocks, testInitContainerChatbot, testRenderWrapperChatbot } from '../..';
|
|
13
|
+
import { ChatUiSelectors } from '../../utils/chat-ui-selectors';
|
|
14
|
+
|
|
15
|
+
interface IChatbotMessageAnswerProps {
|
|
16
|
+
message: ChatMessageModelText;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function runChatbotMessageAnswerSharedTests(
|
|
20
|
+
ChatbotMessageAnswerComponent: FC<IChatbotMessageAnswerProps>,
|
|
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 = (message: ChatMessageModelText, onAfterInit?: () => void) => {
|
|
41
|
+
return cy.wrap(null).then(() => {
|
|
42
|
+
const component = <ChatbotMessageAnswerComponent message={message} />;
|
|
43
|
+
const wrappedComponent = wrapperComponent ? wrapperComponent(component) : component;
|
|
44
|
+
|
|
45
|
+
return testRenderWrapperChatbot(container, wrappedComponent, onAfterInit);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
it('should render basic message answer', () => {
|
|
50
|
+
const message = mockChatMessageModelText(false, {
|
|
51
|
+
message: 'This is a test answer from the chatbot',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
render(message);
|
|
55
|
+
|
|
56
|
+
ChatUiSelectors.chatbotMessageAnswer.should('be.visible');
|
|
57
|
+
ChatUiSelectors.chatbotMessageAnswer.should(
|
|
58
|
+
'contain.text',
|
|
59
|
+
'This is a test answer from the chatbot'
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should render message answer with bot message data and links', () => {
|
|
64
|
+
const botMessageWithFeedback: Models.IBotMessageWithFeedback = {
|
|
65
|
+
...ModelsMocks.mockBotMessage({ answer: 'Test answer with links' }),
|
|
66
|
+
scoredUrls: [
|
|
67
|
+
ModelsMocks.mockScoredUrl({
|
|
68
|
+
url: 'https://example.com/article1',
|
|
69
|
+
title: 'Example Article 1',
|
|
70
|
+
score: 0.9,
|
|
71
|
+
}),
|
|
72
|
+
ModelsMocks.mockScoredUrl({
|
|
73
|
+
url: 'https://example.com/article2',
|
|
74
|
+
title: 'Example Article 2',
|
|
75
|
+
score: 0.8,
|
|
76
|
+
}),
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const message = mockChatMessageModelText(false, {
|
|
81
|
+
message: 'Test answer with links',
|
|
82
|
+
data: botMessageWithFeedback,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
render(message);
|
|
86
|
+
|
|
87
|
+
ChatUiSelectors.chatbotMessageAnswer.should('be.visible');
|
|
88
|
+
ChatUiSelectors.chatbotMessageAnswer.should('contain.text', 'Test answer with links');
|
|
89
|
+
|
|
90
|
+
// Check that links are rendered
|
|
91
|
+
ChatUiSelectors.chatbotLinksMore.should('contain.text', 'Learn more').click();
|
|
92
|
+
ChatUiSelectors.chatbotLinksLink.should('be.visible');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should render multiline text correctly', () => {
|
|
96
|
+
const multilineMessage = 'Line 1\nLine 2\nLine 3';
|
|
97
|
+
const message = mockChatMessageModelText(false, {
|
|
98
|
+
message: multilineMessage,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
render(message);
|
|
102
|
+
|
|
103
|
+
ChatUiSelectors.chatbotMessageAnswer.should('be.visible');
|
|
104
|
+
ChatUiSelectors.chatbotMessageAnswer.should('contain.text', 'Line 1');
|
|
105
|
+
ChatUiSelectors.chatbotMessageAnswer.should('contain.text', 'Line 2');
|
|
106
|
+
ChatUiSelectors.chatbotMessageAnswer.should('contain.text', 'Line 3');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should trigger scroll when links are toggled for last message', () => {
|
|
110
|
+
const botMessageWithFeedback: Models.IBotMessageWithFeedback = {
|
|
111
|
+
...ModelsMocks.mockBotMessage({ answer: 'Last message with links' }),
|
|
112
|
+
scoredUrls: [
|
|
113
|
+
ModelsMocks.mockScoredUrl({
|
|
114
|
+
url: 'https://example.com/article',
|
|
115
|
+
title: 'Example Article',
|
|
116
|
+
score: 0.9,
|
|
117
|
+
}),
|
|
118
|
+
],
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const message = mockChatMessageModelText(false, {
|
|
122
|
+
message: 'Last message with links',
|
|
123
|
+
data: botMessageWithFeedback,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
render(message, () => {
|
|
127
|
+
// Set this message as the last message in the store
|
|
128
|
+
chatbotUiStore.setMessages([message]);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
cy.wait(1).then(() => {
|
|
132
|
+
// Verify the message is the last one in the store
|
|
133
|
+
expect(chatbotUiStore.messages.at(-1)?.id).to.equal(message.id);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
ChatUiSelectors.chatbotMessageAnswer.should('be.visible');
|
|
137
|
+
|
|
138
|
+
// Toggle links to trigger scroll
|
|
139
|
+
ChatUiSelectors.chatbotLinksMore.click();
|
|
140
|
+
|
|
141
|
+
// Verify scroll was triggered (this would be implementation-specific)
|
|
142
|
+
cy.wait(150); // Wait for setTimeout to complete
|
|
143
|
+
});
|
|
144
|
+
}
|