@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.
Files changed (178) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +3 -0
  5. package/dist/index.js.map +1 -1
  6. package/dist/mocks/chatbot-api-client.mock.d.ts +0 -1
  7. package/dist/mocks/chatbot-api-client.mock.d.ts.map +1 -1
  8. package/dist/mocks/chatbot-api-client.mock.js +0 -6
  9. package/dist/mocks/chatbot-api-client.mock.js.map +1 -1
  10. package/dist/tests/index.d.ts +30 -0
  11. package/dist/tests/index.d.ts.map +1 -0
  12. package/dist/tests/index.js +30 -0
  13. package/dist/tests/index.js.map +1 -0
  14. package/dist/tests/titan-chat-ui/chat-error.shared-tests.d.ts +3 -0
  15. package/dist/tests/titan-chat-ui/chat-error.shared-tests.d.ts.map +1 -0
  16. package/dist/tests/titan-chat-ui/chat-error.shared-tests.js +138 -0
  17. package/dist/tests/titan-chat-ui/chat-error.shared-tests.js.map +1 -0
  18. package/dist/tests/titan-chat-ui/chat-input-file.shared-tests.d.ts +7 -0
  19. package/dist/tests/titan-chat-ui/chat-input-file.shared-tests.d.ts.map +1 -0
  20. package/dist/tests/titan-chat-ui/chat-input-file.shared-tests.js +123 -0
  21. package/dist/tests/titan-chat-ui/chat-input-file.shared-tests.js.map +1 -0
  22. package/dist/tests/titan-chat-ui/chat-input.shared-tests.d.ts +3 -0
  23. package/dist/tests/titan-chat-ui/chat-input.shared-tests.d.ts.map +1 -0
  24. package/dist/tests/titan-chat-ui/chat-input.shared-tests.js +71 -0
  25. package/dist/tests/titan-chat-ui/chat-input.shared-tests.js.map +1 -0
  26. package/dist/tests/titan-chat-ui/chat-log.shared-tests.d.ts +9 -0
  27. package/dist/tests/titan-chat-ui/chat-log.shared-tests.d.ts.map +1 -0
  28. package/dist/tests/titan-chat-ui/chat-log.shared-tests.js +73 -0
  29. package/dist/tests/titan-chat-ui/chat-log.shared-tests.js.map +1 -0
  30. package/dist/tests/titan-chat-ui/chat-messages.shared-tests.d.ts +8 -0
  31. package/dist/tests/titan-chat-ui/chat-messages.shared-tests.d.ts.map +1 -0
  32. package/dist/tests/titan-chat-ui/chat-messages.shared-tests.js +118 -0
  33. package/dist/tests/titan-chat-ui/chat-messages.shared-tests.js.map +1 -0
  34. package/dist/tests/titan-chat-ui/chat-notifications.shared-tests.d.ts +3 -0
  35. package/dist/tests/titan-chat-ui/chat-notifications.shared-tests.d.ts.map +1 -0
  36. package/dist/tests/titan-chat-ui/chat-notifications.shared-tests.js +110 -0
  37. package/dist/tests/titan-chat-ui/chat-notifications.shared-tests.js.map +1 -0
  38. package/dist/tests/titan-chat-ui/chat-timer.shared-tests.d.ts +3 -0
  39. package/dist/tests/titan-chat-ui/chat-timer.shared-tests.d.ts.map +1 -0
  40. package/dist/tests/titan-chat-ui/chat-timer.shared-tests.js +76 -0
  41. package/dist/tests/titan-chat-ui/chat-timer.shared-tests.js.map +1 -0
  42. package/dist/tests/titan-chat-ui/chat.shared-tests.d.ts +9 -0
  43. package/dist/tests/titan-chat-ui/chat.shared-tests.d.ts.map +1 -0
  44. package/dist/tests/titan-chat-ui/chat.shared-tests.js +111 -0
  45. package/dist/tests/titan-chat-ui/chat.shared-tests.js.map +1 -0
  46. package/dist/tests/titan-chat-ui/message-agent.shared-tests.d.ts +27 -0
  47. package/dist/tests/titan-chat-ui/message-agent.shared-tests.d.ts.map +1 -0
  48. package/dist/tests/titan-chat-ui/message-agent.shared-tests.js +67 -0
  49. package/dist/tests/titan-chat-ui/message-agent.shared-tests.js.map +1 -0
  50. package/dist/tests/titan-chat-ui/message-content-file.shared-tests.d.ts +10 -0
  51. package/dist/tests/titan-chat-ui/message-content-file.shared-tests.d.ts.map +1 -0
  52. package/dist/tests/titan-chat-ui/message-content-file.shared-tests.js +88 -0
  53. package/dist/tests/titan-chat-ui/message-content-file.shared-tests.js.map +1 -0
  54. package/dist/tests/titan-chat-ui/message-system.shared-tests.d.ts +16 -0
  55. package/dist/tests/titan-chat-ui/message-system.shared-tests.d.ts.map +1 -0
  56. package/dist/tests/titan-chat-ui/message-system.shared-tests.js +65 -0
  57. package/dist/tests/titan-chat-ui/message-system.shared-tests.js.map +1 -0
  58. package/dist/tests/titan-chat-ui/message-timeout.shared-tests.d.ts +8 -0
  59. package/dist/tests/titan-chat-ui/message-timeout.shared-tests.d.ts.map +1 -0
  60. package/dist/tests/titan-chat-ui/message-timeout.shared-tests.js +63 -0
  61. package/dist/tests/titan-chat-ui/message-timeout.shared-tests.js.map +1 -0
  62. package/dist/tests/titan-chat-ui/message-typing.shared-tests.d.ts +12 -0
  63. package/dist/tests/titan-chat-ui/message-typing.shared-tests.d.ts.map +1 -0
  64. package/dist/tests/titan-chat-ui/message-typing.shared-tests.js +46 -0
  65. package/dist/tests/titan-chat-ui/message-typing.shared-tests.js.map +1 -0
  66. package/dist/tests/titan-chat-ui/message-user.shared-tests.d.ts +10 -0
  67. package/dist/tests/titan-chat-ui/message-user.shared-tests.d.ts.map +1 -0
  68. package/dist/tests/titan-chat-ui/message-user.shared-tests.js +64 -0
  69. package/dist/tests/titan-chat-ui/message-user.shared-tests.js.map +1 -0
  70. package/dist/tests/titan-chatbot-ui/chatbot-filters.shared-tests.d.ts +7 -0
  71. package/dist/tests/titan-chatbot-ui/chatbot-filters.shared-tests.d.ts.map +1 -0
  72. package/dist/tests/titan-chatbot-ui/chatbot-filters.shared-tests.js +118 -0
  73. package/dist/tests/titan-chatbot-ui/chatbot-filters.shared-tests.js.map +1 -0
  74. package/dist/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.d.ts +9 -0
  75. package/dist/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.d.ts.map +1 -0
  76. package/dist/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.js +162 -0
  77. package/dist/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.js.map +1 -0
  78. package/dist/tests/titan-chatbot-ui/chatbot-links.shared-tests.d.ts +15 -0
  79. package/dist/tests/titan-chatbot-ui/chatbot-links.shared-tests.d.ts.map +1 -0
  80. package/dist/tests/titan-chatbot-ui/chatbot-links.shared-tests.js +123 -0
  81. package/dist/tests/titan-chatbot-ui/chatbot-links.shared-tests.js.map +1 -0
  82. package/dist/tests/titan-chatbot-ui/chatbot-live.shared-tests.d.ts +9 -0
  83. package/dist/tests/titan-chatbot-ui/chatbot-live.shared-tests.d.ts.map +1 -0
  84. package/dist/tests/titan-chatbot-ui/chatbot-live.shared-tests.js +84 -0
  85. package/dist/tests/titan-chatbot-ui/chatbot-live.shared-tests.js.map +1 -0
  86. package/dist/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.d.ts +8 -0
  87. package/dist/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.d.ts.map +1 -0
  88. package/dist/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.js +142 -0
  89. package/dist/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.js.map +1 -0
  90. package/dist/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.d.ts +8 -0
  91. package/dist/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.d.ts.map +1 -0
  92. package/dist/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.js +105 -0
  93. package/dist/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.js.map +1 -0
  94. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.d.ts +3 -0
  95. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.d.ts.map +1 -0
  96. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.js +86 -0
  97. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.js.map +1 -0
  98. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.d.ts +3 -0
  99. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.d.ts.map +1 -0
  100. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.js +143 -0
  101. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.js.map +1 -0
  102. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.d.ts +8 -0
  103. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.d.ts.map +1 -0
  104. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.js +200 -0
  105. package/dist/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.js.map +1 -0
  106. package/dist/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.d.ts +11 -0
  107. package/dist/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.d.ts.map +1 -0
  108. package/dist/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.js +81 -0
  109. package/dist/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.js.map +1 -0
  110. package/dist/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.d.ts +8 -0
  111. package/dist/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.d.ts.map +1 -0
  112. package/dist/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.js +60 -0
  113. package/dist/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.js.map +1 -0
  114. package/dist/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.d.ts +8 -0
  115. package/dist/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.d.ts.map +1 -0
  116. package/dist/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.js +77 -0
  117. package/dist/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.js.map +1 -0
  118. package/dist/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.d.ts +7 -0
  119. package/dist/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.d.ts.map +1 -0
  120. package/dist/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.js +130 -0
  121. package/dist/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.js.map +1 -0
  122. package/dist/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.d.ts +9 -0
  123. package/dist/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.d.ts.map +1 -0
  124. package/dist/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.js +157 -0
  125. package/dist/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.js.map +1 -0
  126. package/dist/tests/titan-chatbot-ui/chatbot.shared-tests.d.ts +9 -0
  127. package/dist/tests/titan-chatbot-ui/chatbot.shared-tests.d.ts.map +1 -0
  128. package/dist/tests/titan-chatbot-ui/chatbot.shared-tests.js +114 -0
  129. package/dist/tests/titan-chatbot-ui/chatbot.shared-tests.js.map +1 -0
  130. package/dist/utils/chat-ui-selectors.d.ts +12 -0
  131. package/dist/utils/chat-ui-selectors.d.ts.map +1 -1
  132. package/dist/utils/chat-ui-selectors.js +24 -0
  133. package/dist/utils/chat-ui-selectors.js.map +1 -1
  134. package/dist/utils/test-utils-chatbot.d.ts +5 -0
  135. package/dist/utils/test-utils-chatbot.d.ts.map +1 -0
  136. package/dist/utils/test-utils-chatbot.js +55 -0
  137. package/dist/utils/test-utils-chatbot.js.map +1 -0
  138. package/dist/utils/test-utils.d.ts +6 -0
  139. package/dist/utils/test-utils.d.ts.map +1 -0
  140. package/dist/utils/test-utils.js +38 -0
  141. package/dist/utils/test-utils.js.map +1 -0
  142. package/package.json +10 -5
  143. package/src/index.ts +3 -0
  144. package/src/mocks/chatbot-api-client.mock.ts +0 -1
  145. package/src/tests/index.ts +30 -0
  146. package/src/tests/titan-chat-ui/chat-error.shared-tests.tsx +185 -0
  147. package/src/tests/titan-chat-ui/chat-input-file.shared-tests.tsx +182 -0
  148. package/src/tests/titan-chat-ui/chat-input.shared-tests.tsx +99 -0
  149. package/src/tests/titan-chat-ui/chat-log.shared-tests.tsx +117 -0
  150. package/src/tests/titan-chat-ui/chat-messages.shared-tests.tsx +156 -0
  151. package/src/tests/titan-chat-ui/chat-notifications.shared-tests.tsx +153 -0
  152. package/src/tests/titan-chat-ui/chat-timer.shared-tests.tsx +106 -0
  153. package/src/tests/titan-chat-ui/chat.shared-tests.tsx +158 -0
  154. package/src/tests/titan-chat-ui/message-agent.shared-tests.tsx +170 -0
  155. package/src/tests/titan-chat-ui/message-content-file.shared-tests.tsx +139 -0
  156. package/src/tests/titan-chat-ui/message-system.shared-tests.tsx +147 -0
  157. package/src/tests/titan-chat-ui/message-timeout.shared-tests.tsx +117 -0
  158. package/src/tests/titan-chat-ui/message-typing.shared-tests.tsx +92 -0
  159. package/src/tests/titan-chat-ui/message-user.shared-tests.tsx +138 -0
  160. package/src/tests/titan-chatbot-ui/chatbot-filters.shared-tests.tsx +164 -0
  161. package/src/tests/titan-chatbot-ui/chatbot-help-center.shared-tests.tsx +225 -0
  162. package/src/tests/titan-chatbot-ui/chatbot-links.shared-tests.tsx +189 -0
  163. package/src/tests/titan-chatbot-ui/chatbot-live.shared-tests.tsx +127 -0
  164. package/src/tests/titan-chatbot-ui/chatbot-message-answer-readonly.shared-tests.tsx +187 -0
  165. package/src/tests/titan-chatbot-ui/chatbot-message-answer.shared-tests.tsx +144 -0
  166. package/src/tests/titan-chatbot-ui/chatbot-message-feedback-form-guardrail.shared-tests.tsx +127 -0
  167. package/src/tests/titan-chatbot-ui/chatbot-message-feedback-form.shared-tests.tsx +198 -0
  168. package/src/tests/titan-chatbot-ui/chatbot-message-feedback-popover.shared-tests.tsx +285 -0
  169. package/src/tests/titan-chatbot-ui/chatbot-message-typing.shared-tests.tsx +112 -0
  170. package/src/tests/titan-chatbot-ui/chatbot-restart-dialog.shared-tests.tsx +91 -0
  171. package/src/tests/titan-chatbot-ui/chatbot-restart-link.shared-tests.tsx +116 -0
  172. package/src/tests/titan-chatbot-ui/chatbot-session-feedback-modal.shared-tests.tsx +182 -0
  173. package/src/tests/titan-chatbot-ui/chatbot-titan-chatbot.shared-tests.tsx +221 -0
  174. package/src/tests/titan-chatbot-ui/chatbot.shared-tests.tsx +158 -0
  175. package/src/utils/chat-ui-selectors.ts +24 -0
  176. package/src/utils/test-utils-chatbot.tsx +73 -0
  177. package/src/utils/test-utils.tsx +52 -0
  178. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,158 @@
1
+ import { Container } from '@servicetitan/react-ioc';
2
+ import {
3
+ CHAT_UI_BACKEND_STORE_TOKEN,
4
+ CHAT_UI_STORE_TOKEN,
5
+ ChatCustomizations,
6
+ ChatRunState,
7
+ ChatUiBackendEchoStore,
8
+ IChatUiBackendStore,
9
+ IChatUiStore,
10
+ } from '@servicetitan/titan-chat-ui-common';
11
+ import { ComponentType } from 'react';
12
+ import { ChatUiSelectors } from '../../utils/chat-ui-selectors';
13
+ import { testInitContainer, testRenderWrapper } from '../../utils/test-utils';
14
+
15
+ interface IChatProps {
16
+ className?: string;
17
+ customizations?: ChatCustomizations;
18
+ }
19
+
20
+ export function runChatSharedTests(ChatComponent: ComponentType<IChatProps>) {
21
+ let container: Container;
22
+ let chatUiStore: IChatUiStore;
23
+ let chatUiBackendStore: IChatUiBackendStore;
24
+
25
+ beforeEach(() => {
26
+ container = testInitContainer();
27
+ chatUiStore = container.get<IChatUiStore>(CHAT_UI_STORE_TOKEN);
28
+ chatUiBackendStore = container.get<ChatUiBackendEchoStore>(CHAT_UI_BACKEND_STORE_TOKEN);
29
+ cy.viewport(800, 800);
30
+ });
31
+
32
+ const render = (props?: IChatProps, onAfterInit?: () => void) =>
33
+ cy
34
+ .wrap(null)
35
+ .then(() =>
36
+ testRenderWrapper(
37
+ chatUiStore,
38
+ chatUiBackendStore,
39
+ <ChatComponent {...props} />,
40
+ onAfterInit
41
+ )
42
+ );
43
+
44
+ it('should render chat component with default state', () => {
45
+ render();
46
+
47
+ ChatUiSelectors.chat.should('exist');
48
+ ChatUiSelectors.chat.should('be.visible');
49
+ });
50
+
51
+ it('should render loading component when chat is starting', () => {
52
+ render(undefined, () => {
53
+ chatUiStore.setStatus(ChatRunState.Initializing);
54
+ });
55
+
56
+ ChatUiSelectors.chat.should('exist');
57
+ ChatUiSelectors.chatConnecting.should('exist');
58
+ ChatUiSelectors.chatMessages.should('not.exist');
59
+ ChatUiSelectors.chatInput.should('not.exist');
60
+ });
61
+
62
+ it('should render chat messages and input when not starting', () => {
63
+ render(undefined, () => {
64
+ chatUiStore.setStatus(ChatRunState.Started);
65
+ });
66
+
67
+ ChatUiSelectors.chat.should('exist');
68
+ ChatUiSelectors.chatConnecting.should('not.exist');
69
+ ChatUiSelectors.chatMessages.should('exist');
70
+ ChatUiSelectors.chatInput.should('exist');
71
+ ChatUiSelectors.chatNotifications.should('exist');
72
+ });
73
+
74
+ it('should apply custom className when provided', () => {
75
+ const customClass = 'custom-chat-class';
76
+ render({ className: customClass });
77
+
78
+ ChatUiSelectors.chat.should('have.class', customClass);
79
+ });
80
+
81
+ it('should render custom loading component when provided', () => {
82
+ const customLoadingComponent = <div data-cy="custom-loading">Custom Loading</div>;
83
+ const customizations: ChatCustomizations = {
84
+ loadingComponent: customLoadingComponent,
85
+ };
86
+
87
+ render({ customizations }, () => {
88
+ chatUiStore.setStatus(ChatRunState.Initializing);
89
+ });
90
+
91
+ cy.get('[data-cy="custom-loading"]').should('exist');
92
+ cy.get('[data-cy="custom-loading"]').should('contain.text', 'Custom Loading');
93
+ ChatUiSelectors.chatConnecting.should('not.exist');
94
+ });
95
+
96
+ it('should render custom footer component when provided', () => {
97
+ const customFooterComponent = <div data-cy="custom-footer">Custom Footer</div>;
98
+ const customizations: ChatCustomizations = {
99
+ footerComponent: customFooterComponent,
100
+ };
101
+
102
+ render({ customizations }, () => {
103
+ chatUiStore.setStatus(ChatRunState.Started);
104
+ });
105
+
106
+ cy.get('[data-cy="custom-footer"]').should('exist');
107
+ cy.get('[data-cy="custom-footer"]').should('contain.text', 'Custom Footer');
108
+ });
109
+
110
+ it('should hide chat input when input is disabled in customizations', () => {
111
+ const customizations: ChatCustomizations = {
112
+ input: {
113
+ isDisabled: true,
114
+ },
115
+ };
116
+
117
+ render({ customizations }, () => {
118
+ chatUiStore.setStatus(ChatRunState.Started);
119
+ });
120
+
121
+ ChatUiSelectors.chat.should('exist');
122
+ ChatUiSelectors.chatMessages.should('exist');
123
+ ChatUiSelectors.chatInput.should('not.exist');
124
+ ChatUiSelectors.chatUploadFile.should('not.exist');
125
+ });
126
+
127
+ it('should show chat input and upload file when input is enabled', () => {
128
+ const customizations: ChatCustomizations = {
129
+ input: {
130
+ isDisabled: false,
131
+ },
132
+ };
133
+
134
+ render({ customizations }, () => {
135
+ chatUiStore.setStatus(ChatRunState.Started);
136
+ chatUiStore.setFilePickerEnabled(true);
137
+ });
138
+
139
+ ChatUiSelectors.chat.should('exist');
140
+ ChatUiSelectors.chatMessages.should('exist');
141
+ ChatUiSelectors.chatInput.should('exist');
142
+ ChatUiSelectors.chatUploadFile.should('exist');
143
+ });
144
+
145
+ it('should set customization context in store when customizations are provided', () => {
146
+ const customizations: ChatCustomizations = {
147
+ input: {
148
+ isDisabled: true,
149
+ },
150
+ };
151
+
152
+ render({ customizations });
153
+
154
+ cy.wait(1).then(() => {
155
+ expect(chatUiStore.customizations).to.deep.equal(customizations);
156
+ });
157
+ });
158
+ }
@@ -0,0 +1,170 @@
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, ReactNode } from 'react';
11
+ import { ChatUiSelectors } from '../../utils/chat-ui-selectors';
12
+ import { testInitContainer, testRenderWrapper } from '../../utils/test-utils';
13
+
14
+ interface MessageAgentSharedTestsOptions {
15
+ isAnvil2?: boolean;
16
+ }
17
+
18
+ interface MessageAgentProps {
19
+ 'avatar'?: {
20
+ name: string;
21
+ icon: ChatParticipantIcon;
22
+ className?: string;
23
+ };
24
+ 'children'?: ReactNode;
25
+ 'messageFooter'?: ReactNode;
26
+ 'fullWidth'?: boolean;
27
+ 'data-cy'?: string;
28
+ }
29
+
30
+ interface MessageAgentComponents {
31
+ TextComponent: FC<any>;
32
+ ButtonComponent: FC<any>;
33
+ ContainerComponent: FC<any>;
34
+ MessageFooterComponent: FC<any>;
35
+ thumbUpIcon?: any;
36
+ thumbDownIcon?: any;
37
+ }
38
+
39
+ export function runMessageAgentSharedTests(
40
+ MessageAgentComponent: FC<MessageAgentProps>,
41
+ components: MessageAgentComponents,
42
+ options: MessageAgentSharedTestsOptions = {}
43
+ ) {
44
+ let container: Container;
45
+ let chatUiStore: IChatUiStore;
46
+ let chatUiBackendStore: IChatUiBackendStore;
47
+
48
+ beforeEach(() => {
49
+ container = testInitContainer();
50
+ chatUiStore = container.get<IChatUiStore>(CHAT_UI_STORE_TOKEN);
51
+ chatUiBackendStore = container.get<ChatUiBackendEchoStore>(CHAT_UI_BACKEND_STORE_TOKEN);
52
+ cy.viewport(800, 800);
53
+ });
54
+
55
+ const render = (props?: any, onAfterInit?: () => void) => {
56
+ const defaultProps = {
57
+ avatar: {
58
+ name: 'Test User Name',
59
+ icon: ChatParticipantIcon.Bot,
60
+ },
61
+ children: options.isAnvil2 ? (
62
+ <components.TextComponent variant="body" data-cy="content">
63
+ message agent content
64
+ </components.TextComponent>
65
+ ) : (
66
+ <components.TextComponent data-cy="content">
67
+ message agent content
68
+ </components.TextComponent>
69
+ ),
70
+ };
71
+
72
+ return cy
73
+ .wrap(null)
74
+ .then(() =>
75
+ testRenderWrapper(
76
+ chatUiStore,
77
+ chatUiBackendStore,
78
+ <MessageAgentComponent {...defaultProps} {...props} />,
79
+ onAfterInit
80
+ )
81
+ );
82
+ };
83
+
84
+ const createMessageFooter = () => {
85
+ if (options.isAnvil2) {
86
+ return (
87
+ <components.ContainerComponent
88
+ direction="row"
89
+ justifyContent="space-between"
90
+ alignItems="center"
91
+ >
92
+ <components.MessageFooterComponent
93
+ name="name"
94
+ timestamp={new Date('2022-01-01T10:10:00')}
95
+ />
96
+ <components.ContainerComponent direction="row" gap="1" alignItems="center">
97
+ <components.ButtonComponent
98
+ icon={components.thumbUpIcon}
99
+ size="small"
100
+ appearance="ghost"
101
+ />
102
+ <components.ButtonComponent
103
+ icon={components.thumbDownIcon}
104
+ size="small"
105
+ appearance="ghost"
106
+ />
107
+ </components.ContainerComponent>
108
+ </components.ContainerComponent>
109
+ );
110
+ }
111
+
112
+ return (
113
+ <components.ContainerComponent
114
+ direction="row"
115
+ justifyContent="space-between"
116
+ alignItems="center"
117
+ >
118
+ <components.MessageFooterComponent
119
+ name="name"
120
+ timestamp={new Date('2022-01-01T10:10:00')}
121
+ />
122
+ <components.ContainerComponent direction="row" spacing="1">
123
+ <components.ButtonComponent iconName="thumb_up" xsmall fill="subtle" />
124
+ <components.ButtonComponent iconName="thumb_down" xsmall fill="subtle" />
125
+ </components.ContainerComponent>
126
+ </components.ContainerComponent>
127
+ );
128
+ };
129
+
130
+ it('should be properly rendered', () => {
131
+ render({
132
+ avatar: {
133
+ name: 'Test User Name',
134
+ icon: ChatParticipantIcon.Bot,
135
+ className: 'custom-class',
136
+ },
137
+ });
138
+
139
+ ChatUiSelectors.chatMessageAgent.should('be.visible').children().should('have.length', 2);
140
+ ChatUiSelectors.chatAvatarBot.should('be.visible').should('have.class', 'custom-class');
141
+ ChatUiSelectors.chatMessageContentAgent.should('contain.text', 'message agent content');
142
+ });
143
+
144
+ it('should be full width', () => {
145
+ render({
146
+ fullWidth: true,
147
+ });
148
+
149
+ ChatUiSelectors.chatMessageContentAgent.should('contain.text', 'message agent content');
150
+ });
151
+
152
+ it('should render with custom data-cy', () => {
153
+ render({
154
+ 'data-cy': 'custom-data-cy',
155
+ });
156
+
157
+ cy.getCy('custom-data-cy').should('be.visible');
158
+ });
159
+
160
+ it('should render custom message footer', () => {
161
+ render({
162
+ messageFooter: createMessageFooter(),
163
+ });
164
+
165
+ ChatUiSelectors.chatMessageAgent.should('be.visible').children().should('have.length', 2);
166
+ ChatUiSelectors.chatMessageFooter
167
+ .should('be.visible')
168
+ .should('contain.text', 'name • 10:10 AM');
169
+ });
170
+ }
@@ -0,0 +1,139 @@
1
+ import { Container } from '@servicetitan/react-ioc';
2
+ import {
3
+ CHAT_UI_BACKEND_STORE_TOKEN,
4
+ CHAT_UI_STORE_TOKEN,
5
+ ChatMessageModelFile,
6
+ ChatMessageState,
7
+ ChatParticipantIcon,
8
+ ChatParticipantModel,
9
+ ChatUiBackendEchoStore,
10
+ IChatUiBackendStore,
11
+ IChatUiStore,
12
+ } from '@servicetitan/titan-chat-ui-common';
13
+ import { FC } from 'react';
14
+ import { testInitContainer, testRenderWrapper } from '../../utils/test-utils';
15
+
16
+ interface MessageContentFileSharedTestsOptions {
17
+ isAnvil2?: boolean;
18
+ }
19
+
20
+ export function runMessageContentFileSharedTests(
21
+ MessageContentFileComponent: FC<{ message: ChatMessageModelFile }>,
22
+ options: MessageContentFileSharedTestsOptions = {}
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 = (message: ChatMessageModelFile, onAfterInit?: () => void) =>
36
+ cy
37
+ .wrap(null)
38
+ .then(() =>
39
+ testRenderWrapper(
40
+ chatUiStore,
41
+ chatUiBackendStore,
42
+ <MessageContentFileComponent message={message} />,
43
+ onAfterInit
44
+ )
45
+ );
46
+
47
+ const createFileMessage = (
48
+ fileName: string,
49
+ state: ChatMessageState = ChatMessageState.Delivered
50
+ ): ChatMessageModelFile => ({
51
+ id: 'test-file-message',
52
+ type: 'file',
53
+ participant: {
54
+ isAgent: false,
55
+ icon: ChatParticipantIcon.Empty,
56
+ name: 'Test User',
57
+ } as ChatParticipantModel,
58
+ fileName,
59
+ state,
60
+ timestamp: new Date(),
61
+ });
62
+
63
+ const getIconSelector = () => {
64
+ return options.isAnvil2 ? '[data-anv="icon"]' : '[data-anvil-component="Icon"]';
65
+ };
66
+
67
+ it('should render file name with attach icon', () => {
68
+ const message = createFileMessage('test-document.pdf');
69
+ render(message);
70
+
71
+ cy.get(getIconSelector()).should('be.visible');
72
+ cy.contains('test-document.pdf').should('be.visible');
73
+ });
74
+
75
+ it('should display file name for different file types', () => {
76
+ const imageMessage = createFileMessage('image.jpg');
77
+ render(imageMessage);
78
+
79
+ cy.contains('image.jpg').should('be.visible');
80
+ });
81
+
82
+ it('should not show status text when message is in sent state', () => {
83
+ const message = createFileMessage('document.pdf', ChatMessageState.Delivered);
84
+ render(message);
85
+
86
+ cy.contains('File uploaded').should('exist');
87
+ cy.contains('Please wait while uploading...').should('not.exist');
88
+ });
89
+
90
+ it('should show "Please wait while uploading..." when message is delivering', () => {
91
+ const message = createFileMessage('document.pdf', ChatMessageState.Delivering);
92
+ render(message);
93
+
94
+ cy.contains('document.pdf').should('be.visible');
95
+ cy.contains('Please wait while uploading...').should('be.visible');
96
+ cy.contains('File uploaded').should('not.exist');
97
+ });
98
+
99
+ it('should show "File uploaded" when message is delivered', () => {
100
+ const message = createFileMessage('document.pdf', ChatMessageState.Delivered);
101
+ render(message);
102
+
103
+ cy.contains('document.pdf').should('be.visible');
104
+ cy.contains('File uploaded').should('be.visible');
105
+ cy.contains('Please wait while uploading...').should('not.exist');
106
+ });
107
+
108
+ it('should render with long file names', () => {
109
+ const message = createFileMessage('very-long-file-name-that-might-cause-layout-issues.pdf');
110
+ render(message);
111
+
112
+ cy.contains('very-long-file-name-that-might-cause-layout-issues.pdf').should('be.visible');
113
+ });
114
+
115
+ it('should render file with special characters in name', () => {
116
+ const message = createFileMessage('test file (1) - copy.pdf');
117
+ render(message);
118
+
119
+ cy.contains('test file (1) - copy.pdf').should('be.visible');
120
+ });
121
+
122
+ it('should not show status text when message is in pending state', () => {
123
+ const message = createFileMessage('document.pdf', ChatMessageState.Delivering);
124
+ render(message);
125
+
126
+ cy.contains('document.pdf').should('be.visible');
127
+ cy.contains('File uploaded').should('not.exist');
128
+ cy.contains('Please wait while uploading...').should('be.visible');
129
+ });
130
+
131
+ it('should not show status text when message is in error state', () => {
132
+ const message = createFileMessage('document.pdf', ChatMessageState.Failed);
133
+ render(message);
134
+
135
+ cy.contains('document.pdf').should('be.visible');
136
+ cy.contains('File uploaded').should('not.exist');
137
+ cy.contains('Please wait while uploading...').should('not.exist');
138
+ });
139
+ }
@@ -0,0 +1,147 @@
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 MessageSystemSharedTestsOptions {
14
+ isAnvil2?: boolean;
15
+ }
16
+
17
+ interface MessageSystemProps {
18
+ className?: string;
19
+ fullWidth?: boolean;
20
+ children?: ReactNode;
21
+ }
22
+
23
+ interface MessageSystemComponents {
24
+ TextComponent: FC<any>;
25
+ ContainerComponent: FC<any>;
26
+ }
27
+
28
+ export function runMessageSystemSharedTests(
29
+ MessageSystemComponent: FC<MessageSystemProps>,
30
+ components: MessageSystemComponents,
31
+ options: MessageSystemSharedTestsOptions = {}
32
+ ) {
33
+ let container: Container;
34
+ let chatUiStore: IChatUiStore;
35
+ let chatUiBackendStore: IChatUiBackendStore;
36
+
37
+ beforeEach(() => {
38
+ container = testInitContainer();
39
+ chatUiStore = container.get<IChatUiStore>(CHAT_UI_STORE_TOKEN);
40
+ chatUiBackendStore = container.get<ChatUiBackendEchoStore>(CHAT_UI_BACKEND_STORE_TOKEN);
41
+ cy.viewport(800, 800);
42
+ });
43
+
44
+ const render = (
45
+ props: { className?: string; fullWidth?: boolean; children?: ReactNode } = {},
46
+ onAfterInit?: () => void
47
+ ) =>
48
+ cy.wrap(null).then(() =>
49
+ testRenderWrapper(
50
+ chatUiStore,
51
+ chatUiBackendStore,
52
+ <MessageSystemComponent className={props.className} fullWidth={props.fullWidth}>
53
+ {props.children}
54
+ </MessageSystemComponent>,
55
+ onAfterInit
56
+ )
57
+ );
58
+
59
+ const createTestContent = () => {
60
+ if (options.isAnvil2) {
61
+ return (
62
+ <components.ContainerComponent>
63
+ <components.TextComponent variant="body" data-cy="content">
64
+ message system content
65
+ </components.TextComponent>
66
+ </components.ContainerComponent>
67
+ );
68
+ }
69
+
70
+ return (
71
+ <components.ContainerComponent className="border">
72
+ <components.TextComponent data-cy="content">
73
+ message system content
74
+ </components.TextComponent>
75
+ </components.ContainerComponent>
76
+ );
77
+ };
78
+
79
+ const createSimpleTestContent = () => {
80
+ if (options.isAnvil2) {
81
+ return <components.TextComponent variant="body">Test content</components.TextComponent>;
82
+ }
83
+
84
+ return <components.TextComponent>Test content</components.TextComponent>;
85
+ };
86
+
87
+ it('should be properly rendered', () => {
88
+ render({
89
+ className: 'custom-class',
90
+ children: createTestContent(),
91
+ });
92
+
93
+ ChatUiSelectors.chatMessageSystem.should('have.class', 'custom-class').should('be.visible');
94
+ cy.get('[data-cy="content"]').should('contain.text', 'message system content');
95
+ });
96
+
97
+ it('should be properly rendered fullwidth', () => {
98
+ render({
99
+ className: 'custom-class',
100
+ fullWidth: true,
101
+ children: createTestContent(),
102
+ });
103
+
104
+ ChatUiSelectors.chatMessageSystem.should('have.class', 'custom-class').should('be.visible');
105
+ cy.get('[data-cy="content"]').should('contain.text', 'message system content');
106
+ });
107
+
108
+ it('should render with default data-cy attribute', () => {
109
+ render({
110
+ children: createSimpleTestContent(),
111
+ });
112
+
113
+ ChatUiSelectors.chatMessageSystem.should(
114
+ 'have.attr',
115
+ 'data-cy',
116
+ 'titan-chat-message-system'
117
+ );
118
+ });
119
+
120
+ it('should render without children', () => {
121
+ render();
122
+
123
+ ChatUiSelectors.chatMessageSystem.should('not.be.visible');
124
+ });
125
+
126
+ it('should handle complex children structure', () => {
127
+ const complexChildren = options.isAnvil2 ? (
128
+ <components.ContainerComponent>
129
+ <components.TextComponent variant="body">First line</components.TextComponent>
130
+ <components.TextComponent variant="body">Second line</components.TextComponent>
131
+ </components.ContainerComponent>
132
+ ) : (
133
+ <components.ContainerComponent>
134
+ <components.TextComponent>First line</components.TextComponent>
135
+ <components.TextComponent>Second line</components.TextComponent>
136
+ </components.ContainerComponent>
137
+ );
138
+
139
+ render({
140
+ children: complexChildren,
141
+ });
142
+
143
+ ChatUiSelectors.chatMessageSystem.should('be.visible');
144
+ cy.contains('First line').should('be.visible');
145
+ cy.contains('Second line').should('be.visible');
146
+ });
147
+ }