8
0

imageuploadediting.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals window, setTimeout */
  6. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  7. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  8. import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  9. import ImageEditing from '../../src/image/imageediting';
  10. import ImageUploadEditing from '../../src/imageupload/imageuploadediting';
  11. import ImageUploadCommand from '../../src/imageupload/imageuploadcommand';
  12. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  13. import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
  14. import DataTransfer from '@ckeditor/ckeditor5-clipboard/src/datatransfer';
  15. import FileRepository from '@ckeditor/ckeditor5-upload/src/filerepository';
  16. import { UploadAdapterMock, createNativeFileMock, NativeFileReaderMock } from '@ckeditor/ckeditor5-upload/tests/_utils/mocks';
  17. import { setData as setModelData, getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  18. import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  19. import log from '@ckeditor/ckeditor5-utils/src/log';
  20. import env from '@ckeditor/ckeditor5-utils/src/env';
  21. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  22. import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';
  23. describe( 'ImageUploadEditing', () => {
  24. // eslint-disable-next-line max-len
  25. const base64Sample = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=';
  26. let editor, model, view, doc, fileRepository, viewDocument, nativeReaderMock, loader, adapterMock;
  27. testUtils.createSinonSandbox();
  28. class UploadAdapterPluginMock extends Plugin {
  29. init() {
  30. fileRepository = this.editor.plugins.get( FileRepository );
  31. fileRepository.createUploadAdapter = newLoader => {
  32. loader = newLoader;
  33. adapterMock = new UploadAdapterMock( loader );
  34. return adapterMock;
  35. };
  36. }
  37. }
  38. beforeEach( () => {
  39. // Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
  40. testUtils.sinon.stub( env, 'isEdge' ).get( () => false );
  41. testUtils.sinon.stub( window, 'FileReader' ).callsFake( () => {
  42. nativeReaderMock = new NativeFileReaderMock();
  43. return nativeReaderMock;
  44. } );
  45. return VirtualTestEditor
  46. .create( {
  47. plugins: [ ImageEditing, ImageUploadEditing, Paragraph, UndoEditing, UploadAdapterPluginMock ]
  48. } )
  49. .then( newEditor => {
  50. editor = newEditor;
  51. model = editor.model;
  52. doc = model.document;
  53. view = editor.editing.view;
  54. viewDocument = view.document;
  55. } );
  56. } );
  57. afterEach( () => {
  58. return editor.destroy();
  59. } );
  60. it( 'should register proper schema rules', () => {
  61. expect( model.schema.checkAttribute( [ '$root', 'image' ], 'uploadId' ) ).to.be.true;
  62. } );
  63. it( 'should register imageUpload command', () => {
  64. expect( editor.commands.get( 'imageUpload' ) ).to.be.instanceOf( ImageUploadCommand );
  65. } );
  66. it( 'should insert image when is pasted', () => {
  67. const fileMock = createNativeFileMock();
  68. const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
  69. setModelData( model, '<paragraph>[]foo</paragraph>' );
  70. const targetRange = model.createRange( model.createPositionAt( doc.getRoot(), 1 ), model.createPositionAt( doc.getRoot(), 1 ) );
  71. const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
  72. viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
  73. const id = fileRepository.getLoader( fileMock ).id;
  74. expect( getModelData( model ) ).to.equal(
  75. `<paragraph>foo</paragraph>[<image uploadId="${ id }" uploadStatus="reading"></image>]`
  76. );
  77. } );
  78. it( 'should insert image at optimized position when is pasted', () => {
  79. const fileMock = createNativeFileMock();
  80. const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
  81. setModelData( model, '<paragraph>[]foo</paragraph>' );
  82. const paragraph = doc.getRoot().getChild( 0 );
  83. const targetRange = model.createRange( model.createPositionAt( paragraph, 1 ), model.createPositionAt( paragraph, 1 ) ); // f[]oo
  84. const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
  85. viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
  86. const id = fileRepository.getLoader( fileMock ).id;
  87. expect( getModelData( model ) ).to.equal(
  88. `[<image uploadId="${ id }" uploadStatus="reading"></image>]<paragraph>foo</paragraph>`
  89. );
  90. } );
  91. it( 'should insert multiple image files when are pasted', () => {
  92. const files = [ createNativeFileMock(), createNativeFileMock() ];
  93. const dataTransfer = new DataTransfer( { files, types: [ 'Files' ] } );
  94. setModelData( model, '<paragraph>[]foo</paragraph>' );
  95. const targetRange = model.createRange( model.createPositionAt( doc.getRoot(), 1 ), model.createPositionAt( doc.getRoot(), 1 ) );
  96. const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
  97. viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
  98. const id1 = fileRepository.getLoader( files[ 0 ] ).id;
  99. const id2 = fileRepository.getLoader( files[ 1 ] ).id;
  100. expect( getModelData( model ) ).to.equal(
  101. '<paragraph>foo</paragraph>' +
  102. `<image uploadId="${ id1 }" uploadStatus="reading"></image>` +
  103. `[<image uploadId="${ id2 }" uploadStatus="reading"></image>]`
  104. );
  105. } );
  106. it( 'should insert image when is pasted on allowed position when ImageUploadCommand is disabled', () => {
  107. setModelData( model, '<paragraph>foo</paragraph>[<image></image>]' );
  108. const fileMock = createNativeFileMock();
  109. const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
  110. const command = editor.commands.get( 'imageUpload' );
  111. expect( command.isEnabled ).to.be.false;
  112. const targetRange = model.createRange( model.createPositionAt( doc.getRoot(), 0 ), model.createPositionAt( doc.getRoot(), 0 ) );
  113. const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
  114. viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
  115. const id = fileRepository.getLoader( fileMock ).id;
  116. expect( getModelData( model ) ).to.equal(
  117. `[<image uploadId="${ id }" uploadStatus="reading"></image>]<paragraph>foo</paragraph><image></image>`
  118. );
  119. } );
  120. it( 'should not insert image when editor is in read-only mode', () => {
  121. // Clipboard plugin is required for this test.
  122. return VirtualTestEditor
  123. .create( {
  124. plugins: [ ImageEditing, ImageUploadEditing, Paragraph, UploadAdapterPluginMock, Clipboard ]
  125. } )
  126. .then( editor => {
  127. const fileMock = createNativeFileMock();
  128. const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
  129. setModelData( editor.model, '<paragraph>[]foo</paragraph>' );
  130. const targetRange = editor.model.document.selection.getFirstRange();
  131. const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
  132. editor.isReadOnly = true;
  133. editor.editing.view.document.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
  134. expect( getModelData( editor.model ) ).to.equal( '<paragraph>[]foo</paragraph>' );
  135. return editor.destroy();
  136. } );
  137. } );
  138. it( 'should not insert image when file is not an image', () => {
  139. const viewDocument = editor.editing.view.document;
  140. const fileMock = {
  141. type: 'media/mp3',
  142. size: 1024
  143. };
  144. const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
  145. setModelData( model, '<paragraph>foo[]</paragraph>' );
  146. const targetRange = doc.selection.getFirstRange();
  147. const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
  148. viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
  149. expect( getModelData( model ) ).to.equal( '<paragraph>foo[]</paragraph>' );
  150. } );
  151. it( 'should not insert image when file is null', () => {
  152. const viewDocument = editor.editing.view.document;
  153. const dataTransfer = new DataTransfer( { files: [ null ], types: [ 'Files' ] } );
  154. setModelData( model, '<paragraph>foo[]</paragraph>' );
  155. const targetRange = doc.selection.getFirstRange();
  156. const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
  157. viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
  158. expect( getModelData( model ) ).to.equal( '<paragraph>foo[]</paragraph>' );
  159. } );
  160. it( 'should not insert image when there is non-empty HTML content pasted', () => {
  161. const fileMock = createNativeFileMock();
  162. const dataTransfer = new DataTransfer( {
  163. files: [ fileMock ],
  164. types: [ 'Files', 'text/html' ],
  165. getData: type => type === 'text/html' ? '<p>SomeData</p>' : ''
  166. } );
  167. setModelData( model, '<paragraph>[]foo</paragraph>' );
  168. const targetRange = model.createRange( model.createPositionAt( doc.getRoot(), 1 ), model.createPositionAt( doc.getRoot(), 1 ) );
  169. const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
  170. viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
  171. expect( getModelData( model ) ).to.equal( '<paragraph>[]foo</paragraph>' );
  172. } );
  173. it( 'should not insert image nor crash when pasted image could not be inserted', () => {
  174. model.schema.register( 'other', {
  175. allowIn: '$root',
  176. isLimit: true
  177. } );
  178. model.schema.extend( '$text', { allowIn: 'other' } );
  179. editor.conversion.elementToElement( { model: 'other', view: 'p' } );
  180. setModelData( model, '<other>[]</other>' );
  181. const fileMock = createNativeFileMock();
  182. const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
  183. const targetRange = doc.selection.getFirstRange();
  184. const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
  185. viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
  186. expect( getModelData( model ) ).to.equal( '<other>[]</other>' );
  187. } );
  188. it( 'should not throw when upload adapter is not set (FileRepository will log an error anyway) when image is pasted', () => {
  189. const fileMock = createNativeFileMock();
  190. const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
  191. const logStub = testUtils.sinon.stub( log, 'error' );
  192. setModelData( model, '<paragraph>[]foo</paragraph>' );
  193. fileRepository.createUploadAdapter = undefined;
  194. const targetRange = model.createRange( model.createPositionAt( doc.getRoot(), 1 ), model.createPositionAt( doc.getRoot(), 1 ) );
  195. const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
  196. expect( () => {
  197. viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
  198. } ).to.not.throw();
  199. expect( getModelData( model ) ).to.equal( '<paragraph>foo[]</paragraph>' );
  200. sinon.assert.calledOnce( logStub );
  201. } );
  202. // https://github.com/ckeditor/ckeditor5-upload/issues/70
  203. it( 'should not crash on browsers which do not implement DOMStringList as a child class of an Array', () => {
  204. const typesDomStringListMock = {
  205. length: 2,
  206. '0': 'text/html',
  207. '1': 'text/plain'
  208. };
  209. const dataTransfer = new DataTransfer( {
  210. types: typesDomStringListMock,
  211. getData: type => type === 'text/html' ? '<p>SomeData</p>' : 'SomeData'
  212. } );
  213. setModelData( model, '<paragraph>[]foo</paragraph>' );
  214. const targetRange = doc.selection.getFirstRange();
  215. const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
  216. viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
  217. // Well, there's no clipboard plugin, so nothing happens.
  218. expect( getModelData( model ) ).to.equal( '<paragraph>[]foo</paragraph>' );
  219. } );
  220. it( 'should not convert image\'s uploadId attribute if is consumed already', () => {
  221. editor.editing.downcastDispatcher.on( 'attribute:uploadId:image', ( evt, data, conversionApi ) => {
  222. conversionApi.consumable.consume( data.item, evt.name );
  223. }, { priority: 'high' } );
  224. setModelData( model, '<image uploadId="1234"></image>' );
  225. expect( getViewData( view ) ).to.equal(
  226. '[<figure class="ck-widget image" contenteditable="false">' +
  227. '<img></img>' +
  228. '</figure>]' );
  229. } );
  230. it( 'should use read data once it is present', done => {
  231. const file = createNativeFileMock();
  232. setModelData( model, '<paragraph>{}foo bar</paragraph>' );
  233. editor.execute( 'imageUpload', { files: file } );
  234. model.once( '_change', () => {
  235. expect( getViewData( view ) ).to.equal(
  236. '[<figure class="ck-widget image" contenteditable="false">' +
  237. `<img src="${ base64Sample }"></img>` +
  238. '</figure>]' +
  239. '<p>foo bar</p>' );
  240. expect( loader.status ).to.equal( 'uploading' );
  241. done();
  242. } );
  243. expect( loader.status ).to.equal( 'reading' );
  244. nativeReaderMock.mockSuccess( base64Sample );
  245. } );
  246. it( 'should replace read data with server response once it is present', done => {
  247. const file = createNativeFileMock();
  248. setModelData( model, '<paragraph>{}foo bar</paragraph>' );
  249. editor.execute( 'imageUpload', { files: file } );
  250. model.document.once( 'change', () => {
  251. model.document.once( 'change', () => {
  252. expect( getViewData( view ) ).to.equal(
  253. '[<figure class="ck-widget image" contenteditable="false"><img src="image.png"></img></figure>]<p>foo bar</p>'
  254. );
  255. expect( loader.status ).to.equal( 'idle' );
  256. done();
  257. }, { priority: 'lowest' } );
  258. adapterMock.mockSuccess( { default: 'image.png' } );
  259. } );
  260. nativeReaderMock.mockSuccess( base64Sample );
  261. } );
  262. it( 'should fire notification event in case of error', done => {
  263. const notification = editor.plugins.get( Notification );
  264. const file = createNativeFileMock();
  265. notification.on( 'show:warning', ( evt, data ) => {
  266. expect( data.message ).to.equal( 'Reading error.' );
  267. expect( data.title ).to.equal( 'Upload failed' );
  268. evt.stop();
  269. done();
  270. }, { priority: 'high' } );
  271. setModelData( model, '<paragraph>{}foo bar</paragraph>' );
  272. editor.execute( 'imageUpload', { files: file } );
  273. nativeReaderMock.mockError( 'Reading error.' );
  274. } );
  275. it( 'should not fire notification on abort', done => {
  276. const notification = editor.plugins.get( Notification );
  277. const file = createNativeFileMock();
  278. const spy = testUtils.sinon.spy();
  279. notification.on( 'show:warning', evt => {
  280. spy();
  281. evt.stop();
  282. }, { priority: 'high' } );
  283. setModelData( model, '<paragraph>{}foo bar</paragraph>' );
  284. editor.execute( 'imageUpload', { files: file } );
  285. nativeReaderMock.abort();
  286. setTimeout( () => {
  287. sinon.assert.notCalled( spy );
  288. done();
  289. }, 0 );
  290. } );
  291. it( 'should throw when other error happens during upload', done => {
  292. const file = createNativeFileMock();
  293. const error = new Error( 'Foo bar baz' );
  294. const uploadEditing = editor.plugins.get( ImageUploadEditing );
  295. const loadSpy = sinon.spy( uploadEditing, '_readAndUpload' );
  296. const catchSpy = sinon.spy();
  297. // Throw an error when async attribute change occur.
  298. editor.editing.downcastDispatcher.on( 'attribute:uploadStatus:image', ( evt, data ) => {
  299. if ( data.attributeNewValue == 'uploading' ) {
  300. throw error;
  301. }
  302. } );
  303. setModelData( model, '<paragraph>{}foo bar</paragraph>' );
  304. editor.execute( 'imageUpload', { files: file } );
  305. sinon.assert.calledOnce( loadSpy );
  306. const promise = loadSpy.returnValues[ 0 ];
  307. // Check if error can be caught.
  308. promise.catch( catchSpy );
  309. nativeReaderMock.mockSuccess();
  310. setTimeout( () => {
  311. sinon.assert.calledOnce( catchSpy );
  312. sinon.assert.calledWithExactly( catchSpy, error );
  313. done();
  314. }, 0 );
  315. } );
  316. it( 'should do nothing if image does not have uploadId', () => {
  317. setModelData( model, '<image src="image.png"></image>' );
  318. expect( getViewData( view ) ).to.equal(
  319. '[<figure class="ck-widget image" contenteditable="false"><img src="image.png"></img></figure>]'
  320. );
  321. } );
  322. it( 'should remove image in case of upload error', done => {
  323. const file = createNativeFileMock();
  324. const spy = testUtils.sinon.spy();
  325. const notification = editor.plugins.get( Notification );
  326. setModelData( model, '<paragraph>{}foo bar</paragraph>' );
  327. notification.on( 'show:warning', evt => {
  328. spy();
  329. evt.stop();
  330. }, { priority: 'high' } );
  331. editor.execute( 'imageUpload', { files: file } );
  332. model.document.once( 'change', () => {
  333. model.document.once( 'change', () => {
  334. expect( getModelData( model ) ).to.equal( '<paragraph>[]foo bar</paragraph>' );
  335. sinon.assert.calledOnce( spy );
  336. done();
  337. } );
  338. } );
  339. nativeReaderMock.mockError( 'Upload error.' );
  340. } );
  341. it( 'should abort upload if image is removed', () => {
  342. const file = createNativeFileMock();
  343. setModelData( model, '<paragraph>{}foo bar</paragraph>' );
  344. editor.execute( 'imageUpload', { files: file } );
  345. const abortSpy = testUtils.sinon.spy( loader, 'abort' );
  346. expect( loader.status ).to.equal( 'reading' );
  347. nativeReaderMock.mockSuccess( base64Sample );
  348. const image = doc.getRoot().getChild( 0 );
  349. model.change( writer => {
  350. writer.remove( image );
  351. } );
  352. expect( loader.status ).to.equal( 'aborted' );
  353. sinon.assert.calledOnce( abortSpy );
  354. } );
  355. it( 'should not abort and not restart upload when image is moved', () => {
  356. const file = createNativeFileMock();
  357. setModelData( model, '<paragraph>{}foo bar</paragraph>' );
  358. editor.execute( 'imageUpload', { files: file } );
  359. const abortSpy = testUtils.sinon.spy( loader, 'abort' );
  360. const loadSpy = testUtils.sinon.spy( loader, 'read' );
  361. const image = doc.getRoot().getChild( 0 );
  362. model.change( writer => {
  363. writer.move( writer.createRangeOn( image ), writer.createPositionAt( doc.getRoot(), 2 ) );
  364. } );
  365. expect( abortSpy.called ).to.be.false;
  366. expect( loadSpy.called ).to.be.false;
  367. } );
  368. it( 'image should be permanently removed if it is removed by user during upload', done => {
  369. const file = createNativeFileMock();
  370. const notification = editor.plugins.get( Notification );
  371. setModelData( model, '<paragraph>{}foo bar</paragraph>' );
  372. // Prevent popping up alert window.
  373. notification.on( 'show:warning', evt => {
  374. evt.stop();
  375. }, { priority: 'high' } );
  376. editor.execute( 'imageUpload', { files: file } );
  377. model.document.once( 'change', () => {
  378. // This is called after "manual" remove.
  379. model.document.once( 'change', () => {
  380. // This is called after attributes are removed.
  381. let undone = false;
  382. model.document.once( 'change', () => {
  383. if ( !undone ) {
  384. undone = true;
  385. // This is called after abort remove.
  386. expect( getModelData( model ) ).to.equal( '<paragraph>[]foo bar</paragraph>' );
  387. editor.execute( 'undo' );
  388. // Expect that the image has not been brought back.
  389. expect( getModelData( model ) ).to.equal( '<paragraph>[]foo bar</paragraph>' );
  390. done();
  391. }
  392. } );
  393. } );
  394. } );
  395. const image = doc.getRoot().getChild( 0 );
  396. model.change( writer => {
  397. writer.remove( image );
  398. } );
  399. } );
  400. it( 'should create responsive image if server return multiple images', done => {
  401. const file = createNativeFileMock();
  402. setModelData( model, '<paragraph>{}foo bar</paragraph>' );
  403. editor.execute( 'imageUpload', { files: file } );
  404. model.document.once( 'change', () => {
  405. model.document.once( 'change', () => {
  406. expect( getViewData( view ) ).to.equal(
  407. '[<figure class="ck-widget image" contenteditable="false">' +
  408. '<img sizes="100vw" src="image.png" srcset="image-500.png 500w, image-800.png 800w" width="800"></img>' +
  409. '</figure>]<p>foo bar</p>'
  410. );
  411. expect( loader.status ).to.equal( 'idle' );
  412. done();
  413. }, { priority: 'lowest' } );
  414. adapterMock.mockSuccess( { default: 'image.png', 500: 'image-500.png', 800: 'image-800.png' } );
  415. } );
  416. nativeReaderMock.mockSuccess( base64Sample );
  417. } );
  418. it( 'should prevent from browser redirecting when an image is dropped on another image', () => {
  419. const spy = testUtils.sinon.spy();
  420. editor.editing.view.document.fire( 'dragover', {
  421. preventDefault: spy
  422. } );
  423. expect( spy.calledOnce ).to.equal( true );
  424. } );
  425. } );