@@ -65,7 +65,10 @@ describe('Cursors (mockClient)', () => {
65
65
it < CursorsTestContext > ( 'emits a cursorsUpdate event' , ( { space, dispensing, batching, fakeMessageStub } ) => {
66
66
const fakeMessage = {
67
67
...fakeMessageStub ,
68
- data : [ { position : { x : 1 , y : 1 } } , { position : { x : 1 , y : 2 } , data : { color : 'red' } } ] ,
68
+ data : [
69
+ { cursor : { position : { x : 1 , y : 1 } } } ,
70
+ { cursor : { position : { x : 1 , y : 2 } , data : { color : 'red' } } } ,
71
+ ] ,
69
72
} ;
70
73
71
74
const spy = vitest . fn ( ) ;
@@ -149,16 +152,16 @@ describe('Cursors (mockClient)', () => {
149
152
150
153
it < CursorsTestContext > ( 'creates an outgoingBuffer for a new cursor movement' , ( { batching, channel } ) => {
151
154
batching . pushCursorPosition ( channel , { position : { x : 1 , y : 1 } , data : { } } ) ;
152
- expect ( batching . outgoingBuffers ) . toEqual ( [ { position : { x : 1 , y : 1 } , data : { } } ] ) ;
155
+ expect ( batching . outgoingBuffers ) . toEqual ( [ { cursor : { position : { x : 1 , y : 1 } , data : { } } , offset : 0 } ] ) ;
153
156
} ) ;
154
157
155
158
it < CursorsTestContext > ( 'adds cursor data to an existing buffer' , ( { batching, channel } ) => {
156
159
batching . pushCursorPosition ( channel , { position : { x : 1 , y : 1 } , data : { } } ) ;
157
- expect ( batching . outgoingBuffers ) . toEqual ( [ { position : { x : 1 , y : 1 } , data : { } } ] ) ;
160
+ expect ( batching . outgoingBuffers ) . toEqual ( [ { cursor : { position : { x : 1 , y : 1 } , data : { } } , offset : 0 } ] ) ;
158
161
batching . pushCursorPosition ( channel , { position : { x : 2 , y : 2 } , data : { } } ) ;
159
162
expect ( batching . outgoingBuffers ) . toEqual ( [
160
- { position : { x : 1 , y : 1 } , data : { } } ,
161
- { position : { x : 2 , y : 2 } , data : { } } ,
163
+ { cursor : { position : { x : 1 , y : 1 } , data : { } } , offset : 0 } ,
164
+ { cursor : { position : { x : 2 , y : 2 } , data : { } } , offset : 0 } ,
162
165
] ) ;
163
166
} ) ;
164
167
@@ -193,15 +196,17 @@ describe('Cursors (mockClient)', () => {
193
196
194
197
it < CursorsTestContext > ( 'should publish the cursor buffer' , async ( { batching, channel } ) => {
195
198
batching . hasMovement = true ;
196
- batching . outgoingBuffers = [ { position : { x : 1 , y : 1 } , data : { } } ] ;
199
+ batching . outgoingBuffers = [ { cursor : { position : { x : 1 , y : 1 } , data : { } } , offset : 0 } ] ;
197
200
const spy = vi . spyOn ( channel , 'publish' ) ;
198
201
await batching [ 'batchToChannel' ] ( channel , CURSOR_UPDATE ) ;
199
- expect ( spy ) . toHaveBeenCalledWith ( CURSOR_UPDATE , [ { position : { x : 1 , y : 1 } , data : { } } ] ) ;
202
+ expect ( spy ) . toHaveBeenCalledWith ( CURSOR_UPDATE , [
203
+ { cursor : { position : { x : 1 , y : 1 } , data : { } } , offset : 0 } ,
204
+ ] ) ;
200
205
} ) ;
201
206
202
207
it < CursorsTestContext > ( 'should clear the buffer' , async ( { batching, channel } ) => {
203
208
batching . hasMovement = true ;
204
- batching . outgoingBuffers = [ { position : { x : 1 , y : 1 } , data : { } } ] ;
209
+ batching . outgoingBuffers = [ { cursor : { position : { x : 1 , y : 1 } , data : { } } , offset : 0 } ] ;
205
210
await batching [ 'batchToChannel' ] ( channel , CURSOR_UPDATE ) ;
206
211
expect ( batching . outgoingBuffers ) . toEqual ( [ ] ) ;
207
212
} ) ;
@@ -239,7 +244,7 @@ describe('Cursors (mockClient)', () => {
239
244
240
245
const fakeMessage = {
241
246
...fakeMessageStub ,
242
- data : [ { position : { x : 1 , y : 1 } } ] ,
247
+ data : [ { cursor : { position : { x : 1 , y : 1 } } } ] ,
243
248
} ;
244
249
245
250
dispensing [ 'handlerRunning' ] = true ;
@@ -252,7 +257,7 @@ describe('Cursors (mockClient)', () => {
252
257
253
258
const fakeMessage = {
254
259
...fakeMessageStub ,
255
- data : [ { position : { x : 1 , y : 1 } } ] ,
260
+ data : [ { cursor : { position : { x : 1 , y : 1 } } } ] ,
256
261
} ;
257
262
258
263
dispensing . processBatch ( fakeMessage ) ;
@@ -266,9 +271,9 @@ describe('Cursors (mockClient)', () => {
266
271
const fakeMessage = {
267
272
...fakeMessageStub ,
268
273
data : [
269
- { position : { x : 1 , y : 1 } } ,
270
- { position : { x : 2 , y : 3 } , data : { color : 'blue' } } ,
271
- { position : { x : 5 , y : 4 } } ,
274
+ { cursor : { position : { x : 1 , y : 1 } } , offset : 0 } ,
275
+ { cursor : { position : { x : 2 , y : 3 } , data : { color : 'blue' } } , offset : 1 } ,
276
+ { cursor : { position : { x : 5 , y : 4 } } , offset : 2 } ,
272
277
] ,
273
278
} ;
274
279
@@ -278,18 +283,21 @@ describe('Cursors (mockClient)', () => {
278
283
{
279
284
position : { x : 1 , y : 1 } ,
280
285
data : undefined ,
286
+ offset : 0 ,
281
287
clientId : 'clientId' ,
282
288
connectionId : 'connectionId' ,
283
289
} ,
284
290
{
285
291
position : { x : 2 , y : 3 } ,
286
292
data : { color : 'blue' } ,
293
+ offset : 1 ,
287
294
clientId : 'clientId' ,
288
295
connectionId : 'connectionId' ,
289
296
} ,
290
297
{
291
298
position : { x : 5 , y : 4 } ,
292
299
data : undefined ,
300
+ offset : 2 ,
293
301
clientId : 'clientId' ,
294
302
connectionId : 'connectionId' ,
295
303
} ,
@@ -303,9 +311,9 @@ describe('Cursors (mockClient)', () => {
303
311
const fakeMessage = {
304
312
...fakeMessageStub ,
305
313
data : [
306
- { position : { x : 1 , y : 1 } } ,
307
- { position : { x : 2 , y : 3 } , data : { color : 'blue' } } ,
308
- { position : { x : 5 , y : 4 } } ,
314
+ { cursor : { position : { x : 1 , y : 1 } } , offset : 0 } ,
315
+ { cursor : { position : { x : 2 , y : 3 } , data : { color : 'blue' } } , offset : 1 } ,
316
+ { cursor : { position : { x : 5 , y : 4 } } , offset : 2 } ,
309
317
] ,
310
318
} ;
311
319
@@ -359,6 +367,7 @@ describe('Cursors (mockClient)', () => {
359
367
x : 2 ,
360
368
y : 3 ,
361
369
} ,
370
+ offset : 0 ,
362
371
} ,
363
372
connectionId2 : {
364
373
connectionId : 'connectionId2' ,
@@ -368,6 +377,7 @@ describe('Cursors (mockClient)', () => {
368
377
x : 25 ,
369
378
y : 44 ,
370
379
} ,
380
+ offset : 0 ,
371
381
} ,
372
382
connectionId3 : {
373
383
connectionId : 'connectionId3' ,
@@ -377,6 +387,7 @@ describe('Cursors (mockClient)', () => {
377
387
x : 225 ,
378
388
y : 244 ,
379
389
} ,
390
+ offset : 0 ,
380
391
} ,
381
392
} ;
382
393
} ) ;
@@ -496,6 +507,7 @@ describe('Cursors (mockClient)', () => {
496
507
x : 2 ,
497
508
y : 3 ,
498
509
} ,
510
+ offset : 0 ,
499
511
} ,
500
512
} ;
501
513
@@ -524,6 +536,7 @@ describe('Cursors (mockClient)', () => {
524
536
y : 44 ,
525
537
} ,
526
538
data : undefined ,
539
+ offset : 0 ,
527
540
} ,
528
541
connectionId3 : {
529
542
connectionId : 'connectionId3' ,
@@ -533,6 +546,7 @@ describe('Cursors (mockClient)', () => {
533
546
y : 244 ,
534
547
} ,
535
548
data : undefined ,
549
+ offset : 0 ,
536
550
} ,
537
551
} ) ;
538
552
} ) ;
0 commit comments