@@ -25,10 +25,10 @@ function createOperation<T extends OperationType>(
2525}
2626
2727describe ( 'DocumentManager' , ( ) => {
28- it ( 'should process consequential operations' , ( ) => {
28+ it ( 'should process consequential operations' , async ( ) => {
2929 const manager = new DocumentManager ( 'document' ) ;
3030
31- manager . process (
31+ await manager . process (
3232 createOperation (
3333 OperationType . Insert ,
3434 'doc@0:block@0' ,
@@ -48,7 +48,7 @@ describe('DocumentManager', () => {
4848 0
4949 )
5050 ) ;
51- manager . process (
51+ await manager . process (
5252 createOperation (
5353 OperationType . Insert ,
5454 'doc@0:block@0:data@text:[0,0]' ,
@@ -57,7 +57,7 @@ describe('DocumentManager', () => {
5757 1
5858 )
5959 ) ;
60- manager . process (
60+ await manager . process (
6161 createOperation (
6262 OperationType . Insert ,
6363 'doc@0:block@0:data@text:[0,0]' ,
@@ -66,7 +66,7 @@ describe('DocumentManager', () => {
6666 2
6767 )
6868 ) ;
69- manager . process (
69+ await manager . process (
7070 createOperation (
7171 OperationType . Insert ,
7272 'doc@0:block@0:data@text:[0,0]' ,
@@ -95,10 +95,10 @@ describe('DocumentManager', () => {
9595 } ) ;
9696 } ) ;
9797
98- it ( 'should process concurrent operations' , ( ) => {
98+ it ( 'should process concurrent operations' , async ( ) => {
9999 const manager = new DocumentManager ( 'document' ) ;
100100
101- manager . process (
101+ await manager . process (
102102 createOperation (
103103 OperationType . Insert ,
104104 'doc@0:block@0' ,
@@ -118,7 +118,7 @@ describe('DocumentManager', () => {
118118 0
119119 )
120120 ) ;
121- manager . process (
121+ await manager . process (
122122 createOperation (
123123 OperationType . Insert ,
124124 'doc@0:block@0:data@text:[0,0]' ,
@@ -127,7 +127,7 @@ describe('DocumentManager', () => {
127127 1
128128 )
129129 ) ;
130- manager . process (
130+ await manager . process (
131131 createOperation (
132132 OperationType . Insert ,
133133 'doc@0:block@0:data@text:[0,0]' ,
@@ -156,10 +156,10 @@ describe('DocumentManager', () => {
156156 } ) ;
157157 } ) ;
158158
159- it ( 'should process older operations' , ( ) => {
159+ it ( 'should process older operations' , async ( ) => {
160160 const manager = new DocumentManager ( 'document' ) ;
161161
162- manager . process (
162+ await manager . process (
163163 createOperation (
164164 OperationType . Insert ,
165165 'doc@0:block@0' ,
@@ -179,7 +179,7 @@ describe('DocumentManager', () => {
179179 0
180180 )
181181 ) ;
182- manager . process (
182+ await manager . process (
183183 createOperation (
184184 OperationType . Insert ,
185185 'doc@0:block@0:data@text:[0,0]' ,
@@ -188,7 +188,7 @@ describe('DocumentManager', () => {
188188 1
189189 )
190190 ) ;
191- manager . process (
191+ await manager . process (
192192 createOperation (
193193 OperationType . Insert ,
194194 'doc@0:block@0:data@text:[0,0]' ,
@@ -197,7 +197,7 @@ describe('DocumentManager', () => {
197197 2
198198 )
199199 ) ;
200- manager . process (
200+ await manager . process (
201201 createOperation (
202202 OperationType . Insert ,
203203 'doc@0:block@0:data@text:[0,0]' ,
@@ -225,4 +225,77 @@ describe('DocumentManager', () => {
225225 properties : { } ,
226226 } ) ;
227227 } ) ;
228+
229+ it ( 'should correctly process async operations' , async ( ) => {
230+ const manager = new DocumentManager ( 'document' ) ;
231+
232+ void manager . process (
233+ createOperation (
234+ OperationType . Insert ,
235+ 'doc@0:block@0' ,
236+ {
237+ payload : [ {
238+ name : 'paragraph' ,
239+ data : {
240+ text : {
241+ $t : 't' ,
242+ value : '' ,
243+ fragments : [ ] ,
244+ } ,
245+ } ,
246+ } ] ,
247+ } ,
248+ 'user' ,
249+ 0
250+ )
251+ ) ;
252+ void manager . process (
253+ createOperation (
254+ OperationType . Insert ,
255+ 'doc@0:block@0:data@text:[0,0]' ,
256+ { payload : 'A' } ,
257+ 'user' ,
258+ 1
259+ )
260+ ) ;
261+ void manager . process (
262+ createOperation (
263+ OperationType . Insert ,
264+ 'doc@0:block@0:data@text:[0,0]' ,
265+ { payload : 'A' } ,
266+ 'user' ,
267+ 2
268+ )
269+ ) ;
270+ /**
271+ * Waiting for the last operation so expect is executed after it is processed
272+ */
273+ await manager . process (
274+ createOperation (
275+ OperationType . Insert ,
276+ 'doc@0:block@0:data@text:[0,0]' ,
277+ { payload : 'A' } ,
278+ 'user' ,
279+ 3
280+ )
281+ ) ;
282+
283+ expect ( manager . currentModelState ( ) ) . toEqual ( {
284+ identifier : 'document' ,
285+ blocks : [
286+ {
287+ name : 'paragraph' ,
288+ tunes : { } ,
289+ data : {
290+ text : {
291+ $t : 't' ,
292+ value : 'AAA' ,
293+ fragments : [ ] ,
294+ } ,
295+ } ,
296+ } ,
297+ ] ,
298+ properties : { } ,
299+ } ) ;
300+ } ) ;
228301} ) ;
0 commit comments