@@ -36,7 +36,7 @@ import { CustomTemplatesService } from '../custom-templates.service';
3636import { MessageInputConfigService } from './message-input-config.service' ;
3737import { MessageTextComponent } from '../message-text/message-text.component' ;
3838
39- describe ( 'MessageInputComponent' , ( ) => {
39+ fdescribe ( 'MessageInputComponent' , ( ) => {
4040 let nativeElement : HTMLElement ;
4141 let component : MessageInputComponent ;
4242 let fixture : ComponentFixture < MessageInputComponent > ;
@@ -1144,4 +1144,200 @@ describe('MessageInputComponent', () => {
11441144 expect ( queryFileInput ( ) ?. disabled ) . toBe ( true ) ;
11451145 expect ( queryVoiceRecorderButton ( ) ?. disabled ) . toBe ( true ) ;
11461146 } ) ;
1147+
1148+ describe ( 'message draft output' , ( ) => {
1149+ it ( 'should emit undefined when all message fields are cleared' , ( ) => {
1150+ // Parent id doesn't count here
1151+ component . mode = 'thread' ;
1152+ mockActiveParentMessageId$ . next ( 'parentMessageId' ) ;
1153+ attachmentService . mapToAttachments . and . returnValue ( [ ] ) ;
1154+
1155+ attachmentService . resetAttachmentUploads ( ) ;
1156+ component . quotedMessage = undefined ;
1157+ component . textareaValue = '' ;
1158+ component [ 'pollId' ] = undefined ;
1159+ component . mentionedUsers = [ ] ;
1160+
1161+ const messageDraftSpy = jasmine . createSpy ( ) ;
1162+ component . messageDraftChange . subscribe ( messageDraftSpy ) ;
1163+ messageDraftSpy . calls . reset ( ) ;
1164+ component . updateMessageDraft ( ) ;
1165+
1166+ expect ( messageDraftSpy ) . toHaveBeenCalledWith ( undefined ) ;
1167+ } ) ;
1168+
1169+ it ( 'should emit message draft when textarea value changes' , ( ) => {
1170+ const messageDraftSpy = jasmine . createSpy ( ) ;
1171+ component . messageDraftChange . subscribe ( messageDraftSpy ) ;
1172+ messageDraftSpy . calls . reset ( ) ;
1173+ queryTextarea ( ) ?. valueChange . next ( 'Hello, world!' ) ;
1174+
1175+ expect ( messageDraftSpy ) . toHaveBeenCalledWith ( {
1176+ text : 'Hello, world!' ,
1177+ attachments : undefined ,
1178+ mentioned_users : [ ] ,
1179+ parent_id : undefined ,
1180+ quoted_message_id : undefined ,
1181+ poll_id : undefined ,
1182+ } ) ;
1183+ } ) ;
1184+
1185+ it ( 'should emit message draft when mentioned users change' , ( ) => {
1186+ const messageDraftSpy = jasmine . createSpy ( ) ;
1187+ component . messageDraftChange . subscribe ( messageDraftSpy ) ;
1188+ messageDraftSpy . calls . reset ( ) ;
1189+ queryTextarea ( ) ?. userMentions . next ( [ { id : 'user1' , name : 'User 1' } ] ) ;
1190+ fixture . detectChanges ( ) ;
1191+
1192+ expect ( messageDraftSpy ) . toHaveBeenCalledWith (
1193+ jasmine . objectContaining ( {
1194+ mentioned_users : [ 'user1' ] ,
1195+ } )
1196+ ) ;
1197+ } ) ;
1198+
1199+ it ( 'should emit message draft when poll is added' , ( ) => {
1200+ const messageDraftSpy = jasmine . createSpy ( ) ;
1201+ component . messageDraftChange . subscribe ( messageDraftSpy ) ;
1202+ messageDraftSpy . calls . reset ( ) ;
1203+ component . addPoll ( 'poll1' ) ;
1204+ fixture . detectChanges ( ) ;
1205+
1206+ expect ( messageDraftSpy ) . toHaveBeenCalledWith (
1207+ jasmine . objectContaining ( {
1208+ poll_id : 'poll1' ,
1209+ } )
1210+ ) ;
1211+ } ) ;
1212+
1213+ it ( 'should emit message draft when attachment is added' , ( ) => {
1214+ const messageDraftSpy = jasmine . createSpy ( ) ;
1215+ component . messageDraftChange . subscribe ( messageDraftSpy ) ;
1216+ messageDraftSpy . calls . reset ( ) ;
1217+ attachmentService . mapToAttachments . and . returnValue ( [ { type : 'file' } ] ) ;
1218+ attachmentService . attachmentUploads$ . next ( [
1219+ {
1220+ type : 'file' ,
1221+ state : 'success' ,
1222+ url : 'url' ,
1223+ file : { name : 'file.pdf' , type : 'application/pdf' } as File ,
1224+ } as AttachmentUpload ,
1225+ ] ) ;
1226+
1227+ expect ( messageDraftSpy ) . toHaveBeenCalledWith (
1228+ jasmine . objectContaining ( {
1229+ attachments : [ { type : 'file' } ] ,
1230+ } )
1231+ ) ;
1232+ } ) ;
1233+
1234+ it ( 'should not emit if attachment upload is in progress' , ( ) => {
1235+ const messageDraftSpy = jasmine . createSpy ( ) ;
1236+ component . messageDraftChange . subscribe ( messageDraftSpy ) ;
1237+ messageDraftSpy . calls . reset ( ) ;
1238+ attachmentService . mapToAttachments . and . returnValue ( [ ] ) ;
1239+ attachmentService . attachmentUploads$ . next ( [
1240+ {
1241+ type : 'file' ,
1242+ state : 'uploading' ,
1243+ url : 'url' ,
1244+ file : { name : 'file.pdf' , type : 'application/pdf' } as File ,
1245+ } as AttachmentUpload ,
1246+ ] ) ;
1247+
1248+ expect ( messageDraftSpy ) . not . toHaveBeenCalled ( ) ;
1249+ } ) ;
1250+
1251+ it ( 'should emit message draft when custom attachment is added' , ( ) => {
1252+ const messageDraftSpy = jasmine . createSpy ( ) ;
1253+ component . messageDraftChange . subscribe ( messageDraftSpy ) ;
1254+ messageDraftSpy . calls . reset ( ) ;
1255+ const customAttachment = {
1256+ type : 'image' ,
1257+ image_url : 'url' ,
1258+ } ;
1259+ attachmentService . mapToAttachments . and . returnValue ( [ customAttachment ] ) ;
1260+ attachmentService . customAttachments$ . next ( [ customAttachment ] ) ;
1261+
1262+ expect ( messageDraftSpy ) . toHaveBeenCalledWith (
1263+ jasmine . objectContaining ( {
1264+ attachments : [ customAttachment ] ,
1265+ } )
1266+ ) ;
1267+ } ) ;
1268+
1269+ it ( 'should emit undefined if message is sent' , async ( ) => {
1270+ const messageDraftSpy = jasmine . createSpy ( ) ;
1271+ component . messageDraftChange . subscribe ( messageDraftSpy ) ;
1272+ queryTextarea ( ) ?. valueChange . next ( 'Hello' ) ;
1273+ messageDraftSpy . calls . reset ( ) ;
1274+ await component . messageSent ( ) ;
1275+ fixture . detectChanges ( ) ;
1276+
1277+ expect ( messageDraftSpy ) . toHaveBeenCalledOnceWith ( undefined ) ;
1278+ } ) ;
1279+
1280+ it ( 'should not emit undefined even if message request fails (users can retry from preview added to message list)' , async ( ) => {
1281+ const messageDraftSpy = jasmine . createSpy ( ) ;
1282+ component . messageDraftChange . subscribe ( messageDraftSpy ) ;
1283+ queryTextarea ( ) ?. valueChange . next ( 'Hello' ) ;
1284+ messageDraftSpy . calls . reset ( ) ;
1285+ sendMessageSpy . and . throwError ( 'error' ) ;
1286+ await component . messageSent ( ) ;
1287+ fixture . detectChanges ( ) ;
1288+
1289+ expect ( messageDraftSpy ) . toHaveBeenCalledOnceWith ( undefined ) ;
1290+ } ) ;
1291+
1292+ it ( 'should emit if quoted message changes' , ( ) => {
1293+ const messageDraftSpy = jasmine . createSpy ( ) ;
1294+ component . messageDraftChange . subscribe ( messageDraftSpy ) ;
1295+ messageDraftSpy . calls . reset ( ) ;
1296+ const quotedMessage = mockMessage ( ) ;
1297+ mockMessageToQuote$ . next ( quotedMessage ) ;
1298+ fixture . detectChanges ( ) ;
1299+
1300+ expect ( messageDraftSpy ) . toHaveBeenCalledWith (
1301+ jasmine . objectContaining ( {
1302+ quoted_message_id : quotedMessage . id ,
1303+ } )
1304+ ) ;
1305+ } ) ;
1306+
1307+ it ( `shouldn't emit if in edit mode` , ( ) => {
1308+ component . message = mockMessage ( ) ;
1309+ fixture . detectChanges ( ) ;
1310+ const messageDraftSpy = jasmine . createSpy ( ) ;
1311+ component . messageDraftChange . subscribe ( messageDraftSpy ) ;
1312+ messageDraftSpy . calls . reset ( ) ;
1313+ queryTextarea ( ) ?. valueChange . next ( 'Hello' ) ;
1314+ fixture . detectChanges ( ) ;
1315+
1316+ expect ( messageDraftSpy ) . not . toHaveBeenCalled ( ) ;
1317+ } ) ;
1318+
1319+ it ( 'should not emit if active channel changes' , ( ) => {
1320+ const messageDraftSpy = jasmine . createSpy ( ) ;
1321+ component . messageDraftChange . subscribe ( messageDraftSpy ) ;
1322+ queryTextarea ( ) ?. valueChange . next ( 'Hello' ) ;
1323+ messageDraftSpy . calls . reset ( ) ;
1324+ mockActiveChannel$ . next ( {
1325+ ...mockActiveChannel$ . getValue ( ) ,
1326+ id : 'new-channel' ,
1327+ } as any as Channel ) ;
1328+ fixture . detectChanges ( ) ;
1329+
1330+ expect ( messageDraftSpy ) . not . toHaveBeenCalled ( ) ;
1331+ } ) ;
1332+
1333+ it ( `shouldn't emit if parent message id changes (it's basically same as active channel changes)` , ( ) => {
1334+ const messageDraftSpy = jasmine . createSpy ( ) ;
1335+ component . messageDraftChange . subscribe ( messageDraftSpy ) ;
1336+ messageDraftSpy . calls . reset ( ) ;
1337+ mockActiveParentMessageId$ . next ( 'parentMessageId' ) ;
1338+ fixture . detectChanges ( ) ;
1339+
1340+ expect ( messageDraftSpy ) . not . toHaveBeenCalled ( ) ;
1341+ } ) ;
1342+ } ) ;
11471343} ) ;
0 commit comments