11/* eslint-disable jsdoc/require-jsdoc, @stylistic/comma-dangle,@typescript-eslint/naming-convention */
22import { beforeEach , jest } from '@jest/globals' ;
33import type { BlockToolFacade , EditorJSAdapterPlugin } from '@editorjs/sdk' ;
4- import type { Index } from '@editorjs/model' ;
4+ import type { BlockId , Index } from '@editorjs/model' ;
55
66const USER_ID = 'user' ;
77
@@ -45,6 +45,7 @@ jest.unstable_mockModule('@editorjs/model', () => {
4545 BlockAddedEvent,
4646 BlockRemovedEvent,
4747 EventType,
48+ createBlockId : ( str : string ) => str ,
4849 } ;
4950} ) ;
5051
@@ -114,8 +115,11 @@ describe('BlockRenderer (unit, mocked deps)', () => {
114115
115116 const event = new BlockAddedEvent (
116117 { blockIndex : 0 } as Index ,
117- { name : 'tool' ,
118- data : { } } ,
118+ {
119+ name : 'tool' ,
120+ id : 'test-block-id' as BlockId ,
121+ data : { }
122+ } ,
119123 USER_ID ,
120124 ) ;
121125
@@ -132,8 +136,11 @@ describe('BlockRenderer (unit, mocked deps)', () => {
132136 it ( 'should throw when blockIndex is undefined' , async ( ) => {
133137 const event = new BlockAddedEvent (
134138 { } as Index ,
135- { name : 'tool' ,
136- data : { } } ,
139+ {
140+ name : 'tool' ,
141+ id : 'test-block-id' as BlockId ,
142+ data : { }
143+ } ,
137144 USER_ID ,
138145 ) ;
139146
@@ -149,8 +156,11 @@ describe('BlockRenderer (unit, mocked deps)', () => {
149156
150157 const event = new BlockAddedEvent (
151158 { blockIndex : 0 } as Index ,
152- { name : 'missing-tool' ,
153- data : { } } ,
159+ {
160+ name : 'missing-tool' ,
161+ id : 'test-block-id' as BlockId ,
162+ data : { }
163+ } ,
154164 USER_ID ,
155165 ) ;
156166
@@ -174,8 +184,11 @@ describe('BlockRenderer (unit, mocked deps)', () => {
174184
175185 const event = new BlockAddedEvent (
176186 { blockIndex : 0 } as Index ,
177- { name : 'tool' ,
178- data : { } } ,
187+ {
188+ name : 'tool' ,
189+ id : 'test-block-id' as BlockId ,
190+ data : { }
191+ } ,
179192 USER_ID ,
180193 ) ;
181194
@@ -194,8 +207,11 @@ describe('BlockRenderer (unit, mocked deps)', () => {
194207 it ( 'should dispatch BlockRemovedCoreEvent via EventBus' , ( ) => {
195208 const event = new BlockRemovedEvent (
196209 { blockIndex : 1 } as Index ,
197- { name : 'tool' ,
198- data : { } } ,
210+ {
211+ name : 'tool' ,
212+ id : 'test-block-id' as BlockId ,
213+ data : { }
214+ } ,
199215 USER_ID ,
200216 ) ;
201217
@@ -204,24 +220,31 @@ describe('BlockRenderer (unit, mocked deps)', () => {
204220 expect ( eventBus . dispatchEvent ) . toHaveBeenCalled ( ) ;
205221 } ) ;
206222
207- it ( 'should call destroyBlockToolAdapter with the block index' , ( ) => {
223+ it ( 'should call destroyBlockToolAdapter with the block id' , ( ) => {
224+ const blockId = 'test-block-id' as unknown as BlockId ;
208225 const event = new BlockRemovedEvent (
209- { blockIndex : 2 } as Index ,
210- { name : 'tool' ,
211- data : { } } ,
226+ { blockIndex : 1 } as Index ,
227+ {
228+ name : 'tool' ,
229+ id : blockId ,
230+ data : { }
231+ } ,
212232 USER_ID ,
213233 ) ;
214234
215235 void changedListener ( event ) ;
216236
217- expect ( adapter . destroyBlockToolAdapter ) . toHaveBeenCalledWith ( 2 ) ;
237+ expect ( adapter . destroyBlockToolAdapter ) . toHaveBeenCalledWith ( blockId ) ;
218238 } ) ;
219239
220240 it ( 'should throw when blockIndex is undefined' , ( ) => {
221241 const event = new BlockRemovedEvent (
222242 { } as Index ,
223- { name : 'tool' ,
224- data : { } } ,
243+ {
244+ name : 'tool' ,
245+ id : 'test-block-id' as BlockId ,
246+ data : { }
247+ } ,
225248 USER_ID ,
226249 ) ;
227250
0 commit comments