@@ -7,6 +7,7 @@ import useSessionContext from '../useSessionContext';
7
7
import { SessionContextType } from '../../Context/SessionProvider/session' ;
8
8
import useEmoji , { EmojiWrapper } from '../useEmoji' ;
9
9
import VonageVideoClient from '../../utils/VonageVideoClient' ;
10
+ import { SignalEvent , SubscriberWrapper } from '../../types/session' ;
10
11
11
12
vi . mock ( '../useSessionContext' ) ;
12
13
@@ -34,7 +35,7 @@ describe('useEmoji', () => {
34
35
vonageVideoClient = {
35
36
current : Object . assign ( new EventEmitter ( ) , {
36
37
signal : vi . fn ( ) ,
37
- connectionId : 'connection-id ' ,
38
+ connectionId : '123 ' ,
38
39
} ) as unknown as VonageVideoClient ,
39
40
} ;
40
41
@@ -84,13 +85,10 @@ describe('useEmoji', () => {
84
85
} ) ;
85
86
86
87
expect ( vonageVideoClient . current ?. signal ) . toBeCalledTimes ( 1 ) ;
87
- expect ( vonageVideoClient . current ?. signal ) . toBeCalledWith (
88
- {
89
- type : 'emoji' ,
90
- data : '{"emoji":"❤️","time":12000000}' ,
91
- } ,
92
- expect . any ( Function )
93
- ) ;
88
+ expect ( vonageVideoClient . current ?. signal ) . toBeCalledWith ( {
89
+ type : 'emoji' ,
90
+ data : '{"emoji":"❤️","time":12000000}' ,
91
+ } ) ;
94
92
} ) ;
95
93
96
94
it ( 'when called multiple times, sendEmoji throttles calls to once every 500ms' , async ( ) => {
@@ -118,22 +116,29 @@ describe('useEmoji', () => {
118
116
it ( 'adds emojis to the queue when a signal event is received and gets the correct sender name' , async ( ) => {
119
117
const { result } = renderHook ( ( ) => useEmoji ( { vonageVideoClient } ) ) ;
120
118
119
+ // Mock receiving a signal event from another user
121
120
act ( ( ) => {
122
- // Simulate sending an emoji
123
- result . current . sendEmoji ( '❤️' ) ;
124
- } ) ;
125
-
126
- // Mock emitting a signal event from another user's connection
127
- act ( ( ) => {
128
- vonageVideoClient . current ?. emit ( 'signal' , {
121
+ const signalEvent : SignalEvent = {
129
122
type : 'signal:emoji' ,
130
123
data : JSON . stringify ( {
131
124
emoji : '❤️' ,
132
125
time : Date . now ( ) ,
133
126
connectionId : mockConnection . connectionId , // Different from the session connection
134
- } ) ,
127
+ } ) as unknown as string ,
135
128
from : { connectionId : '456' , creationTime : 1 , data : 'some-data' } ,
136
- } ) ;
129
+ } ;
130
+ const subscriberWrapper : SubscriberWrapper = {
131
+ subscriber : {
132
+ stream : {
133
+ connection : {
134
+ connectionId : '456' ,
135
+ } ,
136
+ name : 'John Doe' ,
137
+ } ,
138
+ } ,
139
+ } as unknown as SubscriberWrapper ;
140
+ const subscriberWrappers = [ subscriberWrapper ] ;
141
+ result . current . onEmoji ( signalEvent , subscriberWrappers ) ;
137
142
} ) ;
138
143
139
144
const expectedEmojiWrapper : EmojiWrapper = {
@@ -147,4 +152,44 @@ describe('useEmoji', () => {
147
152
expect ( result . current . emojiQueue ) . toContainEqual ( expectedEmojiWrapper ) ;
148
153
} ) ;
149
154
} ) ;
155
+
156
+ it ( 'recognizes when a received signal event is from local user' , async ( ) => {
157
+ const { result } = renderHook ( ( ) => useEmoji ( { vonageVideoClient } ) ) ;
158
+
159
+ // Mock receiving a signal event from local user
160
+ act ( ( ) => {
161
+ const signalEvent : SignalEvent = {
162
+ type : 'signal:emoji' ,
163
+ data : JSON . stringify ( {
164
+ emoji : '😲' ,
165
+ time : Date . now ( ) ,
166
+ connectionId : mockConnection . connectionId , // Different from the session connection
167
+ } ) as unknown as string ,
168
+ from : { connectionId : '123' , creationTime : 1 , data : 'some-data' } ,
169
+ } ;
170
+ const subscriberWrapper : SubscriberWrapper = {
171
+ subscriber : {
172
+ stream : {
173
+ connection : {
174
+ connectionId : '123' ,
175
+ } ,
176
+ name : 'That be I' ,
177
+ } ,
178
+ } ,
179
+ } as unknown as SubscriberWrapper ;
180
+ const subscriberWrappers = [ subscriberWrapper ] ;
181
+ result . current . onEmoji ( signalEvent , subscriberWrappers ) ;
182
+ } ) ;
183
+
184
+ const expectedEmojiWrapper : EmojiWrapper = {
185
+ name : 'You' ,
186
+ emoji : '😲' ,
187
+ time : expect . any ( Number ) ,
188
+ } ;
189
+
190
+ // Use waitFor to check if emojiQueue contains the expected emoji
191
+ await waitFor ( ( ) => {
192
+ expect ( result . current . emojiQueue ) . toContainEqual ( expectedEmojiWrapper ) ;
193
+ } ) ;
194
+ } ) ;
150
195
} ) ;
0 commit comments