@chat21/chat21-web-widget 5.1.33 → 5.1.34-rc1

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 (201) hide show
  1. package/.angular-mcp-cache/package.json +1 -0
  2. package/.cursor/angular18-accessibility-auditor-skill.md +442 -0
  3. package/.cursor/mcp.json +15 -0
  4. package/.github/workflows/docker-community-push-latest.yml +23 -13
  5. package/.github/workflows/docker-image-tag-community-tag-push.yml +22 -12
  6. package/.github/workflows/playwright.yml +27 -0
  7. package/CHANGELOG.md +130 -6
  8. package/Dockerfile +4 -5
  9. package/angular.json +24 -4
  10. package/docs/changelog/this-branch.md +36 -0
  11. package/env.sample +3 -2
  12. package/mocks/voice-websocket-mock/server.cjs +245 -0
  13. package/nginx.conf +22 -2
  14. package/package.json +10 -3
  15. package/playwright.config.ts +41 -0
  16. package/src/app/app.component.html +2 -2
  17. package/src/app/app.component.scss +25 -14
  18. package/src/app/app.component.spec.ts +21 -6
  19. package/src/app/app.component.ts +10 -9
  20. package/src/app/app.module.ts +15 -0
  21. package/src/app/component/conversation-detail/conversation/conversation.component.html +25 -11
  22. package/src/app/component/conversation-detail/conversation/conversation.component.scss +40 -2
  23. package/src/app/component/conversation-detail/conversation/conversation.component.spec.ts +644 -75
  24. package/src/app/component/conversation-detail/conversation/conversation.component.ts +100 -14
  25. package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.html +25 -13
  26. package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.spec.ts +123 -5
  27. package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.ts +1 -0
  28. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.html +23 -10
  29. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.scss +33 -2
  30. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.spec.ts +242 -149
  31. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.ts +8 -6
  32. package/src/app/component/conversation-detail/conversation-emojii/conversation-emojii.component.spec.ts +53 -3
  33. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.html +200 -96
  34. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.scss +211 -6
  35. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.spec.ts +452 -78
  36. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.ts +291 -76
  37. package/src/app/component/conversation-detail/conversation-header/conversation-header.component.html +113 -53
  38. package/src/app/component/conversation-detail/conversation-header/conversation-header.component.scss +12 -4
  39. package/src/app/component/conversation-detail/conversation-header/conversation-header.component.spec.ts +274 -29
  40. package/src/app/component/conversation-detail/conversation-internal-frame/conversation-internal-frame.component.html +23 -9
  41. package/src/app/component/conversation-detail/conversation-internal-frame/conversation-internal-frame.component.spec.ts +80 -8
  42. package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.html +29 -23
  43. package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.spec.ts +185 -16
  44. package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.ts +34 -14
  45. package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.html +46 -0
  46. package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.scss +83 -0
  47. package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.ts +192 -0
  48. package/src/app/component/error-alert/error-alert.component.spec.ts +65 -5
  49. package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.html +16 -7
  50. package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.scss +21 -0
  51. package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.spec.ts +89 -7
  52. package/src/app/component/form/form-builder/form-builder.component.html +1 -1
  53. package/src/app/component/form/form-builder/form-builder.component.spec.ts +163 -21
  54. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.html +8 -4
  55. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.scss +10 -5
  56. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.spec.ts +90 -16
  57. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.ts +26 -0
  58. package/src/app/component/form/inputs/form-label/form-label.component.spec.ts +45 -11
  59. package/src/app/component/form/inputs/form-radio-button/form-radio-button.component.spec.ts +24 -6
  60. package/src/app/component/form/inputs/form-select/form-select.component.spec.ts +14 -5
  61. package/src/app/component/form/inputs/form-text/form-text.component.html +14 -12
  62. package/src/app/component/form/inputs/form-text/form-text.component.scss +11 -1
  63. package/src/app/component/form/inputs/form-text/form-text.component.spec.ts +113 -17
  64. package/src/app/component/form/inputs/form-text/form-text.component.ts +35 -3
  65. package/src/app/component/form/inputs/form-textarea/form-textarea.component.html +13 -11
  66. package/src/app/component/form/inputs/form-textarea/form-textarea.component.scss +6 -5
  67. package/src/app/component/form/inputs/form-textarea/form-textarea.component.spec.ts +149 -13
  68. package/src/app/component/form/inputs/form-textarea/form-textarea.component.ts +26 -0
  69. package/src/app/component/form/prechat-form/prechat-form.component.html +14 -11
  70. package/src/app/component/form/prechat-form/prechat-form.component.spec.ts +102 -10
  71. package/src/app/component/form/prechat-form/prechat-form.component.ts +8 -1
  72. package/src/app/component/form/prechat-form-test-mock.ts +35 -0
  73. package/src/app/component/home/home.component.html +38 -31
  74. package/src/app/component/home/home.component.scss +4 -2
  75. package/src/app/component/home/home.component.spec.ts +226 -11
  76. package/src/app/component/home-conversations/home-conversations.component.html +30 -26
  77. package/src/app/component/home-conversations/home-conversations.component.scss +3 -0
  78. package/src/app/component/home-conversations/home-conversations.component.spec.ts +212 -36
  79. package/src/app/component/last-message/last-message.component.html +15 -9
  80. package/src/app/component/last-message/last-message.component.scss +16 -2
  81. package/src/app/component/last-message/last-message.component.spec.ts +204 -23
  82. package/src/app/component/last-message/last-message.component.ts +4 -1
  83. package/src/app/component/launcher-button/launcher-button.component.html +8 -13
  84. package/src/app/component/launcher-button/launcher-button.component.spec.ts +104 -8
  85. package/src/app/component/list-all-conversations/list-all-conversations.component.html +12 -17
  86. package/src/app/component/list-all-conversations/list-all-conversations.component.scss +2 -0
  87. package/src/app/component/list-conversations/list-conversations.component.html +22 -22
  88. package/src/app/component/menu-options/menu-options.component.html +30 -20
  89. package/src/app/component/menu-options/menu-options.component.spec.ts +125 -9
  90. package/src/app/component/message/audio/audio.component.html +13 -15
  91. package/src/app/component/message/audio/audio.component.spec.ts +140 -5
  92. package/src/app/component/message/audio/audio.component.ts +1 -5
  93. package/src/app/component/message/audio-sync/audio-sync.component.html +18 -0
  94. package/src/app/component/message/audio-sync/audio-sync.component.scss +65 -0
  95. package/src/app/component/message/audio-sync/audio-sync.component.spec.ts +103 -0
  96. package/src/app/component/message/audio-sync/audio-sync.component.ts +643 -0
  97. package/src/app/component/message/avatar/avatar.component.html +2 -2
  98. package/src/app/component/message/avatar/avatar.component.spec.ts +99 -7
  99. package/src/app/component/message/bubble-message/bubble-message.component.html +43 -51
  100. package/src/app/component/message/bubble-message/bubble-message.component.scss +59 -1
  101. package/src/app/component/message/bubble-message/bubble-message.component.spec.ts +154 -57
  102. package/src/app/component/message/bubble-message/bubble-message.component.ts +152 -109
  103. package/src/app/component/message/buttons/action-button/action-button.component.html +3 -4
  104. package/src/app/component/message/buttons/action-button/action-button.component.spec.ts +49 -5
  105. package/src/app/component/message/buttons/link-button/link-button.component.scss +5 -8
  106. package/src/app/component/message/buttons/link-button/link-button.component.spec.ts +50 -5
  107. package/src/app/component/message/buttons/text-button/text-button.component.spec.ts +44 -5
  108. package/src/app/component/message/carousel/carousel.component.html +29 -16
  109. package/src/app/component/message/carousel/carousel.component.scss +20 -8
  110. package/src/app/component/message/carousel/carousel.component.spec.ts +80 -3
  111. package/src/app/component/message/carousel/carousel.component.ts +16 -0
  112. package/src/app/component/message/frame/frame.component.html +9 -4
  113. package/src/app/component/message/frame/frame.component.spec.ts +34 -15
  114. package/src/app/component/message/frame/frame.component.ts +7 -2
  115. package/src/app/component/message/html/html.component.html +1 -1
  116. package/src/app/component/message/html/html.component.scss +1 -1
  117. package/src/app/component/message/html/html.component.spec.ts +24 -7
  118. package/src/app/component/message/image/image.component.html +12 -10
  119. package/src/app/component/message/image/image.component.scss +16 -0
  120. package/src/app/component/message/image/image.component.spec.ts +101 -15
  121. package/src/app/component/message/image/image.component.ts +90 -51
  122. package/src/app/component/message/info-message/info-message.component.spec.ts +26 -14
  123. package/src/app/component/message/json-sources/json-sources.component.html +38 -0
  124. package/src/app/component/message/json-sources/json-sources.component.scss +201 -0
  125. package/src/app/component/message/json-sources/json-sources.component.ts +89 -0
  126. package/src/app/component/message/like-unlike/like-unlike.component.html +7 -9
  127. package/src/app/component/message/like-unlike/like-unlike.component.spec.ts +31 -3
  128. package/src/app/component/message/return-receipt/return-receipt.component.spec.ts +38 -17
  129. package/src/app/component/message/text/text.component.html +3 -3
  130. package/src/app/component/message/text/text.component.scss +80 -86
  131. package/src/app/component/message/text/text.component.spec.ts +106 -13
  132. package/src/app/component/message-attachment/message-attachment.component.spec.ts +134 -13
  133. package/src/app/component/selection-department/selection-department.component.html +21 -23
  134. package/src/app/component/selection-department/selection-department.component.spec.ts +159 -14
  135. package/src/app/component/selection-department/selection-department.component.ts +8 -1
  136. package/src/app/component/send-button/send-button.component.html +5 -13
  137. package/src/app/component/send-button/send-button.component.spec.ts +2 -2
  138. package/src/app/component/star-rating-widget/star-rating-widget.component.html +51 -81
  139. package/src/app/directives/tooltip.directive.spec.ts +8 -4
  140. package/src/app/modals/confirm-close/confirm-close.component.html +20 -8
  141. package/src/app/modals/confirm-close/confirm-close.component.scss +3 -0
  142. package/src/app/modals/confirm-close/confirm-close.component.spec.ts +13 -4
  143. package/src/app/modals/confirm-close/confirm-close.component.ts +8 -1
  144. package/src/app/pipe/html-entites-encode.pipe.spec.ts +35 -2
  145. package/src/app/pipe/marked.pipe.spec.ts +38 -2
  146. package/src/app/pipe/marked.pipe.ts +51 -41
  147. package/src/app/providers/app-config.service.ts +4 -2
  148. package/src/app/providers/brand.service.spec.ts +23 -2
  149. package/src/app/providers/brand.service.ts +1 -1
  150. package/src/app/providers/global-settings.service.spec.ts +1009 -14
  151. package/src/app/providers/global-settings.service.ts +82 -2
  152. package/src/app/providers/json-sources-parser.service.ts +175 -0
  153. package/src/app/providers/translator.service.ts +26 -6
  154. package/src/app/providers/tts-audio-playback-coordinator.service.spec.ts +117 -0
  155. package/src/app/providers/tts-audio-playback-coordinator.service.ts +109 -0
  156. package/src/app/providers/url-preview.service.ts +82 -0
  157. package/src/app/providers/voice/STT&TTS/openai-voice.config.ts +12 -0
  158. package/src/app/providers/voice/STT&TTS/openai-voice.provider.ts +171 -0
  159. package/src/app/providers/voice/STT&TTS/speech-provider.abstract.ts +39 -0
  160. package/src/app/providers/voice/audio.types.ts +40 -0
  161. package/src/app/providers/voice/vad.service.spec.ts +28 -0
  162. package/src/app/providers/voice/vad.service.ts +70 -0
  163. package/src/app/providers/voice/voice-streaming.service.spec.ts +23 -0
  164. package/src/app/providers/voice/voice-streaming.service.ts +702 -0
  165. package/src/app/providers/voice/voice-streaming.types.ts +112 -0
  166. package/src/app/providers/voice/voice.service.spec.ts +227 -0
  167. package/src/app/providers/voice/voice.service.ts +973 -0
  168. package/src/app/sass/_variables.scss +3 -0
  169. package/src/app/sass/animations.scss +19 -1
  170. package/src/app/shims/onnxruntime-web-wasm.ts +4 -0
  171. package/src/app/utils/globals.ts +21 -1
  172. package/src/app/utils/json-sources-utils.ts +27 -0
  173. package/src/app/utils/url-utils.ts +98 -0
  174. package/src/app/utils/utils-resources.ts +1 -1
  175. package/src/assets/i18n/en.json +106 -99
  176. package/src/assets/i18n/es.json +107 -100
  177. package/src/assets/i18n/fr.json +107 -100
  178. package/src/assets/i18n/it.json +107 -98
  179. package/src/assets/onnx/ort-wasm-simd-threaded.mjs +59 -0
  180. package/src/assets/onnx/ort-wasm-simd-threaded.wasm +0 -0
  181. package/src/assets/sounds/keyboard.mp3 +0 -0
  182. package/src/assets/twp/chatbot-panel.html +3 -1
  183. package/src/assets/twp/index-dev.html +18 -0
  184. package/src/assets/twp/tiledesk_widget_files/widget-css-override-example.css +14 -0
  185. package/src/assets/vad/silero_vad_legacy.onnx +0 -0
  186. package/src/assets/vad/vad.worklet.bundle.min.js +1 -0
  187. package/src/chat21-core/models/message.ts +2 -1
  188. package/src/chat21-core/providers/chat-manager.spec.ts +72 -0
  189. package/src/chat21-core/providers/firebase/firebase-conversation-handler.ts +3 -2
  190. package/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts +12 -0
  191. package/src/chat21-core/providers/scripts/script.service.spec.ts +12 -2
  192. package/src/chat21-core/providers/tiledesk/tiledesk-requests.service.ts +1 -1
  193. package/src/chat21-core/utils/constants.ts +4 -0
  194. package/src/chat21-core/utils/utils-message.ts +45 -6
  195. package/src/chat21-core/utils/utils.ts +5 -2
  196. package/src/widget-config-template.json +4 -1
  197. package/src/widget-config.json +4 -1
  198. package/tests/widget-form-rich.spec.ts +67 -0
  199. package/tests/widget-index-dev-settings.spec.ts +52 -0
  200. package/tests/widget-twp-iframe.spec.ts +39 -0
  201. package/tsconfig.json +5 -0
@@ -1,6 +1,10 @@
1
- import { async, ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
1
+ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2
2
  import { By } from '@angular/platform-browser';
3
- import { MSG_STATUS_SENT } from 'src/chat21-core/utils/constants';
3
+ import {
4
+ MSG_STATUS_RETURN_RECEIPT,
5
+ MSG_STATUS_SENT,
6
+ MSG_STATUS_SENT_SERVER,
7
+ } from 'src/app/utils/constants';
4
8
 
5
9
  import { ReturnReceiptComponent } from './return-receipt.component';
6
10
 
@@ -10,31 +14,48 @@ describe('ReturnReceiptComponent', () => {
10
14
 
11
15
  beforeEach(waitForAsync(() => {
12
16
  TestBed.configureTestingModule({
13
- declarations: [ ReturnReceiptComponent ]
14
- })
15
- .compileComponents();
17
+ declarations: [ReturnReceiptComponent],
18
+ }).compileComponents();
16
19
  }));
17
20
 
18
21
  beforeEach(() => {
19
22
  fixture = TestBed.createComponent(ReturnReceiptComponent);
20
23
  component = fixture.componentInstance;
21
- fixture.detectChanges();
22
24
  });
23
25
 
24
26
  it('should create', () => {
27
+ fixture.detectChanges();
25
28
  expect(component).toBeTruthy();
26
29
  });
27
30
 
28
- it('shold render MSG_STATUS_SENT icon', ()=> {
29
- component.status= MSG_STATUS_SENT
31
+ it('should render schedule icon when status is falsy', () => {
32
+ component.status = 0 as any;
33
+ fixture.detectChanges();
34
+ const icons = fixture.debugElement.queryAll(By.css('.icon'));
35
+ expect(icons.length).toBe(1);
36
+ });
37
+
38
+ it('should render sent icon for MSG_STATUS_SENT', () => {
39
+ component.status = MSG_STATUS_SENT;
40
+ fixture.detectChanges();
41
+ expect(fixture.debugElement.queryAll(By.css('.icon')).length).toBe(1);
42
+ });
43
+
44
+ it('should render server-sent icon for MSG_STATUS_SENT_SERVER', () => {
45
+ component.status = MSG_STATUS_SENT_SERVER;
46
+ fixture.detectChanges();
47
+ expect(fixture.debugElement.queryAll(By.css('.icon')).length).toBe(1);
48
+ });
49
+
50
+ it('should render return receipt icon for MSG_STATUS_RETURN_RECEIPT', () => {
51
+ component.status = MSG_STATUS_RETURN_RECEIPT;
30
52
  fixture.detectChanges();
31
- expect(component.status).toBe(MSG_STATUS_SENT)
32
- })
33
-
34
- // it('shold render MSG_STATUS_SENT icon', ()=> {
35
- // component.status= MSG_STATUS_SENT
36
- // fixture.detectChanges();
37
- // let element = fixture.debugElement.query(By.css('icon'))
38
- // expect(element.classes).toBeE('icon')
39
- // })
53
+ expect(fixture.debugElement.queryAll(By.css('.icon')).length).toBe(1);
54
+ });
55
+
56
+ it('should expose status constants on component', () => {
57
+ expect(component.MSG_STATUS_SENT).toBe(MSG_STATUS_SENT);
58
+ expect(component.MSG_STATUS_SENT_SERVER).toBe(MSG_STATUS_SENT_SERVER);
59
+ expect(component.MSG_STATUS_RETURN_RECEIPT).toBe(MSG_STATUS_RETURN_RECEIPT);
60
+ });
40
61
  });
@@ -1,3 +1,3 @@
1
- <p #messageEl class="message_innerhtml marked"
2
- [innerHTML]="printMessage(text, messageEl, this) | marked"
3
- [style.color]="color"></p>
1
+ <div #messageEl class="message_innerhtml marked"
2
+ [innerHTML]="printMessage(text, messageEl, this) | marked"
3
+ [style.color]="color"></div>
@@ -1,113 +1,107 @@
1
- // Shadow DOM styles - isolati dal resto dell'applicazione
2
1
  :host {
3
2
  display: block;
4
- // Le variabili CSS custom properties possono attraversare il boundary del Shadow DOM
5
3
  font-size: var(--font-size-bubble-message, 14px);
6
4
  }
7
5
 
8
6
  .message_innerhtml {
9
7
  margin: 0px;
10
- // padding: 0px 14px;
11
- &.marked{
8
+
9
+ &.marked {
12
10
  padding: 12px 16px;
13
- margin-block-start: 0em!important;
14
- margin-block-end: 0em!important;
11
+ margin-block-start: 0em !important;
12
+ margin-block-end: 0em !important;
15
13
  }
16
-
14
+
17
15
  .text-message {
18
16
  padding-top: 14px;
19
17
  }
20
- }
21
18
 
22
- p {
23
- font-size: inherit;
24
- margin: 0;
25
- // padding: 14px;
26
- line-height: 1.4em;
27
- font-style: normal;
28
- letter-spacing: normal;
29
- font-stretch: normal;
30
- font-variant: normal;
31
- font-weight: 300;
32
- overflow: hidden;
33
- }
19
+ p {
20
+ font-size: inherit;
21
+ margin: 0;
22
+ line-height: 1.4em;
23
+ font-style: normal;
24
+ letter-spacing: normal;
25
+ font-stretch: normal;
26
+ font-variant: normal;
27
+ font-weight: 300;
28
+ overflow: hidden;
29
+ }
34
30
 
35
- p ::ng-deep a,
36
- p a {
37
- word-break: break-word;
38
- color: inherit; // Eredita il colore dal parent
39
- text-decoration: underline;
40
- }
31
+ a {
32
+ word-break: break-word;
33
+ color: inherit;
34
+ text-decoration: underline;
35
+ }
41
36
 
42
- p ::ng-deep p,
43
- p a:hover{
44
- margin-block-end: 0em;
45
- margin-block-start: 0em;
46
- }
37
+ a:hover {
38
+ margin-block-end: 0em;
39
+ margin-block-start: 0em;
40
+ }
47
41
 
48
- p ol {
49
- margin-block-end: 0em;
50
- margin-block-start: 0em;
51
- padding-inline-start: 15px;
52
-
53
- li::before {
54
- content: "";
55
- font-size: 1.4em;
56
- vertical-align: middle;
42
+ ol {
43
+ margin-block-end: 0em;
44
+ margin-block-start: 0em;
45
+ padding-inline-start: 15px;
46
+
47
+ li::before {
48
+ content: "";
49
+ font-size: 1.4em;
50
+ vertical-align: middle;
51
+ }
57
52
  }
58
- }
59
53
 
60
- // Stili aggiuntivi per elementi markdown comuni
61
- p h1, p h2, p h3, p h4, p h5, p h6 {
62
- margin-block-start: 0.5em;
63
- margin-block-end: 0.5em;
64
- font-weight: bold;
65
- color: inherit; // Eredita il colore dal parent
66
- }
54
+ h1, h2, h3, h4, h5, h6 {
55
+ margin-block-start: 0.5em;
56
+ margin-block-end: 0.5em;
57
+ font-weight: bold;
58
+ color: inherit;
59
+ }
67
60
 
68
- .message_innerhtml.marked h1 {
69
- line-height: normal;
70
- }
61
+ &.marked h1 {
62
+ line-height: normal;
63
+ }
71
64
 
72
- p ul {
73
- margin-block-end: 0em;
74
- margin-block-start: 0em;
75
- padding-inline-start: 15px;
76
- }
65
+ ul {
66
+ margin-block-end: 0em;
67
+ margin-block-start: 0em;
68
+ padding-inline-start: 15px;
69
+ }
77
70
 
78
- p code {
79
- background-color: rgba(0, 0, 0, 0.05);
80
- padding: 2px 4px;
81
- border-radius: 3px;
82
- font-family: monospace;
83
- }
71
+ code {
72
+ background-color: rgba(0, 0, 0, 0.05);
73
+ padding: 2px 4px;
74
+ border-radius: 3px;
75
+ font-family: monospace;
76
+ }
84
77
 
85
- p pre {
86
- background-color: rgba(0, 0, 0, 0.05);
87
- padding: 10px;
88
- border-radius: 3px;
89
- overflow-x: auto;
90
- }
78
+ pre {
79
+ background-color: rgba(0, 0, 0, 0.05);
80
+ padding: 10px;
81
+ border-radius: 3px;
82
+ overflow-x: auto;
83
+ }
91
84
 
92
- p blockquote {
93
- border-left: 3px solid rgba(0, 0, 0, 0.1);
94
- padding-left: 10px;
95
- margin-left: 0;
96
- font-style: italic;
97
- }
85
+ blockquote {
86
+ border-left: 3px solid rgba(0, 0, 0, 0.1);
87
+ padding-left: 10px;
88
+ margin-left: 0;
89
+ font-style: italic;
90
+ }
98
91
 
99
- p table {
100
- border-collapse: collapse;
101
- width: 100%;
102
- margin: 10px 0;
103
- }
92
+ table {
93
+ border-collapse: collapse;
94
+ width: 100%;
95
+ margin: 10px 0;
96
+ }
104
97
 
105
- p table td, p table th {
106
- border: 1px solid rgba(0, 0, 0, 0.1);
107
- padding: 8px;
108
- }
98
+ table td, table th {
99
+ border: 1px solid rgba(0, 0, 0, 0.1);
100
+ padding: 8px;
101
+ }
109
102
 
110
- p table th {
111
- background-color: rgba(0, 0, 0, 0.05);
112
- font-weight: bold;
103
+ table th {
104
+ background-color: rgba(0, 0, 0, 0.05);
105
+ font-weight: bold;
106
+ }
113
107
  }
@@ -1,33 +1,126 @@
1
- import { HtmlEntitiesEncodePipe } from './../../../pipe/html-entities-encode.pipe';
2
- import { MarkedPipe } from './../../../pipe/marked.pipe';
3
- import { async, ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
1
+ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
4
2
 
3
+ import { MarkedPipe } from '../../../pipe/marked.pipe';
5
4
  import { TextComponent } from './text.component';
6
5
 
7
- describe('TextComponent', () => {
6
+ /**
7
+ * Il template usa solo `| marked` su ciò che ritorna `printMessage(...)`:
8
+ * `[innerHTML]="printMessage(text, messageEl, this) | marked"`
9
+ * I test qui riproducono gli stessi use case (XSS / HTML grezzo / markdown) sulla pipeline reale del componente.
10
+ */
11
+ describe('TextComponent (render via MarkedPipe)', () => {
8
12
  let component: TextComponent;
9
13
  let fixture: ComponentFixture<TextComponent>;
14
+ let markedPipe: MarkedPipe;
15
+
16
+ function shadowInnerHtml(): string {
17
+ const host = fixture.nativeElement as HTMLElement;
18
+ const root = host.shadowRoot;
19
+ if (!root) {
20
+ throw new Error('Expected ShadowDom root');
21
+ }
22
+ return (root.querySelector('.message_innerhtml') as HTMLElement).innerHTML;
23
+ }
10
24
 
11
25
  beforeEach(waitForAsync(() => {
12
26
  TestBed.configureTestingModule({
13
- declarations: [
14
- TextComponent,
15
- MarkedPipe,
16
- HtmlEntitiesEncodePipe
17
- ]
18
- })
19
- .compileComponents();
27
+ declarations: [TextComponent, MarkedPipe],
28
+ }).compileComponents();
20
29
  }));
21
30
 
22
31
  beforeEach(() => {
23
32
  fixture = TestBed.createComponent(TextComponent);
24
33
  component = fixture.componentInstance;
25
- component.text = 'Msg text'
26
- component.color= 'black'
34
+ markedPipe = new MarkedPipe();
35
+ component.text = 'Msg text';
36
+ component.color = 'black';
27
37
  fixture.detectChanges();
28
38
  });
29
39
 
30
40
  it('should create', () => {
31
41
  expect(component).toBeTruthy();
32
42
  });
43
+
44
+ it('printMessage should emit before and after and return text (input grezzo per la pipe)', () => {
45
+ spyOn(component.onBeforeMessageRender, 'emit');
46
+ spyOn(component.onAfterMessageRender, 'emit');
47
+ const out = component.printMessage('Hello', {} as any, component);
48
+ expect(out).toBe('Hello');
49
+ expect(component.onBeforeMessageRender.emit).toHaveBeenCalled();
50
+ expect(component.onAfterMessageRender.emit).toHaveBeenCalled();
51
+ });
52
+
53
+ it('should render message container with color style', () => {
54
+ const host = fixture.nativeElement as HTMLElement;
55
+ const el = host.shadowRoot!.querySelector('div.message_innerhtml') as HTMLElement;
56
+ expect(el).toBeTruthy();
57
+ expect(el.style.color).toBe('black');
58
+ });
59
+
60
+ describe('markdown (use case contenuto legittimo)', () => {
61
+ it('should render heading and bold from markdown', () => {
62
+ component.text = '# Title\n\n**Bold**';
63
+ fixture.detectChanges();
64
+ const html = shadowInnerHtml();
65
+ expect(html).toMatch(/<h1|<h2/i);
66
+ expect(html).toMatch(/<strong>|<b>/i);
67
+ });
68
+
69
+ it('should render unordered list from markdown', () => {
70
+ component.text = '- uno\n- due';
71
+ fixture.detectChanges();
72
+ const html = shadowInnerHtml();
73
+ expect(html).toMatch(/<ul/i);
74
+ expect(html).toMatch(/<li/i);
75
+ });
76
+
77
+ it('should render safe https link with rel=noopener (MarkedPipe renderer)', () => {
78
+ component.text = '[label](https://example.com/path)';
79
+ fixture.detectChanges();
80
+ const html = shadowInnerHtml();
81
+ expect(html).toContain('https://example.com/path');
82
+ expect(html).toContain('rel="noopener noreferrer"');
83
+ expect(html).toContain('target="_blank"');
84
+ });
85
+ });
86
+
87
+ describe('sicurezza / anti code-injection (stesso use case, solo marked)', () => {
88
+ it('should not leave raw script tags in DOM innerHTML', () => {
89
+ component.text = '<script>alert(1)</script>testo';
90
+ fixture.detectChanges();
91
+ const html = shadowInnerHtml();
92
+ expect(html.toLowerCase()).not.toContain('<script');
93
+ expect(html).toContain('&lt;');
94
+ });
95
+
96
+ it('should escape inline HTML img/onerror so it is not a live <img> node', () => {
97
+ component.text = 'Hi <img src=x onerror="alert(1)">';
98
+ fixture.detectChanges();
99
+ const html = shadowInnerHtml();
100
+ expect(html.toLowerCase()).not.toContain('<img');
101
+ expect(html).toContain('&lt;');
102
+ });
103
+
104
+ it('should not emit javascript: href for markdown link', () => {
105
+ component.text = '[bad](javascript:void(0))';
106
+ fixture.detectChanges();
107
+ const html = shadowInnerHtml();
108
+ expect(html).not.toMatch(/href=["']javascript:/i);
109
+ });
110
+
111
+ it('should not emit data: href for markdown link', () => {
112
+ component.text = '[bad](data:text/html,<script>alert(1)</script>)';
113
+ fixture.detectChanges();
114
+ const html = shadowInnerHtml();
115
+ expect(html).not.toMatch(/href=["']data:/i);
116
+ });
117
+
118
+ it('DOM innerHTML should match MarkedPipe applied to printMessage output (stessa pipeline del template)', () => {
119
+ component.text = 'Line1\n\n**x**';
120
+ fixture.detectChanges();
121
+ const raw = component.printMessage(component.text, {} as any, component);
122
+ const viaPipe = markedPipe.transform(raw) as string;
123
+ expect(shadowInnerHtml()).toBe(viaPipe);
124
+ });
125
+ });
33
126
  });
@@ -1,33 +1,154 @@
1
- import { ActionButtonComponent } from './../message/buttons/action-button/action-button.component';
2
- import { TextButtonComponent } from './../message/buttons/text-button/text-button.component';
3
- import { LinkButtonComponent } from './../message/buttons/link-button/link-button.component';
4
- import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
1
+ import { CommonModule } from '@angular/common';
2
+ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
3
+ import { By } from '@angular/platform-browser';
4
+
5
+ import { MessageModel } from 'src/chat21-core/models/message';
6
+ import { ActionButtonComponent } from '../message/buttons/action-button/action-button.component';
7
+ import { LinkButtonComponent } from '../message/buttons/link-button/link-button.component';
8
+ import { TextButtonComponent } from '../message/buttons/text-button/text-button.component';
5
9
 
6
10
  import { MessageAttachmentComponent } from './message-attachment.component';
7
11
 
12
+ function makeMessageWithAttachment(buttons: any[]): MessageModel {
13
+ return new MessageModel(
14
+ 'm1',
15
+ 'it',
16
+ 'r1',
17
+ 'Recipient',
18
+ 's1',
19
+ 'Sender',
20
+ 200,
21
+ {},
22
+ 'testo',
23
+ Date.now(),
24
+ 'text',
25
+ {
26
+ attachment: {
27
+ type: 'template',
28
+ buttons,
29
+ },
30
+ },
31
+ 'chat',
32
+ true,
33
+ false,
34
+ );
35
+ }
36
+
8
37
  describe('MessageAttachmentComponent', () => {
9
38
  let component: MessageAttachmentComponent;
10
39
  let fixture: ComponentFixture<MessageAttachmentComponent>;
11
40
 
12
41
  beforeEach(waitForAsync(() => {
13
42
  TestBed.configureTestingModule({
14
- declarations: [
15
- MessageAttachmentComponent,
16
- LinkButtonComponent,
17
- TextButtonComponent,
18
- ActionButtonComponent
19
- ]
20
- })
21
- .compileComponents();
43
+ imports: [CommonModule],
44
+ declarations: [
45
+ MessageAttachmentComponent,
46
+ LinkButtonComponent,
47
+ TextButtonComponent,
48
+ ActionButtonComponent,
49
+ ],
50
+ }).compileComponents();
22
51
  }));
23
52
 
24
53
  beforeEach(() => {
25
54
  fixture = TestBed.createComponent(MessageAttachmentComponent);
26
55
  component = fixture.componentInstance;
27
- fixture.detectChanges();
56
+ component.isConversationArchived = false;
57
+ component.isLastMessage = true;
58
+ component.fullscreenMode = false;
59
+ component.limit = 5;
60
+ component.stylesMap = new Map<string, string>([
61
+ ['buttonFontSize', '14px'],
62
+ ['buttonBackgroundColor', '#eee'],
63
+ ['buttonTextColor', '#111'],
64
+ ['buttonHoverBackgroundColor', '#ddd'],
65
+ ['buttonHoverTextColor', '#000'],
66
+ ]);
28
67
  });
29
68
 
30
69
  it('should create', () => {
70
+ component.message = makeMessageWithAttachment([]);
71
+ fixture.detectChanges();
31
72
  expect(component).toBeTruthy();
32
73
  });
74
+
75
+ it('getAttachmentButton should read type and buttons from message.attributes.attachment', () => {
76
+ component.message = makeMessageWithAttachment([
77
+ { type: 'text', value: 'OK' },
78
+ { type: 'url', value: 'Apri', link: 'https://example.com' },
79
+ ]);
80
+ component.ngOnInit();
81
+ expect(component.type).toBe('template');
82
+ expect((component.buttons as unknown as any[]).length).toBe(2);
83
+ });
84
+
85
+ it('should render text and url attachment buttons in DOM when isLastMessage is true for text', () => {
86
+ component.message = makeMessageWithAttachment([
87
+ { type: 'text', value: 'Conferma' },
88
+ { type: 'url', value: 'Vai', link: 'https://example.com', target: '_blank' },
89
+ ]);
90
+ fixture.detectChanges();
91
+ const root = fixture.nativeElement.querySelector('#buttons-in-message') as HTMLElement;
92
+ expect(root).toBeTruthy();
93
+ expect(fixture.nativeElement.querySelector('chat-text-button-attachment')).toBeTruthy();
94
+ expect(fixture.nativeElement.querySelector('chat-link-button-attachment')).toBeTruthy();
95
+ const textBtn = fixture.nativeElement.querySelector('chat-text-button-attachment .text') as HTMLElement;
96
+ expect(textBtn.textContent?.trim()).toContain('Conferma');
97
+ });
98
+
99
+ it('should respect limit via slice (only first button when limit is 1)', () => {
100
+ component.limit = 1;
101
+ component.message = makeMessageWithAttachment([
102
+ { type: 'text', value: 'A' },
103
+ { type: 'text', value: 'B' },
104
+ ]);
105
+ fixture.detectChanges();
106
+ const textButtons = fixture.nativeElement.querySelectorAll('chat-text-button-attachment');
107
+ expect(textButtons.length).toBe(1);
108
+ });
109
+
110
+ it('should hide text and action buttons when isLastMessage is false', () => {
111
+ component.isLastMessage = false;
112
+ component.message = makeMessageWithAttachment([
113
+ { type: 'text', value: 'Nascosto' },
114
+ { type: 'url', value: 'Visibile', link: 'https://x.com' },
115
+ ]);
116
+ fixture.detectChanges();
117
+ expect(fixture.nativeElement.querySelector('chat-text-button-attachment')).toBeNull();
118
+ expect(fixture.nativeElement.querySelector('chat-link-button-attachment')).toBeTruthy();
119
+ });
120
+
121
+ it('returnOnAttachmentButtonClicked should emit structured event when target exists', () => {
122
+ component.message = makeMessageWithAttachment([{ type: 'text', value: 'X' }]);
123
+ fixture.detectChanges();
124
+ spyOn(component.onAttachmentButtonClicked, 'emit');
125
+ const inner = fixture.debugElement.query(By.css('chat-text-button-attachment .text'));
126
+ inner.triggerEventHandler('click', {});
127
+ expect(component.onAttachmentButtonClicked.emit).toHaveBeenCalled();
128
+ const arg = (component.onAttachmentButtonClicked.emit as jasmine.Spy).calls.mostRecent().args[0];
129
+ expect(arg.message).toBe(component.message);
130
+ expect(arg.target).toBeTruthy();
131
+ });
132
+
133
+ it('returnOnAttachmentButtonClicked should not emit when event has no target', () => {
134
+ component.message = makeMessageWithAttachment([{ type: 'text', value: 'X' }]);
135
+ fixture.detectChanges();
136
+ spyOn(component.onAttachmentButtonClicked, 'emit');
137
+ component.returnOnAttachmentButtonClicked({} as any);
138
+ expect(component.onAttachmentButtonClicked.emit).not.toHaveBeenCalled();
139
+ });
140
+
141
+ it('ngAfterViewInit should emit onElementRendered for attachment', () => {
142
+ spyOn(component.onElementRendered, 'emit');
143
+ component.message = makeMessageWithAttachment([{ type: 'url', value: 'L', link: 'https://a' }]);
144
+ fixture.detectChanges();
145
+ component.ngAfterViewInit();
146
+ expect(component.onElementRendered.emit).toHaveBeenCalledWith({ element: 'attachment', status: true });
147
+ });
148
+
149
+ it('should render action button when type is action and isLastMessage', () => {
150
+ component.message = makeMessageWithAttachment([{ type: 'action', value: 'Azione', action: 'reply' }]);
151
+ fixture.detectChanges();
152
+ expect(fixture.nativeElement.querySelector('chat-action-button-attachment')).toBeTruthy();
153
+ });
33
154
  });
@@ -1,24 +1,25 @@
1
- <!-- <div id="chat21-modal-content modal-body"></div> -->
2
- <!-- tabindex="1200"-->
3
-
4
- <div id="chat21-selection-department"
1
+ <div id="chat21-selection-department"
5
2
  #afSelectionDepartment
6
- tabindex="1200"
3
+ role="dialog"
7
4
  aria-modal="true"
8
- onFocus="document.querySelector('[start-focus-chat21-selection-department]').focus()">
5
+ cdkTrapFocus
6
+ [cdkTrapFocusAutoCapture]="true"
7
+ [attr.aria-label]="g.LABEL_SELECT_TOPIC">
9
8
 
10
9
  <!-- HEADER -->
11
- <div class="c21-header" [ngStyle]="{'color': g.themeForegroundColor, 'background-image': g.colorGradient180 }" >
10
+ <div class="c21-header" [ngStyle]="{'color': g.themeForegroundColor, 'background-image': g.colorGradient180 }">
12
11
  <div class="c21-header-container">
13
12
 
14
- <!-- ICON CLOSE CHAT -->
13
+ <!-- ICON CLOSE PANEL -->
15
14
  <div class="c21-header-button">
16
- <div class="c21-close-button c21-small" role="button">
17
- <button tabindex="1210" aria-label=" chiudi pannello" class="c21-close-button-body" (click)="closePage()">
18
- <svg role="img" aria-labelledby="altIconTitle" xmlns="http://www.w3.org/2000/svg" width="20px" height="20px" viewBox="0 0 24 24">
15
+ <div class="c21-close-button c21-small">
16
+ <button type="button"
17
+ [attr.aria-label]="g.BUTTON_CLOSE_TO_ICON || 'Close panel'"
18
+ class="c21-close-button-body"
19
+ (click)="closePage()">
20
+ <svg aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" width="20px" height="20px" viewBox="0 0 24 24">
19
21
  <path fill="none" d="M0 0h24v24H0V0z"/>
20
22
  <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/>
21
- <!-- <title id="altIconTitle">{{BUTTON_CLOSE_CHAT}}</title> -->
22
23
  </svg>
23
24
  </button>
24
25
  </div>
@@ -26,9 +27,7 @@
26
27
 
27
28
  <!-- CONTENT HEADER -->
28
29
  <div class="c21-header-content">
29
- <!-- TITLE HEADER -->
30
30
  <div class="c21-title" [ngStyle]="{'color': g.themeForegroundColor}">
31
- <!-- <span>{{g.LABEL_SELECT_TOPIC}}</span> -->
32
31
  </div>
33
32
  </div>
34
33
 
@@ -40,15 +39,17 @@
40
39
  <div class="c21-body-container">
41
40
 
42
41
  <div class="c21-body-header">
43
- <div start-focus-chat21-selection-department tabindex="1201" class="c21-message-field">{{g.LABEL_SELECT_TOPIC}}</div>
42
+ <h2 start-focus-chat21-selection-department class="c21-message-field">{{g.LABEL_SELECT_TOPIC}}</h2>
44
43
  </div>
45
44
 
46
- <div class="c21-body-content" tabindex="211" onFocus="document.querySelector('[start-focus]').focus()">
45
+ <div class="c21-body-content">
47
46
  <ul class="chat21-content-modal-select">
48
47
  <li *ngFor="let department of departments; let i = index">
49
- <button tabindex="1202" class="c21-button-department c21-button-clean" (click)="onSelectDepartment(department)">
50
- <span class="chat21-badge">{{i+1}}</span>
51
- <span class="chat21-name-list" >{{department?.name}}</span>
48
+ <button type="button"
49
+ class="c21-button-department c21-button-clean"
50
+ (click)="onSelectDepartment(department)">
51
+ <span class="chat21-badge" aria-hidden="true">{{i+1}}</span>
52
+ <span class="chat21-name-list">{{department?.name}}</span>
52
53
  </button>
53
54
  </li>
54
55
  </ul>
@@ -56,7 +57,4 @@
56
57
 
57
58
  </div>
58
59
  </div>
59
-
60
- <span style="height:0px" tabindex="1299" onFocus="document.querySelector('[start-focus-chat21-selection-department]').focus()"></span>
61
- </div>
62
-
60
+ </div>