8
0

classictesteditor.js 3.0 KB

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