@servicetitan/titan-chatbot-ui-cypress 3.0.1 → 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 +24 -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/mocks/chatbot-api-client.mock.d.ts +0 -1
- package/dist/mocks/chatbot-api-client.mock.d.ts.map +1 -1
- package/dist/mocks/chatbot-api-client.mock.js +0 -6
- package/dist/mocks/chatbot-api-client.mock.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/mocks/chatbot-api-client.mock.ts +0 -1
- 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,117 @@
|
|
|
1
|
+
import { Container } from '@servicetitan/react-ioc';
|
|
2
|
+
import {
|
|
3
|
+
CHAT_UI_BACKEND_STORE_TOKEN,
|
|
4
|
+
CHAT_UI_STORE_TOKEN,
|
|
5
|
+
ChatUiBackendEchoStore,
|
|
6
|
+
IChatUiBackendStore,
|
|
7
|
+
IChatUiStore,
|
|
8
|
+
} from '@servicetitan/titan-chat-ui-common';
|
|
9
|
+
import { FC } from 'react';
|
|
10
|
+
import { ChatUiSelectors } from '../../utils/chat-ui-selectors';
|
|
11
|
+
import { testInitContainer, testRenderWrapper } from '../../utils/test-utils';
|
|
12
|
+
|
|
13
|
+
interface MessageTimeoutProps {
|
|
14
|
+
onResume: () => void;
|
|
15
|
+
onReset: () => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function runMessageTimeoutSharedTests(MessageTimeoutComponent: FC<MessageTimeoutProps>) {
|
|
19
|
+
let container: Container;
|
|
20
|
+
let chatUiStore: IChatUiStore;
|
|
21
|
+
let chatUiBackendStore: IChatUiBackendStore;
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
container = testInitContainer();
|
|
25
|
+
chatUiStore = container.get<IChatUiStore>(CHAT_UI_STORE_TOKEN);
|
|
26
|
+
chatUiBackendStore = container.get<ChatUiBackendEchoStore>(CHAT_UI_BACKEND_STORE_TOKEN);
|
|
27
|
+
cy.viewport(800, 800);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const render = (onResume?: () => void, onReset?: () => void, onAfterInit?: () => void) =>
|
|
31
|
+
cy
|
|
32
|
+
.wrap(null)
|
|
33
|
+
.then(() =>
|
|
34
|
+
testRenderWrapper(
|
|
35
|
+
chatUiStore,
|
|
36
|
+
chatUiBackendStore,
|
|
37
|
+
<MessageTimeoutComponent
|
|
38
|
+
onResume={onResume ?? cy.spy().as('onResume')}
|
|
39
|
+
onReset={onReset ?? cy.spy().as('onReset')}
|
|
40
|
+
/>,
|
|
41
|
+
onAfterInit
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
it('should render timeout message with proper text content', () => {
|
|
46
|
+
render();
|
|
47
|
+
|
|
48
|
+
ChatUiSelectors.chatMessageTimeout.should('be.visible');
|
|
49
|
+
ChatUiSelectors.chatMessageTimeout.should('contain.text', 'Your session has timed out.');
|
|
50
|
+
ChatUiSelectors.chatMessageTimeout.should(
|
|
51
|
+
'contain.text',
|
|
52
|
+
'Would you like to resume it or start a new one?'
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should render resume and reset links', () => {
|
|
57
|
+
render();
|
|
58
|
+
|
|
59
|
+
ChatUiSelectors.chatMessageTimeoutResume
|
|
60
|
+
.should('be.visible')
|
|
61
|
+
.should('contain.text', 'Continue session');
|
|
62
|
+
|
|
63
|
+
ChatUiSelectors.chatMessageTimeoutReset
|
|
64
|
+
.should('be.visible')
|
|
65
|
+
.should('contain.text', 'Start new session');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should call onResume when continue session link is clicked', () => {
|
|
69
|
+
const onResume = cy.spy().as('onResume');
|
|
70
|
+
render(onResume);
|
|
71
|
+
|
|
72
|
+
ChatUiSelectors.chatMessageTimeoutResume.click();
|
|
73
|
+
cy.get('@onResume').should('have.been.calledOnce');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should call onReset when start new session link is clicked', () => {
|
|
77
|
+
const onReset = cy.spy().as('onReset');
|
|
78
|
+
render(undefined, onReset);
|
|
79
|
+
|
|
80
|
+
ChatUiSelectors.chatMessageTimeoutReset.click();
|
|
81
|
+
cy.get('@onReset').should('have.been.calledOnce');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should handle both callbacks being provided', () => {
|
|
85
|
+
const onResume = cy.spy().as('onResume');
|
|
86
|
+
const onReset = cy.spy().as('onReset');
|
|
87
|
+
render(onResume, onReset);
|
|
88
|
+
|
|
89
|
+
ChatUiSelectors.chatMessageTimeoutResume.click();
|
|
90
|
+
cy.get('@onResume').should('have.been.calledOnce');
|
|
91
|
+
cy.get('@onReset').should('not.have.been.called');
|
|
92
|
+
|
|
93
|
+
ChatUiSelectors.chatMessageTimeoutReset.click();
|
|
94
|
+
cy.get('@onReset').should('have.been.calledOnce');
|
|
95
|
+
cy.get('@onResume').should('have.been.calledOnce');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should have proper data-cy attributes', () => {
|
|
99
|
+
render();
|
|
100
|
+
|
|
101
|
+
ChatUiSelectors.chatMessageTimeout.should(
|
|
102
|
+
'have.attr',
|
|
103
|
+
'data-cy',
|
|
104
|
+
'titan-chat-message-timeout'
|
|
105
|
+
);
|
|
106
|
+
ChatUiSelectors.chatMessageTimeoutResume.should(
|
|
107
|
+
'have.attr',
|
|
108
|
+
'data-cy',
|
|
109
|
+
'titan-chat-message-timeout-resume'
|
|
110
|
+
);
|
|
111
|
+
ChatUiSelectors.chatMessageTimeoutReset.should(
|
|
112
|
+
'have.attr',
|
|
113
|
+
'data-cy',
|
|
114
|
+
'titan-chat-message-timeout-reset'
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Container } from '@servicetitan/react-ioc';
|
|
2
|
+
import {
|
|
3
|
+
CHAT_UI_BACKEND_STORE_TOKEN,
|
|
4
|
+
CHAT_UI_STORE_TOKEN,
|
|
5
|
+
ChatParticipantIcon,
|
|
6
|
+
ChatUiBackendEchoStore,
|
|
7
|
+
IChatUiBackendStore,
|
|
8
|
+
IChatUiStore,
|
|
9
|
+
} from '@servicetitan/titan-chat-ui-common';
|
|
10
|
+
import { FC } from 'react';
|
|
11
|
+
import { ChatUiSelectors } from '../../utils/chat-ui-selectors';
|
|
12
|
+
import { testInitContainer, testRenderWrapper } from '../../utils/test-utils';
|
|
13
|
+
|
|
14
|
+
interface MessageTypingProps {
|
|
15
|
+
avatar: {
|
|
16
|
+
name: string;
|
|
17
|
+
icon: ChatParticipantIcon;
|
|
18
|
+
className?: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function runMessageTypingSharedTests(MessageTypingComponent: FC<MessageTypingProps>) {
|
|
23
|
+
let container: Container;
|
|
24
|
+
let chatUiStore: IChatUiStore;
|
|
25
|
+
let chatUiBackendStore: IChatUiBackendStore;
|
|
26
|
+
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
container = testInitContainer();
|
|
29
|
+
chatUiStore = container.get<IChatUiStore>(CHAT_UI_STORE_TOKEN);
|
|
30
|
+
chatUiBackendStore = container.get<ChatUiBackendEchoStore>(CHAT_UI_BACKEND_STORE_TOKEN);
|
|
31
|
+
cy.viewport(800, 800);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const render = (icon: ChatParticipantIcon, onAfterInit?: () => void) =>
|
|
35
|
+
cy.wrap(null).then(() =>
|
|
36
|
+
testRenderWrapper(
|
|
37
|
+
chatUiStore,
|
|
38
|
+
chatUiBackendStore,
|
|
39
|
+
<MessageTypingComponent
|
|
40
|
+
avatar={{
|
|
41
|
+
name: 'Test User Name',
|
|
42
|
+
icon,
|
|
43
|
+
className: 'custom-class',
|
|
44
|
+
}}
|
|
45
|
+
/>,
|
|
46
|
+
onAfterInit
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
it('should render typing message with proper structure', () => {
|
|
51
|
+
render(ChatParticipantIcon.Bot);
|
|
52
|
+
|
|
53
|
+
ChatUiSelectors.chatMessageTyping.should('be.visible').children().should('have.length', 2);
|
|
54
|
+
ChatUiSelectors.chatMessageTypingDots.should('be.visible');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should render typing message with user icon', () => {
|
|
58
|
+
render(ChatParticipantIcon.Initials);
|
|
59
|
+
|
|
60
|
+
ChatUiSelectors.chatMessageTyping.should('be.visible');
|
|
61
|
+
ChatUiSelectors.chatMessageTypingDots.should('be.visible');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should render typing message with agent icon', () => {
|
|
65
|
+
render(ChatParticipantIcon.Bot);
|
|
66
|
+
|
|
67
|
+
ChatUiSelectors.chatMessageTyping.should('be.visible');
|
|
68
|
+
ChatUiSelectors.chatMessageTypingDots.should('be.visible');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should render typing message with empty icon', () => {
|
|
72
|
+
render(ChatParticipantIcon.Empty);
|
|
73
|
+
|
|
74
|
+
ChatUiSelectors.chatMessageTyping.should('be.visible');
|
|
75
|
+
ChatUiSelectors.chatMessageTypingDots.should('be.visible');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should have proper data-cy attributes', () => {
|
|
79
|
+
render(ChatParticipantIcon.Bot);
|
|
80
|
+
|
|
81
|
+
ChatUiSelectors.chatMessageTyping.should(
|
|
82
|
+
'have.attr',
|
|
83
|
+
'data-cy',
|
|
84
|
+
'titan-chat-message-typing'
|
|
85
|
+
);
|
|
86
|
+
ChatUiSelectors.chatMessageTypingDots.should(
|
|
87
|
+
'have.attr',
|
|
88
|
+
'data-cy',
|
|
89
|
+
'titan-chat-message-typing-dots'
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Container } from '@servicetitan/react-ioc';
|
|
2
|
+
import {
|
|
3
|
+
CHAT_UI_BACKEND_STORE_TOKEN,
|
|
4
|
+
CHAT_UI_STORE_TOKEN,
|
|
5
|
+
ChatUiBackendEchoStore,
|
|
6
|
+
IChatUiBackendStore,
|
|
7
|
+
IChatUiStore,
|
|
8
|
+
} from '@servicetitan/titan-chat-ui-common';
|
|
9
|
+
import { FC, ReactNode } from 'react';
|
|
10
|
+
import { ChatUiSelectors } from '../../utils/chat-ui-selectors';
|
|
11
|
+
import { testInitContainer, testRenderWrapper } from '../../utils/test-utils';
|
|
12
|
+
|
|
13
|
+
interface MessageUserProps {
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
messageFooter?: ReactNode;
|
|
16
|
+
isError?: boolean;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function runMessageUserSharedTests(
|
|
21
|
+
MessageUserComponent: FC<MessageUserProps>,
|
|
22
|
+
TextComponent: FC<any>
|
|
23
|
+
) {
|
|
24
|
+
let container: Container;
|
|
25
|
+
let chatUiStore: IChatUiStore;
|
|
26
|
+
let chatUiBackendStore: IChatUiBackendStore;
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
container = testInitContainer();
|
|
30
|
+
chatUiStore = container.get<IChatUiStore>(CHAT_UI_STORE_TOKEN);
|
|
31
|
+
chatUiBackendStore = container.get<ChatUiBackendEchoStore>(CHAT_UI_BACKEND_STORE_TOKEN);
|
|
32
|
+
cy.viewport(800, 800);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const render = (
|
|
36
|
+
children?: ReactNode,
|
|
37
|
+
messageFooter?: ReactNode,
|
|
38
|
+
isError?: boolean,
|
|
39
|
+
className?: string,
|
|
40
|
+
onAfterInit?: () => void
|
|
41
|
+
) =>
|
|
42
|
+
cy.wrap(null).then(() =>
|
|
43
|
+
testRenderWrapper(
|
|
44
|
+
chatUiStore,
|
|
45
|
+
chatUiBackendStore,
|
|
46
|
+
<MessageUserComponent
|
|
47
|
+
messageFooter={messageFooter}
|
|
48
|
+
isError={isError}
|
|
49
|
+
className={className}
|
|
50
|
+
>
|
|
51
|
+
{children}
|
|
52
|
+
</MessageUserComponent>,
|
|
53
|
+
onAfterInit
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
it('should render user message with basic content', () => {
|
|
58
|
+
render(<TextComponent data-cy="content">message user content</TextComponent>);
|
|
59
|
+
|
|
60
|
+
ChatUiSelectors.chatMessageUser.should('be.visible');
|
|
61
|
+
ChatUiSelectors.chatMessageContent
|
|
62
|
+
.should('be.visible')
|
|
63
|
+
.should('contain.text', 'message user content');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should render user message with long text content', () => {
|
|
67
|
+
const longText = 'message user content '.repeat(100).trim();
|
|
68
|
+
render(<TextComponent data-cy="content">{longText}</TextComponent>);
|
|
69
|
+
|
|
70
|
+
ChatUiSelectors.chatMessageContent.should('be.visible').should('contain.text', longText);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should render user message with footer', () => {
|
|
74
|
+
render(
|
|
75
|
+
<TextComponent data-cy="content">message user content</TextComponent>,
|
|
76
|
+
<TextComponent>message user footer</TextComponent>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
ChatUiSelectors.chatMessageFooter.should('be.visible');
|
|
80
|
+
ChatUiSelectors.chatMessageFooter.should('contain.text', 'message user footer');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should render user message with error state', () => {
|
|
84
|
+
render(
|
|
85
|
+
<TextComponent data-cy="content">error message content</TextComponent>,
|
|
86
|
+
undefined,
|
|
87
|
+
true
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
ChatUiSelectors.chatMessageUser.should('be.visible');
|
|
91
|
+
ChatUiSelectors.chatMessageContent.should('be.visible');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should render user message with custom className', () => {
|
|
95
|
+
render(
|
|
96
|
+
<TextComponent data-cy="content">message content</TextComponent>,
|
|
97
|
+
undefined,
|
|
98
|
+
false,
|
|
99
|
+
'custom-message-class'
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
ChatUiSelectors.chatMessageUser.should('be.visible');
|
|
103
|
+
ChatUiSelectors.chatMessageUser.should('have.class', 'custom-message-class');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('should not render footer when messageFooter is not provided', () => {
|
|
107
|
+
render(<TextComponent data-cy="content">message without footer</TextComponent>);
|
|
108
|
+
|
|
109
|
+
ChatUiSelectors.chatMessageUser.should('be.visible');
|
|
110
|
+
ChatUiSelectors.chatMessageFooter.should('not.exist');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should have proper data-cy attributes for testing', () => {
|
|
114
|
+
render(<TextComponent data-cy="content">test message</TextComponent>);
|
|
115
|
+
|
|
116
|
+
ChatUiSelectors.chatMessageUser.should('have.attr', 'data-cy', 'titan-chat-message-user');
|
|
117
|
+
ChatUiSelectors.chatMessageContent.should(
|
|
118
|
+
'have.attr',
|
|
119
|
+
'data-cy',
|
|
120
|
+
'titan-chat-message-content'
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should render both content and footer when both are provided', () => {
|
|
125
|
+
render(
|
|
126
|
+
<TextComponent data-cy="content">message content</TextComponent>,
|
|
127
|
+
<TextComponent data-cy="footer">message footer</TextComponent>
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
ChatUiSelectors.chatMessageUser.should('be.visible');
|
|
131
|
+
ChatUiSelectors.chatMessageContent
|
|
132
|
+
.should('be.visible')
|
|
133
|
+
.should('contain.text', 'message content');
|
|
134
|
+
ChatUiSelectors.chatMessageFooter
|
|
135
|
+
.should('be.visible')
|
|
136
|
+
.should('contain.text', 'message footer');
|
|
137
|
+
});
|
|
138
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
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 IChatFiltersProps {
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function runChatbotFiltersSharedTests(
|
|
18
|
+
ChatFiltersComponent: FC<IChatFiltersProps>,
|
|
19
|
+
wrapperComponent?: (component: ReactElement) => ReactElement
|
|
20
|
+
) {
|
|
21
|
+
let container: Container;
|
|
22
|
+
let api: CypressMocks.ChatbotApiClientMock;
|
|
23
|
+
let chatbotUiStore: IChatbotUiStore;
|
|
24
|
+
|
|
25
|
+
const filter = (index: number) => ChatUiSelectors.chatbotFilterButton.eq(index);
|
|
26
|
+
const filterOptions = (index: number) =>
|
|
27
|
+
ChatUiSelectors.chatbotFilterOptions.then($options =>
|
|
28
|
+
ChatUiSelectors.chatbotFilterOptions.eq($options.length === 1 ? 0 : index)
|
|
29
|
+
);
|
|
30
|
+
const filterContent = (index: number) => {
|
|
31
|
+
const selector = `[data-cy="${ChatUiSelectors.cy.chatbotFilterContent}"], [data-anvil-component="Popover"]`;
|
|
32
|
+
return cy
|
|
33
|
+
.get(selector)
|
|
34
|
+
.then($options => cy.get(selector).eq($options.length === 1 ? 0 : index));
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const mockApiClient = () => {
|
|
38
|
+
api.postSession = cy.stub().resolves(ModelsMocks.mockSession());
|
|
39
|
+
api.getOptions = cy.stub().resolves(ModelsMocks.mockFrontendModel());
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
container = testInitContainerChatbot();
|
|
44
|
+
api = container.get<CypressMocks.ChatbotApiClientMock>(CHATBOT_API_CLIENT);
|
|
45
|
+
chatbotUiStore = container.get<ChatbotUiStore>(CHATBOT_UI_STORE_TOKEN);
|
|
46
|
+
mockApiClient();
|
|
47
|
+
cy.viewport(550, 800);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const render = (className?: string, onAfterInit?: () => void) => {
|
|
51
|
+
return cy.wrap(null).then(() => {
|
|
52
|
+
const component = (
|
|
53
|
+
<div
|
|
54
|
+
style={{
|
|
55
|
+
position: 'absolute',
|
|
56
|
+
bottom: '2rem',
|
|
57
|
+
left: '2rem',
|
|
58
|
+
width: 'calc(100% - 4rem)',
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
<ChatFiltersComponent className={className} />
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
const wrappedComponent = wrapperComponent ? wrapperComponent(component) : component;
|
|
65
|
+
|
|
66
|
+
return testRenderWrapperChatbot(container, wrappedComponent, onAfterInit);
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
it('should render filters container when filters are available', () => {
|
|
71
|
+
render().then(() => {
|
|
72
|
+
chatbotUiStore.setFilters(ModelsMocks.mockFrontendModel());
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
ChatUiSelectors.chatbotFilters.should('be.visible');
|
|
76
|
+
ChatUiSelectors.chatbotFilterButton.should('have.length', 1);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should not render anything when no filters are available', () => {
|
|
80
|
+
render().then(() => {
|
|
81
|
+
chatbotUiStore.setFilters(ModelsMocks.mockFrontendModelEmpty());
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
ChatUiSelectors.chatbotFilters.should('not.exist');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should apply custom className to filters container', () => {
|
|
88
|
+
const customClass = 'custom-filters-class';
|
|
89
|
+
|
|
90
|
+
render(customClass).then(() => {
|
|
91
|
+
chatbotUiStore.setFilters(ModelsMocks.mockFrontendModel());
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
ChatUiSelectors.chatbotFilters.should('have.class', customClass);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should cascade filters 1', () => {
|
|
98
|
+
render().then(() => {
|
|
99
|
+
chatbotUiStore.setFilters(ModelsMocks.mockFrontendModel());
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
filter(0).click();
|
|
103
|
+
filterOptions(0).within(() => {
|
|
104
|
+
cy.contains('Knowledge Base').should('be.visible');
|
|
105
|
+
cy.contains('Jarvis').should('be.visible').click();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
ChatUiSelectors.chatbotFilterButton.should('have.length', 2);
|
|
109
|
+
filter(0).should('contain.text', 'Sources');
|
|
110
|
+
filter(1).should('contain.text', 'Content Types').click();
|
|
111
|
+
filterOptions(1).within(() => {
|
|
112
|
+
cy.contains('Xxx').should('be.visible').click();
|
|
113
|
+
cy.contains('Yyy').should('be.visible').click();
|
|
114
|
+
cy.contains('Release Notes').should('be.visible').click();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
ChatUiSelectors.chatbotFilterButton.should('have.length', 2);
|
|
118
|
+
filter(0).should('contain.text', 'Sources1');
|
|
119
|
+
filter(1).should('contain.text', 'Content Types3');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should cascade filters 2', () => {
|
|
123
|
+
render().then(() => {
|
|
124
|
+
chatbotUiStore.setFilters(ModelsMocks.mockFrontendModel());
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
filter(0).click();
|
|
128
|
+
filterOptions(0).within(() => {
|
|
129
|
+
cy.contains('Knowledge Base').should('be.visible').click();
|
|
130
|
+
cy.contains('Jarvis').should('be.visible').click();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
ChatUiSelectors.chatbotFilterButton.should('have.length', 3);
|
|
134
|
+
filter(0).should('contain.text', 'Sources');
|
|
135
|
+
filter(1).should('contain.text', 'Content Types').click();
|
|
136
|
+
filter(2).should('contain.text', 'Product Areas');
|
|
137
|
+
filterOptions(1).within(() => {
|
|
138
|
+
cy.contains('Xxx').should('be.visible').click();
|
|
139
|
+
cy.contains('Yyy').should('be.visible').click();
|
|
140
|
+
cy.contains('FAQ').should('be.visible').click();
|
|
141
|
+
cy.contains('How To').should('be.visible').click();
|
|
142
|
+
cy.contains('Release Notes').should('be.visible').click();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
filter(2).should('contain.text', 'Product Areas').click();
|
|
146
|
+
filterOptions(2).within(() => {
|
|
147
|
+
cy.contains('Call Booking').should('be.visible').click();
|
|
148
|
+
cy.contains('Marketing').should('be.visible').click();
|
|
149
|
+
cy.contains('Marketing Pro').should('be.visible').click();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
ChatUiSelectors.chatbotFilterButton.should('have.length', 3);
|
|
153
|
+
filter(0).should('contain.text', 'Sources2');
|
|
154
|
+
filter(1).should('contain.text', 'Content Types5');
|
|
155
|
+
filter(2).should('contain.text', 'Product Areas3');
|
|
156
|
+
|
|
157
|
+
filter(0).click();
|
|
158
|
+
filterContent(0).within(() => {
|
|
159
|
+
ChatUiSelectors.chatbotFilterNone.click();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
ChatUiSelectors.chatbotFilterButton.should('have.length', 1);
|
|
163
|
+
});
|
|
164
|
+
}
|