@@ -16,31 +16,26 @@ import { MockOfflineDB } from '../offline-support/MockOfflineDB';
1616
1717const generateUuidV4Output = 'test-uuid' ;
1818// Mock dependencies
19- vi . mock ( '../../../src/utils' , ( ) => ( {
19+ vi . mock ( '../../../src/utils' , async ( importOriginal ) => ( {
20+ ...( await importOriginal ( ) ) ,
2021 axiosParamsSerializer : vi . fn ( ) ,
2122 isFunction : vi . fn ( ) ,
2223 isString : vi . fn ( ) ,
2324 isObject : vi . fn ( ) ,
2425 isArray : vi . fn ( ) ,
2526 isDate : vi . fn ( ) ,
2627 isNumber : vi . fn ( ) ,
27- debounce : vi . fn ( ) . mockImplementation ( ( fn ) => fn ) ,
28+ debounce : vi . fn ( ) . mockImplementation ( ( fn ) => {
29+ fn . cancel = ( ) => { } ;
30+ fn . flush = ( ) => { } ;
31+ return fn ;
32+ } ) ,
2833 generateUUIDv4 : vi . fn ( ) . mockReturnValue ( 'test-uuid' ) ,
2934 isLocalMessage : vi . fn ( ) . mockReturnValue ( true ) ,
30- formatMessage : vi . fn ( ) . mockImplementation ( ( msg ) => msg ) ,
3135 randomId : vi . fn ( ) . mockReturnValue ( 'test-uuid' ) ,
3236 throttle : vi . fn ( ) . mockImplementation ( ( fn ) => fn ) ,
3337} ) ) ;
3438
35- vi . mock ( '../../../src/messageComposer/middleware/messageComposer' , ( ) => ( {
36- MessageComposerMiddlewareExecutor : vi . fn ( ) . mockImplementation ( ( ) => ( {
37- execute : vi . fn ( ) . mockResolvedValue ( { state : { } } ) ,
38- } ) ) ,
39- MessageDraftComposerMiddlewareExecutor : vi . fn ( ) . mockImplementation ( ( ) => ( {
40- execute : vi . fn ( ) . mockResolvedValue ( { state : { } } ) ,
41- } ) ) ,
42- } ) ) ;
43-
4439const quotedMessage = {
4540 id : 'quoted-message-id' ,
4641 type : 'regular' as const ,
@@ -877,29 +872,132 @@ describe('MessageComposer', () => {
877872
878873 it ( 'should compose message' , async ( ) => {
879874 const { messageComposer } = setup ( ) ;
880- const mockResult = {
881- state : {
882- message : {
883- id : 'test-message-id' ,
884- text : 'Test message' ,
875+ messageComposer . textComposer . setText ( 'Test message' ) ;
876+
877+ const result = await messageComposer . compose ( ) ;
878+
879+ expect ( result ) . toEqual ( {
880+ localMessage : {
881+ attachments : [ ] ,
882+ created_at : expect . any ( Date ) ,
883+ deleted_at : null ,
884+ error : null ,
885+ id : 'test-uuid' ,
886+ mentioned_users : [ ] ,
887+ parent_id : undefined ,
888+ pinned_at : null ,
889+ quoted_message : null ,
890+ reaction_groups : null ,
891+ status : 'sending' ,
892+ text : 'Test message' ,
893+ type : 'regular' ,
894+ updated_at : expect . any ( Date ) ,
895+ user : {
896+ id : 'user-id' ,
897+ name : 'User Name' ,
885898 } ,
899+ user_id : 'user-id' ,
886900 } ,
887- status : '' ,
888- } ;
901+ message : {
902+ id : 'test-uuid' ,
903+ mentioned_users : [ ] ,
904+ parent_id : undefined ,
905+ text : 'Test message' ,
906+ type : 'regular' ,
907+ } ,
908+ sendOptions : { } ,
909+ } ) ;
910+ } ) ;
889911
890- const spyExecute = vi . spyOn (
891- messageComposer . compositionMiddlewareExecutor ,
892- 'execute' ,
893- ) ;
894- spyExecute . mockResolvedValue ( mockResult ) ;
912+ it ( 'should compose edited message' , async ( ) => {
913+ const date = new Date ( ) ;
914+ const { messageComposer } = setup ( {
915+ composition : {
916+ attachments : [ { type : 'file' } ] ,
917+ created_at : date ,
918+ deleted_at : null ,
919+ id : 'test-uuid' ,
920+ mentioned_users : [ ] ,
921+ pinned : true ,
922+ pinned_at : date ,
923+ // reaction_counts has to be available to infer reaction_groups
924+ reaction_counts : {
925+ like : 1 ,
926+ } ,
927+ // reaction_groups: { like: { count: 1, sum_scores: 1 } },
928+ // reaction_scores has to be available to infer reaction_groups
929+ reaction_scores : {
930+ like : 1 ,
931+ } ,
932+ status : 'received' ,
933+ text : 'Test message' ,
934+ type : 'regular' ,
935+ updated_at : date ,
936+ user : {
937+ id : 'user-id' ,
938+ name : 'User Name' ,
939+ } ,
940+ user_id : 'user-id' ,
941+ } ,
942+ } ) ;
895943
896944 const result = await messageComposer . compose ( ) ;
897945
898- expect ( spyExecute ) . toHaveBeenCalledWith ( {
899- eventName : 'compose' ,
900- initialValue : expect . any ( Object ) ,
946+ expect ( result ) . toEqual ( {
947+ localMessage : {
948+ attachments : [ { type : 'file' } ] ,
949+ created_at : date ,
950+ deleted_at : null ,
951+ error : null ,
952+ id : 'test-uuid' ,
953+ mentioned_users : [ ] ,
954+ parent_id : undefined ,
955+ pinned : true ,
956+ pinned_at : date ,
957+ quoted_message : null ,
958+ reaction_counts : {
959+ like : 1 ,
960+ } ,
961+ reaction_groups : { like : { count : 1 , sum_scores : 1 } } ,
962+ reaction_scores : {
963+ like : 1 ,
964+ } ,
965+ status : 'received' ,
966+ text : 'Test message' ,
967+ type : 'regular' ,
968+ updated_at : date ,
969+ user : {
970+ id : 'user-id' ,
971+ name : 'User Name' ,
972+ } ,
973+ user_id : 'user-id' ,
974+ } ,
975+ message : {
976+ attachments : [
977+ {
978+ type : 'file' ,
979+ } ,
980+ ] ,
981+ id : 'test-uuid' ,
982+ mentioned_users : [ ] ,
983+ parent_id : undefined ,
984+ pinned : true ,
985+ reaction_groups : {
986+ like : {
987+ count : 1 ,
988+ sum_scores : 1 ,
989+ } ,
990+ } ,
991+ reaction_scores : {
992+ like : 1 ,
993+ } ,
994+ status : 'received' ,
995+ text : 'Test message' ,
996+ type : 'regular' ,
997+ user_id : 'user-id' ,
998+ } ,
999+ sendOptions : { } ,
9011000 } ) ;
902- expect ( result ) . toEqual ( mockResult . state ) ;
9031001 } ) ;
9041002
9051003 it ( 'should return undefined when compose middleware returns discard status' , async ( ) => {
0 commit comments