55 fixture ,
66 nextFrame ,
77} from '@open-wc/testing' ;
8- import { html } from 'lit' ;
8+ import { html , nothing } from 'lit' ;
99import { type SinonFakeTimers , spy , useFakeTimers } from 'sinon' ;
1010import type IgcIconButtonComponent from '../button/icon-button.js' ;
1111import {
@@ -26,6 +26,7 @@ import {
2626import { simulateFileUpload } from '../file-input/file-input.spec.js' ;
2727import IgcInputComponent from '../input/input.js' ;
2828import IgcChatComponent from './chat.js' ;
29+ import type { IgcMessage , IgcMessageAttachment } from './types.js' ;
2930
3031describe ( 'Chat' , ( ) => {
3132 before ( ( ) => {
@@ -43,18 +44,22 @@ describe('Chat', () => {
4344 } ;
4445
4546 const messageTemplate = ( msg : any ) => {
46- return html `< div >
47- < h5 > ${ msg . sender === 'user' ? 'You' : 'Bot' } :</ h5 >
48- < p > ${ msg . text } </ p >
49- </ div > ` ;
47+ return html `
48+ < div >
49+ < h5 > ${ msg . sender === 'user' ? 'You' : 'Bot' } :</ h5 >
50+ < p > ${ msg . text } </ p >
51+ </ div >
52+ ` ;
5053 } ;
5154
52- const messageActionsTemplate = ( msg : any ) => {
55+ const messageActionsTemplate = ( msg : IgcMessage ) => {
5356 return msg . sender !== 'user' && msg . text . trim ( )
54- ? html `< div style ="float: right ">
55- < igc-button name ="regenerate " variant ="flat "> ...</ igc-button >
56- </ div > `
57- : html `` ;
57+ ? html `
58+ < div style ="float: right ">
59+ < igc-button name ="regenerate " variant ="flat "> ...</ igc-button >
60+ </ div >
61+ `
62+ : nothing ;
5863 } ;
5964
6065 const typingIndicatorTemplate = html `< span > loading...</ span > ` ;
@@ -68,51 +73,51 @@ describe('Chat', () => {
6873 } ;
6974
7075 const attachmentContentTemplate = ( attachment : any ) => {
71- return html `< p >
72- This is a template rendered as content of ${ attachment . name }
73- </ p > ` ;
76+ return html `
77+ < p > This is a template rendered as content of ${ attachment . name } </ p >
78+ ` ;
7479 } ;
7580
76- const textInputTemplate = ( text : string ) =>
77- html `< igc-input
78- placeholder ="Type text here... "
79- .value =${ text }
80- > </ igc-input > ` ;
81+ const textInputTemplate = ( text : string ) => html `
82+ < igc-input placeholder ="Type text here... " .value =${ text } > </ igc-input >
83+ ` ;
8184
82- const textAreaActionsTemplate = ( ctx : any ) =>
83- html `< div >
84- ${ ctx . defaults . fileUploadButton ( ctx ) }
85+ const textAreaActionsTemplate = ( ) => html `
86+ < div >
8587 < igc-button > Upload</ igc-button >
8688 < igc-button > Send</ igc-button >
87- </ div > ` ;
88-
89- const textAreaAttachmentsTemplate = ( attachments : any [ ] ) => {
90- return html `< div >
91- ${ attachments . map (
92- ( attachment ) =>
93- html `< a
94- href =${ attachment . file
95- ? URL . createObjectURL ( attachment . file )
96- : attachment . url }
97- target ="_blank"
98- > ${ attachment . name } </ a
99- > `
100- ) }
101- </ div > ` ;
89+ </ div >
90+ ` ;
91+
92+ const textAreaAttachmentsTemplate = ( attachments : IgcMessageAttachment [ ] ) => {
93+ return html `
94+ < div >
95+ ${ attachments . map (
96+ ( attachment ) => html `
97+ < a
98+ href =${ attachment . file
99+ ? URL . createObjectURL ( attachment . file )
100+ : ( attachment . url ?? '' ) }
101+ target ="_blank"
102+ >
103+ ${ attachment . name }
104+ </ a >
105+ `
106+ ) }
107+ </ div >
108+ ` ;
102109 } ;
103110
104- const messages : any [ ] = [
111+ const messages : IgcMessage [ ] = [
105112 {
106113 id : '1' ,
107114 text : 'Hello! How can I help you today?' ,
108115 sender : 'bot' ,
109- timestamp : new Date ( Date . now ( ) - 3600000 ) ,
110116 } ,
111117 {
112118 id : '2' ,
113119 text : 'Hello!' ,
114120 sender : 'user' ,
115- timestamp : new Date ( Date . now ( ) - 3500000 ) ,
116121 attachments : [
117122 {
118123 id : 'img1' ,
@@ -126,7 +131,6 @@ describe('Chat', () => {
126131 id : '3' ,
127132 text : 'Thank you!' ,
128133 sender : 'bot' ,
129- timestamp : new Date ( Date . now ( ) - 3400000 ) ,
130134 attachments : [
131135 {
132136 id : 'file1' ,
@@ -140,7 +144,6 @@ describe('Chat', () => {
140144 id : '4' ,
141145 text : 'Thank you too!' ,
142146 sender : 'user' ,
143- timestamp : new Date ( Date . now ( ) - 3300000 ) ,
144147 } ,
145148 ] ;
146149
@@ -333,7 +336,6 @@ describe('Chat', () => {
333336 id : '1' ,
334337 text : '<script>alert("XSS")</script> Hello!' ,
335338 sender : 'bot' ,
336- timestamp : new Date ( Date . now ( ) - 3600000 ) ,
337339 } ,
338340 ] ;
339341 chat = await fixture < IgcChatComponent > (
@@ -1176,7 +1178,7 @@ describe('Chat', () => {
11761178 chat . options = {
11771179 renderers : {
11781180 input : ( ctx ) => textInputTemplate ( ctx . value ) ,
1179- inputActions : ( ctx ) => textAreaActionsTemplate ( ctx ) ,
1181+ inputActions : ( ) => textAreaActionsTemplate ( ) ,
11801182 inputAttachments : ( ctx ) =>
11811183 textAreaAttachmentsTemplate ( ctx . attachments ) ,
11821184 } ,
@@ -1198,25 +1200,6 @@ describe('Chat', () => {
11981200 </div>
11991201 <div part="buttons-container">
12001202 <div>
1201- <label
1202- for="input_attachments"
1203- part="upload-button"
1204- >
1205- <igc-icon-button
1206- aria-label="Attach files"
1207- name="attach_file"
1208- type="button"
1209- variant="flat"
1210- >
1211- </igc-icon-button>
1212- <input
1213- id="input_attachments"
1214- aria-label="Upload button"
1215- multiple=""
1216- name="input_attachments"
1217- type="file"
1218- >
1219- </label>
12201203 <igc-button type="button" variant="contained">Upload</igc-button>
12211204 <igc-button type="button" variant="contained">Send</igc-button>
12221205 </div>
@@ -1631,7 +1614,7 @@ describe('Chat', () => {
16311614
16321615 simulateClick ( attachmentHeader ) ;
16331616 expect ( eventSpy ) . calledWith ( 'igcAttachmentClick' , {
1634- detail : { ...messages [ 1 ] . attachments [ 0 ] } ,
1617+ detail : { ...messages [ 1 ] . attachments ?. at ( 0 ) } ,
16351618 } ) ;
16361619 } ) ;
16371620
0 commit comments