@servicetitan/titan-chatbot-ui-cypress 3.1.1 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/index.d.ts +0 -3
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +0 -3
  5. package/dist/index.js.map +1 -1
  6. package/dist/utils/chat-ui-selectors.d.ts +2 -0
  7. package/dist/utils/chat-ui-selectors.d.ts.map +1 -1
  8. package/dist/utils/chat-ui-selectors.js +4 -0
  9. package/dist/utils/chat-ui-selectors.js.map +1 -1
  10. package/package.json +5 -12
  11. package/src/index.ts +0 -3
  12. package/src/utils/chat-ui-selectors.ts +4 -0
  13. package/tsconfig.tsbuildinfo +1 -1
  14. package/dist/tests/index.d.ts +0 -30
  15. package/dist/tests/index.d.ts.map +0 -1
  16. package/dist/tests/index.js +0 -30
  17. package/dist/tests/index.js.map +0 -1
  18. package/dist/tests/titan-chat-ui/chat-error.shared-tests.d.ts +0 -3
  19. package/dist/tests/titan-chat-ui/chat-error.shared-tests.d.ts.map +0 -1
  20. package/dist/tests/titan-chat-ui/chat-error.shared-tests.js +0 -138
  21. package/dist/tests/titan-chat-ui/chat-error.shared-tests.js.map +0 -1
  22. package/dist/tests/titan-chat-ui/chat-input-file.shared-tests.d.ts +0 -7
  23. package/dist/tests/titan-chat-ui/chat-input-file.shared-tests.d.ts.map +0 -1
  24. package/dist/tests/titan-chat-ui/chat-input-file.shared-tests.js +0 -123
  25. package/dist/tests/titan-chat-ui/chat-input-file.shared-tests.js.map +0 -1
  26. package/dist/tests/titan-chat-ui/chat-input.shared-tests.d.ts +0 -3
  27. package/dist/tests/titan-chat-ui/chat-input.shared-tests.d.ts.map +0 -1
  28. package/dist/tests/titan-chat-ui/chat-input.shared-tests.js +0 -71
  29. package/dist/tests/titan-chat-ui/chat-input.shared-tests.js.map +0 -1
  30. package/dist/tests/titan-chat-ui/chat-log.shared-tests.d.ts +0 -9
  31. package/dist/tests/titan-chat-ui/chat-log.shared-tests.d.ts.map +0 -1
  32. package/dist/tests/titan-chat-ui/chat-log.shared-tests.js +0 -73
  33. package/dist/tests/titan-chat-ui/chat-log.shared-tests.js.map +0 -1
  34. package/dist/tests/titan-chat-ui/chat-messages.shared-tests.d.ts +0 -8
  35. package/dist/tests/titan-chat-ui/chat-messages.shared-tests.d.ts.map +0 -1
  36. package/dist/tests/titan-chat-ui/chat-messages.shared-tests.js +0 -118
  37. package/dist/tests/titan-chat-ui/chat-messages.shared-tests.js.map +0 -1
  38. package/dist/tests/titan-chat-ui/chat-notifications.shared-tests.d.ts +0 -3
  39. package/dist/tests/titan-chat-ui/chat-notifications.shared-tests.d.ts.map +0 -1
  40. package/dist/tests/titan-chat-ui/chat-notifications.shared-tests.js +0 -110
  41. package/dist/tests/titan-chat-ui/chat-notifications.shared-tests.js.map +0 -1
  42. package/dist/tests/titan-chat-ui/chat-timer.shared-tests.d.ts +0 -3
  43. package/dist/tests/titan-chat-ui/chat-timer.shared-tests.d.ts.map +0 -1
  44. package/dist/tests/titan-chat-ui/chat-timer.shared-tests.js +0 -76
  45. package/dist/tests/titan-chat-ui/chat-timer.shared-tests.js.map +0 -1
  46. package/dist/tests/titan-chat-ui/chat.shared-tests.d.ts +0 -9
  47. package/dist/tests/titan-chat-ui/chat.shared-tests.d.ts.map +0 -1
  48. package/dist/tests/titan-chat-ui/chat.shared-tests.js +0 -111
  49. package/dist/tests/titan-chat-ui/chat.shared-tests.js.map +0 -1
  50. package/dist/tests/titan-chat-ui/message-agent.shared-tests.d.ts +0 -27
  51. package/dist/tests/titan-chat-ui/message-agent.shared-tests.d.ts.map +0 -1
  52. package/dist/tests/titan-chat-ui/message-agent.shared-tests.js +0 -67
  53. package/dist/tests/titan-chat-ui/message-agent.shared-tests.js.map +0 -1
  54. package/dist/tests/titan-chat-ui/message-content-file.shared-tests.d.ts +0 -10
  55. package/dist/tests/titan-chat-ui/message-content-file.shared-tests.d.ts.map +0 -1
  56. package/dist/tests/titan-chat-ui/message-content-file.shared-tests.js +0 -88
  57. package/dist/tests/titan-chat-ui/message-content-file.shared-tests.js.map +0 -1
  58. package/dist/tests/titan-chat-ui/message-system.shared-tests.d.ts +0 -16
  59. package/dist/tests/titan-chat-ui/message-system.shared-tests.d.ts.map +0 -1
  60. package/dist/tests/titan-chat-ui/message-system.shared-tests.js +0 -65
  61. package/dist/tests/titan-chat-ui/message-system.shared-tests.js.map +0 -1
  62. package/dist/tests/titan-chat-ui/message-timeout.shared-tests.d.ts +0 -8
  63. package/dist/tests/titan-chat-ui/message-timeout.shared-tests.d.ts.map +0 -1
  64. package/dist/tests/titan-chat-ui/message-timeout.shared-tests.js +0 -63
  65. package/dist/tests/titan-chat-ui/message-timeout.shared-tests.js.map +0 -1
  66. package/dist/tests/titan-chat-ui/message-typing.shared-tests.d.ts +0 -12
  67. package/dist/tests/titan-chat-ui/message-typing.shared-tests.d.ts.map +0 -1
  68. package/dist/tests/titan-chat-ui/message-typing.shared-tests.js +0 -46
  69. package/dist/tests/titan-chat-ui/message-typing.shared-tests.js.map +0 -1
  70. package/dist/tests/titan-chat-ui/message-user.shared-tests.d.ts +0 -10
  71. package/dist/tests/titan-chat-ui/message-user.shared-tests.d.ts.map +0 -1
  72. package/dist/tests/titan-chat-ui/message-user.shared-tests.js +0 -64
  73. package/dist/tests/titan-chat-ui/message-user.shared-tests.js.map +0 -1
  74. package/dist/tests/titan-chatbot-ui/chatbot-filters.shared-tests.d.ts +0 -7
  75. package/dist/tests/titan-chatbot-ui/chatbot-filters.shared-tests.d.ts.map +0 -1
  76. package/dist/tests/titan-chatbot-ui/chatbot-filters.shared-tests.js +0 -118
  77. package/dist/tests/titan-chatbot-ui/chatbot-filters.shared-tests.js.map +0 -1
  78. package/dist/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.d.ts +0 -9
  79. package/dist/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.d.ts.map +0 -1
  80. package/dist/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.js +0 -162
  81. package/dist/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.js.map +0 -1
  82. package/dist/tests/titan-chatbot-ui/chatbot-links.shared-tests.d.ts +0 -15
  83. package/dist/tests/titan-chatbot-ui/chatbot-links.shared-tests.d.ts.map +0 -1
  84. package/dist/tests/titan-chatbot-ui/chatbot-links.shared-tests.js +0 -123
  85. package/dist/tests/titan-chatbot-ui/chatbot-links.shared-tests.js.map +0 -1
  86. package/dist/tests/titan-chatbot-ui/chatbot-live.shared-tests.d.ts +0 -9
  87. package/dist/tests/titan-chatbot-ui/chatbot-live.shared-tests.d.ts.map +0 -1
  88. package/dist/tests/titan-chatbot-ui/chatbot-live.shared-tests.js +0 -84
  89. package/dist/tests/titan-chatbot-ui/chatbot-live.shared-tests.js.map +0 -1
  90. package/dist/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.d.ts +0 -8
  91. package/dist/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.d.ts.map +0 -1
  92. package/dist/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.js +0 -142
  93. package/dist/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.js.map +0 -1
  94. package/dist/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.d.ts +0 -8
  95. package/dist/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.d.ts.map +0 -1
  96. package/dist/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.js +0 -105
  97. package/dist/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.js.map +0 -1
  98. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.d.ts +0 -3
  99. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.d.ts.map +0 -1
  100. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.js +0 -86
  101. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.js.map +0 -1
  102. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.d.ts +0 -3
  103. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.d.ts.map +0 -1
  104. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.js +0 -143
  105. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.js.map +0 -1
  106. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.d.ts +0 -8
  107. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.d.ts.map +0 -1
  108. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.js +0 -200
  109. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.js.map +0 -1
  110. package/dist/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.d.ts +0 -11
  111. package/dist/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.d.ts.map +0 -1
  112. package/dist/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.js +0 -81
  113. package/dist/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.js.map +0 -1
  114. package/dist/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.d.ts +0 -8
  115. package/dist/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.d.ts.map +0 -1
  116. package/dist/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.js +0 -60
  117. package/dist/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.js.map +0 -1
  118. package/dist/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.d.ts +0 -8
  119. package/dist/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.d.ts.map +0 -1
  120. package/dist/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.js +0 -77
  121. package/dist/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.js.map +0 -1
  122. package/dist/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.d.ts +0 -7
  123. package/dist/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.d.ts.map +0 -1
  124. package/dist/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.js +0 -130
  125. package/dist/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.js.map +0 -1
  126. package/dist/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.d.ts +0 -9
  127. package/dist/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.d.ts.map +0 -1
  128. package/dist/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.js +0 -157
  129. package/dist/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.js.map +0 -1
  130. package/dist/tests/titan-chatbot-ui/chatbot.shared-tests.d.ts +0 -9
  131. package/dist/tests/titan-chatbot-ui/chatbot.shared-tests.d.ts.map +0 -1
  132. package/dist/tests/titan-chatbot-ui/chatbot.shared-tests.js +0 -114
  133. package/dist/tests/titan-chatbot-ui/chatbot.shared-tests.js.map +0 -1
  134. package/dist/utils/test-utils-chatbot.d.ts +0 -5
  135. package/dist/utils/test-utils-chatbot.d.ts.map +0 -1
  136. package/dist/utils/test-utils-chatbot.js +0 -55
  137. package/dist/utils/test-utils-chatbot.js.map +0 -1
  138. package/dist/utils/test-utils.d.ts +0 -6
  139. package/dist/utils/test-utils.d.ts.map +0 -1
  140. package/dist/utils/test-utils.js +0 -38
  141. package/dist/utils/test-utils.js.map +0 -1
  142. package/src/tests/index.ts +0 -30
  143. package/src/tests/titan-chat-ui/chat-error.shared-tests.tsx +0 -185
  144. package/src/tests/titan-chat-ui/chat-input-file.shared-tests.tsx +0 -182
  145. package/src/tests/titan-chat-ui/chat-input.shared-tests.tsx +0 -99
  146. package/src/tests/titan-chat-ui/chat-log.shared-tests.tsx +0 -117
  147. package/src/tests/titan-chat-ui/chat-messages.shared-tests.tsx +0 -156
  148. package/src/tests/titan-chat-ui/chat-notifications.shared-tests.tsx +0 -153
  149. package/src/tests/titan-chat-ui/chat-timer.shared-tests.tsx +0 -106
  150. package/src/tests/titan-chat-ui/chat.shared-tests.tsx +0 -158
  151. package/src/tests/titan-chat-ui/message-agent.shared-tests.tsx +0 -170
  152. package/src/tests/titan-chat-ui/message-content-file.shared-tests.tsx +0 -139
  153. package/src/tests/titan-chat-ui/message-system.shared-tests.tsx +0 -147
  154. package/src/tests/titan-chat-ui/message-timeout.shared-tests.tsx +0 -117
  155. package/src/tests/titan-chat-ui/message-typing.shared-tests.tsx +0 -92
  156. package/src/tests/titan-chat-ui/message-user.shared-tests.tsx +0 -138
  157. package/src/tests/titan-chatbot-ui/chatbot-filters.shared-tests.tsx +0 -164
  158. package/src/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.tsx +0 -225
  159. package/src/tests/titan-chatbot-ui/chatbot-links.shared-tests.tsx +0 -189
  160. package/src/tests/titan-chatbot-ui/chatbot-live.shared-tests.tsx +0 -127
  161. package/src/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.tsx +0 -187
  162. package/src/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.tsx +0 -144
  163. package/src/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.tsx +0 -127
  164. package/src/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.tsx +0 -198
  165. package/src/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.tsx +0 -285
  166. package/src/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.tsx +0 -112
  167. package/src/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.tsx +0 -91
  168. package/src/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.tsx +0 -116
  169. package/src/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.tsx +0 -182
  170. package/src/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.tsx +0 -221
  171. package/src/tests/titan-chatbot-ui/chatbot.shared-tests.tsx +0 -158
  172. package/src/utils/test-utils-chatbot.tsx +0 -73
  173. package/src/utils/test-utils.tsx +0 -52
@@ -1,99 +0,0 @@
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
- export function runChatInputSharedTests(ChatInputComponent: FC) {
14
- let container: Container;
15
- let chatUiStore: IChatUiStore;
16
- let chatUiBackendStore: IChatUiBackendStore;
17
-
18
- beforeEach(() => {
19
- container = testInitContainer();
20
- chatUiStore = container.get<IChatUiStore>(CHAT_UI_STORE_TOKEN);
21
- chatUiBackendStore = container.get<ChatUiBackendEchoStore>(CHAT_UI_BACKEND_STORE_TOKEN);
22
- cy.viewport(800, 800);
23
- });
24
-
25
- const render = (onAfterInit?: () => void) =>
26
- cy
27
- .wrap(null)
28
- .then(() =>
29
- testRenderWrapper(
30
- chatUiStore,
31
- chatUiBackendStore,
32
- <ChatInputComponent />,
33
- onAfterInit
34
- )
35
- );
36
-
37
- it('should render chat input', () => {
38
- render();
39
- ChatUiSelectors.chatInput.should('be.visible');
40
- ChatUiSelectors.chatSend.should('be.visible');
41
- });
42
-
43
- it('should send message when send button is clicked', () => {
44
- render(() => {
45
- cy.spy(chatUiStore, 'sendMessageText').as('sendMessageSpy');
46
- });
47
-
48
- const text = 'Hello, world! '.repeat(30).trim();
49
- ChatUiSelectors.chatInput.type(text, { delay: 0 });
50
- cy.wait(1);
51
- ChatUiSelectors.chatInput.should('have.value', text);
52
- ChatUiSelectors.chatSend.click();
53
- ChatUiSelectors.chatInput.should('have.value', '');
54
- cy.get('@sendMessageSpy').should('have.been.calledWith', text);
55
- });
56
-
57
- it('should send message when Enter key is pressed', () => {
58
- render(() => {
59
- cy.spy(chatUiStore, 'sendMessageText').as('sendMessageSpy');
60
- });
61
-
62
- const text = 'Test message with Enter key';
63
- ChatUiSelectors.chatInput.type(text, { delay: 0 });
64
- cy.wait(1);
65
- ChatUiSelectors.chatInput.type('{enter}');
66
- ChatUiSelectors.chatInput.should('have.value', '');
67
- cy.get('@sendMessageSpy').should('have.been.calledWith', text);
68
- });
69
-
70
- it('should not send empty message', () => {
71
- render(() => {
72
- cy.spy(chatUiStore, 'sendMessageText').as('sendMessageSpy');
73
- });
74
-
75
- ChatUiSelectors.chatInput.type(' ', { delay: 0 });
76
- cy.wait(1);
77
- ChatUiSelectors.chatSend.click();
78
- cy.get('@sendMessageSpy').should('not.have.been.called');
79
- ChatUiSelectors.chatInput.should('have.value', ' ');
80
- });
81
-
82
- it('should handle long text input', () => {
83
- render();
84
-
85
- const longText = 'This is a very long message that exceeds normal length. '.repeat(50);
86
- ChatUiSelectors.chatInput.type(longText, { delay: 0 });
87
- ChatUiSelectors.chatInput.should('have.value', longText);
88
- });
89
-
90
- it('should disable send button when input is empty', () => {
91
- render();
92
-
93
- ChatUiSelectors.chatSend.should('be.disabled');
94
- ChatUiSelectors.chatInput.type('Some text', { delay: 0 });
95
- ChatUiSelectors.chatSend.should('not.be.disabled');
96
- ChatUiSelectors.chatInput.clear();
97
- ChatUiSelectors.chatSend.should('be.disabled');
98
- });
99
- }
@@ -1,117 +0,0 @@
1
- import { Container } from '@servicetitan/react-ioc';
2
- import {
3
- CHAT_UI_BACKEND_STORE_TOKEN,
4
- CHAT_UI_STORE_TOKEN,
5
- ChatCustomizations,
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 ChatLogProps {
15
- className?: string;
16
- customizations?: ChatCustomizations;
17
- }
18
-
19
- export function runChatLogSharedTests(ChatLogComponent: FC<ChatLogProps>) {
20
- let container: Container;
21
- let chatUiStore: IChatUiStore;
22
- let chatUiBackendStore: IChatUiBackendStore;
23
-
24
- beforeEach(() => {
25
- container = testInitContainer();
26
- chatUiStore = container.get<IChatUiStore>(CHAT_UI_STORE_TOKEN);
27
- chatUiBackendStore = container.get<ChatUiBackendEchoStore>(CHAT_UI_BACKEND_STORE_TOKEN);
28
- cy.viewport(800, 800);
29
- });
30
-
31
- const render = (
32
- className?: string,
33
- customizations?: ChatCustomizations,
34
- onAfterInit?: () => void
35
- ) =>
36
- cy
37
- .wrap(null)
38
- .then(() =>
39
- testRenderWrapper(
40
- chatUiStore,
41
- chatUiBackendStore,
42
- <ChatLogComponent className={className} customizations={customizations} />,
43
- onAfterInit
44
- )
45
- );
46
-
47
- it('should render chat log with titan-chat data-cy attribute', () => {
48
- render();
49
-
50
- ChatUiSelectors.chat.should('be.visible');
51
- ChatUiSelectors.chatMessages.should('exist');
52
- });
53
-
54
- it('should apply custom className', () => {
55
- const customClass = 'custom-chat-class';
56
- render(customClass);
57
-
58
- ChatUiSelectors.chat.should('have.class', customClass);
59
- });
60
-
61
- it('should set customization context on mount', () => {
62
- const customizations: ChatCustomizations = {
63
- input: {
64
- isDisabled: true,
65
- },
66
- };
67
-
68
- render(undefined, customizations);
69
-
70
- ChatUiSelectors.chat.should('be.visible');
71
- cy.wait(1).then(() => {
72
- expect(chatUiStore.customizations).to.deep.equal(customizations);
73
- });
74
- });
75
-
76
- it('should display messages from store', () => {
77
- render(undefined, undefined, () => {
78
- chatUiStore.addMessage(true, 'Hello from agent');
79
- chatUiStore.addMessage(false, 'Hello from user');
80
- });
81
-
82
- ChatUiSelectors.chatMessage.should('have.length', 3); // 1st message is the welcome message
83
- });
84
-
85
- it('should show typing indicator when agent is typing', () => {
86
- render(undefined, undefined, () => {
87
- chatUiStore.setAgentTyping(true);
88
- });
89
-
90
- ChatUiSelectors.chatMessageTyping.should('be.visible');
91
- });
92
-
93
- it('should hide typing indicator when agent is not typing', () => {
94
- render(undefined, undefined, () => {
95
- chatUiStore.setAgentTyping(false);
96
- });
97
-
98
- ChatUiSelectors.chatMessageTyping.should('not.exist');
99
- });
100
-
101
- it('should update customization context when customizations prop changes', () => {
102
- const initialCustomizations: ChatCustomizations = {
103
- input: {
104
- isDisabled: false,
105
- },
106
- };
107
-
108
- render(undefined, initialCustomizations);
109
-
110
- cy.get('[data-cy="titan-chat"]').should('be.visible');
111
-
112
- // Verify initial customizations are set
113
- cy.wrap(null).then(() => {
114
- expect(chatUiStore.customizations).to.deep.equal(initialCustomizations);
115
- });
116
- });
117
- }
@@ -1,156 +0,0 @@
1
- import { Container } from '@servicetitan/react-ioc';
2
- import {
3
- CHAT_UI_BACKEND_STORE_TOKEN,
4
- CHAT_UI_STORE_TOKEN,
5
- ChatMessageModelBase,
6
- ChatUiBackendEchoStore,
7
- IChatUiBackendStore,
8
- IChatUiStore,
9
- mockChatMessageModelText,
10
- } from '@servicetitan/titan-chat-ui-common';
11
- import { FC } from 'react';
12
- import { ChatUiSelectors } from '../../utils/chat-ui-selectors';
13
- import { testInitContainer, testRenderWrapper } from '../../utils/test-utils';
14
-
15
- export function runChatMessagesSharedTests(
16
- ChatMessagesComponent: FC<{
17
- className?: string;
18
- messages: ChatMessageModelBase[];
19
- showTypingIndicator?: boolean;
20
- }>
21
- ) {
22
- let container: Container;
23
- let chatUiStore: IChatUiStore;
24
- let chatUiBackendStore: IChatUiBackendStore;
25
-
26
- beforeEach(() => {
27
- container = testInitContainer();
28
- chatUiStore = container.get<IChatUiStore>(CHAT_UI_STORE_TOKEN);
29
- chatUiBackendStore = container.get<ChatUiBackendEchoStore>(CHAT_UI_BACKEND_STORE_TOKEN);
30
- cy.viewport(800, 800);
31
- // cy.clock(new Date('2023-10-01T10:10:00Z').getTime());
32
- });
33
-
34
- const render = (messages: ChatMessageModelBase[], onAfterInit?: () => void) =>
35
- cy
36
- .wrap(null)
37
- .then(() =>
38
- testRenderWrapper(
39
- chatUiStore,
40
- chatUiBackendStore,
41
- <ChatMessagesComponent messages={messages} />,
42
- onAfterInit
43
- )
44
- );
45
-
46
- it('should render default chat', () => {
47
- render([]);
48
-
49
- ChatUiSelectors.chatMessages.should('exist');
50
- ChatUiSelectors.chatMessage.should('have.length', 0);
51
- });
52
-
53
- it('should render several consecutive agent messages without extra avatars', () => {
54
- render([
55
- mockChatMessageModelText(true, {
56
- id: 'id1',
57
- timestamp: new Date('2023-01-01T10:10:00Z'),
58
- message: 'Hello, this is the first message',
59
- }),
60
- mockChatMessageModelText(true, {
61
- id: 'id2',
62
- message: 'Hello, this is the second message. '.repeat(5).trim(),
63
- timestamp: new Date('2023-01-01T10:10:59.999Z'),
64
- }),
65
- mockChatMessageModelText(true, {
66
- id: 'id3',
67
- message: 'Hello, this is the third message',
68
- timestamp: new Date('2023-01-01T10:11:00Z'),
69
- }),
70
- mockChatMessageModelText(true, {
71
- id: 'id4',
72
- message: 'Hello, this is the forth message',
73
- timestamp: new Date('2023-01-01T10:11:01Z'),
74
- }),
75
- mockChatMessageModelText(false, {
76
- id: 'id11',
77
- timestamp: new Date('2023-01-01T11:10:00Z'),
78
- message: 'Hello, this is the first message',
79
- }),
80
- mockChatMessageModelText(false, {
81
- id: 'id22',
82
- message: 'Hello, this is the second message',
83
- timestamp: new Date('2023-01-01T11:11:00Z'),
84
- }),
85
- mockChatMessageModelText(false, {
86
- id: 'id33',
87
- message: 'Hello, this is the third message',
88
- timestamp: new Date('2023-01-01T11:12:00Z'),
89
- }),
90
- mockChatMessageModelText(false, {
91
- id: 'id44',
92
- message: 'Hello, this is the forth message',
93
- timestamp: new Date('2023-01-01T11:12:01Z'),
94
- }),
95
- ]);
96
-
97
- const getTimestamp = (i: number) =>
98
- ChatUiSelectors.chatMessage
99
- .eq(i)
100
- .find(`[data-cy="${ChatUiSelectors.cy.chatMessageFooter}"]`);
101
-
102
- ChatUiSelectors.chatMessageAgent.should('have.length', 4);
103
- ChatUiSelectors.chatMessageUser.should('have.length', 4);
104
-
105
- // Agent avatar should be visible only for the first message in group
106
- const getAvatar = (i: number) =>
107
- ChatUiSelectors.chatMessageAgent
108
- .find(`[data-cy="${ChatUiSelectors.cy.chatAvatar}"]`)
109
- .eq(i);
110
- getAvatar(0).should('be.visible');
111
- getAvatar(1).should('not.exist');
112
- getAvatar(2).should('not.exist');
113
- getAvatar(3).should('not.exist');
114
-
115
- // Footer with date should be visible only for the different formatted timestamps
116
- getTimestamp(0).should('not.exist');
117
- getTimestamp(1).should('be.visible').should('contain.text', 'agent • 10:10 AM');
118
- getTimestamp(2).should('not.exist');
119
- getTimestamp(3).should('be.visible').should('contain.text', 'agent • 10:11 AM');
120
- getTimestamp(4).should('be.visible').should('contain.text', '11:10 AM');
121
- getTimestamp(5).should('be.visible').should('contain.text', '11:11 AM');
122
- getTimestamp(6).should('not.exist');
123
- getTimestamp(7).should('be.visible').should('contain.text', '11:12 AM');
124
- });
125
-
126
- it('should render empty state when no messages', () => {
127
- render([]);
128
-
129
- ChatUiSelectors.chatMessages.should('exist');
130
- ChatUiSelectors.chatMessage.should('have.length', 0);
131
- });
132
-
133
- it('should handle mixed message types correctly', () => {
134
- render([
135
- mockChatMessageModelText(false, {
136
- id: 'user1',
137
- timestamp: new Date('2023-01-01T10:00:00Z'),
138
- message: 'User message first',
139
- }),
140
- mockChatMessageModelText(true, {
141
- id: 'agent1',
142
- timestamp: new Date('2023-01-01T10:01:00Z'),
143
- message: 'Agent response',
144
- }),
145
- mockChatMessageModelText(false, {
146
- id: 'user2',
147
- timestamp: new Date('2023-01-01T10:02:00Z'),
148
- message: 'User follow-up',
149
- }),
150
- ]);
151
-
152
- ChatUiSelectors.chatMessage.should('have.length', 3);
153
- ChatUiSelectors.chatMessageUser.should('have.length', 2);
154
- ChatUiSelectors.chatMessageAgent.should('have.length', 1);
155
- });
156
- }
@@ -1,153 +0,0 @@
1
- import { Container } from '@servicetitan/react-ioc';
2
- import {
3
- CHAT_UI_BACKEND_STORE_TOKEN,
4
- CHAT_UI_STORE_TOKEN,
5
- ChatRunState,
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
- export const runChatNotificationsTests = (ChatNotifications: FC) => {
15
- let container: Container;
16
- let chatUiStore: IChatUiStore;
17
- let chatUiBackendStore: IChatUiBackendStore;
18
-
19
- beforeEach(() => {
20
- container = testInitContainer();
21
- chatUiStore = container.get<IChatUiStore>(CHAT_UI_STORE_TOKEN);
22
- chatUiBackendStore = container.get<ChatUiBackendEchoStore>(CHAT_UI_BACKEND_STORE_TOKEN);
23
- cy.viewport(800, 800);
24
- });
25
-
26
- const render = (onAfterInit?: () => void) =>
27
- cy
28
- .wrap(null)
29
- .then(() =>
30
- testRenderWrapper(
31
- chatUiStore,
32
- chatUiBackendStore,
33
- <ChatNotifications />,
34
- onAfterInit
35
- )
36
- );
37
-
38
- it('should render notifications container', () => {
39
- render();
40
- ChatUiSelectors.chatNotifications.should('exist');
41
- });
42
-
43
- it('should show timer when timer is set and no error', () => {
44
- render(() => {
45
- chatUiStore.setTimer({
46
- secondsLeft: 30,
47
- secondsTotal: 60,
48
- });
49
- chatUiStore.setStatus(ChatRunState.Started);
50
- });
51
-
52
- ChatUiSelectors.chatNotifications.should('be.visible');
53
- ChatUiSelectors.chatTimer.should('be.visible');
54
- ChatUiSelectors.chatError.should('not.exist');
55
- });
56
-
57
- it('should show error when error is present', () => {
58
- render(() => {
59
- chatUiStore.setError('Test error message');
60
- });
61
-
62
- ChatUiSelectors.chatNotifications.should('be.visible');
63
- ChatUiSelectors.chatError.should('be.visible');
64
- ChatUiSelectors.chatTimer.should('not.exist');
65
- });
66
-
67
- it('should hide timer when error is present', () => {
68
- render(() => {
69
- chatUiStore.setTimer({
70
- secondsLeft: 30,
71
- secondsTotal: 60,
72
- });
73
- chatUiStore.setError('Test error message');
74
- });
75
-
76
- ChatUiSelectors.chatNotifications.should('be.visible');
77
- ChatUiSelectors.chatError.should('be.visible');
78
- ChatUiSelectors.chatTimer.should('not.exist');
79
- });
80
-
81
- it('should be empty when no timer and no error', () => {
82
- render(() => {
83
- chatUiStore.resetError(ChatRunState.Started);
84
- chatUiStore.setTimer(undefined);
85
- });
86
-
87
- ChatUiSelectors.chatNotifications.should('exist');
88
- ChatUiSelectors.chatTimer.should('not.exist');
89
- ChatUiSelectors.chatError.should('not.exist');
90
- });
91
-
92
- it('should update when timer is added', () => {
93
- render();
94
-
95
- ChatUiSelectors.chatTimer.should('not.exist');
96
-
97
- cy.then(() => {
98
- chatUiStore.setTimer({
99
- secondsLeft: 30,
100
- secondsTotal: 60,
101
- });
102
- chatUiStore.setStatus(ChatRunState.Started);
103
- });
104
-
105
- ChatUiSelectors.chatTimer.should('be.visible');
106
- });
107
-
108
- it('should update when error is added', () => {
109
- render();
110
-
111
- ChatUiSelectors.chatError.should('not.exist');
112
-
113
- cy.then(() => {
114
- chatUiStore.setError('New error message');
115
- });
116
-
117
- ChatUiSelectors.chatError.should('be.visible');
118
- });
119
-
120
- it('should switch from timer to error when error occurs', () => {
121
- render(() => {
122
- chatUiStore.setTimer({
123
- secondsLeft: 30,
124
- secondsTotal: 60,
125
- });
126
- chatUiStore.setStatus(ChatRunState.Started);
127
- });
128
-
129
- ChatUiSelectors.chatTimer.should('be.visible');
130
- ChatUiSelectors.chatError.should('not.exist');
131
-
132
- cy.then(() => {
133
- chatUiStore.setError('Error occurred');
134
- });
135
-
136
- ChatUiSelectors.chatError.should('be.visible');
137
- ChatUiSelectors.chatTimer.should('not.exist');
138
- });
139
-
140
- it('should handle error recovery', () => {
141
- render(() => {
142
- chatUiStore.setError('Test error');
143
- });
144
-
145
- ChatUiSelectors.chatError.should('be.visible');
146
-
147
- cy.then(() => {
148
- chatUiStore.resetError(ChatRunState.Started);
149
- });
150
-
151
- ChatUiSelectors.chatError.should('not.exist');
152
- });
153
- };
@@ -1,106 +0,0 @@
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
- export const runChatTimerTests = (ChatTimer: FC) => {
14
- let container: Container;
15
- let chatUiStore: IChatUiStore;
16
- let chatUiBackendStore: IChatUiBackendStore;
17
-
18
- beforeEach(() => {
19
- container = testInitContainer();
20
- chatUiStore = container.get<IChatUiStore>(CHAT_UI_STORE_TOKEN);
21
- chatUiBackendStore = container.get<ChatUiBackendEchoStore>(CHAT_UI_BACKEND_STORE_TOKEN);
22
- cy.viewport(800, 800);
23
- });
24
-
25
- const render = (onAfterInit?: () => void) =>
26
- cy
27
- .wrap(null)
28
- .then(() =>
29
- testRenderWrapper(chatUiStore, chatUiBackendStore, <ChatTimer />, onAfterInit)
30
- );
31
-
32
- it('should not render when timer is not set', () => {
33
- render();
34
- ChatUiSelectors.chatTimer.should('not.exist');
35
- });
36
-
37
- it('should render timer when timer is set', () => {
38
- render(() => {
39
- chatUiStore.setTimer({ secondsLeft: 30, secondsTotal: 60 });
40
- });
41
-
42
- ChatUiSelectors.chatTimer.should('be.visible');
43
- ChatUiSelectors.chatTimer.should('contain.text', 'Chat inactive');
44
- ChatUiSelectors.chatTimer.should(
45
- 'contain.text',
46
- 'Are you still there? Please respond within'
47
- );
48
- ChatUiSelectors.chatTimer.should('contain.text', '30s');
49
- ChatUiSelectors.chatTimer.should('contain.text', 'or this chat will time out.');
50
- });
51
-
52
- it('should display correct seconds left', () => {
53
- render(() => {
54
- chatUiStore.setTimer({ secondsLeft: 45, secondsTotal: 60 });
55
- });
56
-
57
- ChatUiSelectors.chatTimer.should('contain.text', '45s');
58
- });
59
-
60
- it('should render restart button with correct text', () => {
61
- render(() => {
62
- chatUiStore.setTimer({ secondsLeft: 30, secondsTotal: 60 });
63
- });
64
-
65
- ChatUiSelectors.chatTimerRestart.should('be.visible');
66
- ChatUiSelectors.chatTimerRestart.should('contain.text', "I'm here");
67
- });
68
-
69
- it('should call restartTimers when restart button is clicked', () => {
70
- render(() => {
71
- chatUiStore.setTimer({ secondsLeft: 30, secondsTotal: 60 });
72
- cy.spy(chatUiStore, 'restartTimers').as('restartTimersSpy');
73
- });
74
-
75
- ChatUiSelectors.chatTimerRestart.click();
76
- cy.get('@restartTimersSpy').should('have.been.called');
77
- });
78
-
79
- it('should update display when timer seconds change', () => {
80
- render(() => {
81
- chatUiStore.setTimer({ secondsLeft: 30, secondsTotal: 60 });
82
- });
83
-
84
- ChatUiSelectors.chatTimer.should('contain.text', '30s');
85
-
86
- // Update timer value and wait for re-render
87
- cy.then(() => {
88
- chatUiStore.setTimer({ secondsLeft: 15, secondsTotal: 60 });
89
- });
90
- ChatUiSelectors.chatTimer.should('contain.text', '15s');
91
- });
92
-
93
- it('should hide timer when timer is cleared', () => {
94
- render(() => {
95
- chatUiStore.setTimer({ secondsLeft: 30, secondsTotal: 60 });
96
- });
97
-
98
- ChatUiSelectors.chatTimer.should('be.visible');
99
-
100
- // Clear timer
101
- cy.then(() => {
102
- chatUiStore.setTimer();
103
- });
104
- ChatUiSelectors.chatTimer.should('not.exist');
105
- });
106
- };