classictesteditor.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. import StandardEditor from '/ckeditor5/editor/standardeditor.js';
  7. import ClassicTestEditor from '/tests/ckeditor5/_utils/classictesteditor.js';
  8. import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
  9. import BoxedEditorUI from '/ckeditor5/ui/editorui/boxed/boxededitorui.js';
  10. import Feature from '/ckeditor5/feature.js';
  11. import { getData } from '/tests/engine/_utils/model.js';
  12. import testUtils from '/tests/ckeditor5/_utils/utils.js';
  13. testUtils.createSinonSandbox();
  14. describe( 'ClassicTestEditor', () => {
  15. let editorElement;
  16. beforeEach( () => {
  17. editorElement = document.createElement( 'div' );
  18. document.body.appendChild( editorElement );
  19. } );
  20. describe( 'constructor', () => {
  21. it( 'creates an instance of editor', () => {
  22. const editor = new ClassicTestEditor( editorElement, { foo: 1 } );
  23. expect( editor ).to.be.instanceof( StandardEditor );
  24. expect( editor.config.get( 'foo' ) ).to.equal( 1 );
  25. expect( editor ).to.have.property( 'element', editorElement );
  26. } );
  27. it( 'creates model and view roots', () => {
  28. const editor = new ClassicTestEditor( { foo: 1 } );
  29. expect( editor.document.getRoot() ).to.have.property( 'name', '$root' );
  30. expect( editor.editing.view.getRoot() ).to.have.property( 'name', 'DIV' ); // See ckeditor5-engine#450.
  31. expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );
  32. } );
  33. } );
  34. describe( 'create', () => {
  35. it( 'creates an instance of editor', () => {
  36. return ClassicTestEditor.create( editorElement, { foo: 1 } )
  37. .then( editor => {
  38. expect( editor ).to.be.instanceof( ClassicTestEditor );
  39. expect( editor.config.get( 'foo' ) ).to.equal( 1 );
  40. expect( editor ).to.have.property( 'element', editorElement );
  41. } );
  42. } );
  43. it( 'creates and initilizes the UI', () => {
  44. return ClassicTestEditor.create( editorElement, { foo: 1 } )
  45. .then( editor => {
  46. expect( editor.ui ).to.be.instanceof( BoxedEditorUI );
  47. } );
  48. } );
  49. it( 'loads data from the editor element', () => {
  50. editorElement.innerHTML = 'foo';
  51. class FeatureTextInRoot extends Feature {
  52. init() {
  53. this.editor.document.schema.allow( { name: '$text', inside: '$root' } );
  54. }
  55. }
  56. return ClassicTestEditor.create( editorElement, { features: [ FeatureTextInRoot ] } )
  57. .then( editor => {
  58. expect( getData( editor.document, { withoutSelection: true } ) ).to.equal( 'foo' );
  59. } );
  60. } );
  61. } );
  62. describe( 'destroy', () => {
  63. it( 'destroys UI and calls super.destroy()', () => {
  64. return ClassicTestEditor.create( editorElement, { foo: 1 } )
  65. .then( editor => {
  66. const superSpy = testUtils.sinon.spy( StandardEditor.prototype, 'destroy' );
  67. const uiSpy = sinon.spy( editor.ui, 'destroy' );
  68. return editor.destroy()
  69. .then( () => {
  70. expect( superSpy.calledOnce ).to.be.true;
  71. expect( uiSpy.calledOnce ).to.be.true;
  72. } );
  73. } );
  74. } );
  75. } );
  76. } );