modeltesteditor.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 Editor from '/ckeditor5/editor/editor.js';
  7. import ModelTestEditor from '/tests/ckeditor5/_utils/modeltesteditor.js';
  8. import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
  9. import { getData, setData } from '/tests/engine/_utils/model.js';
  10. import testUtils from '/tests/ckeditor5/_utils/utils.js';
  11. testUtils.createSinonSandbox();
  12. describe( 'ModelTestEditor', () => {
  13. describe( 'constructor', () => {
  14. it( 'creates an instance of editor', () => {
  15. const editor = new ModelTestEditor( { foo: 1 } );
  16. expect( editor ).to.be.instanceof( Editor );
  17. expect( editor.config.get( 'foo' ) ).to.equal( 1 );
  18. } );
  19. it( 'creates model and view roots', () => {
  20. const editor = new ModelTestEditor( { foo: 1 } );
  21. expect( editor.document.getRoot() ).to.have.property( 'name', '$root' );
  22. expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );
  23. } );
  24. } );
  25. describe( 'create', () => {
  26. it( 'creates an instance of editor', () => {
  27. return ModelTestEditor.create( { foo: 1 } )
  28. .then( editor => {
  29. expect( editor ).to.be.instanceof( ModelTestEditor );
  30. expect( editor.config.get( 'foo' ) ).to.equal( 1 );
  31. } );
  32. } );
  33. } );
  34. describe( 'setData', () => {
  35. let editor;
  36. beforeEach( () => {
  37. return ModelTestEditor.create()
  38. .then( newEditor => {
  39. editor = newEditor;
  40. editor.document.schema.allow( { name: '$text', inside: '$root' } );
  41. } );
  42. } );
  43. it( 'should set data of the first root', () => {
  44. editor.document.createRoot( '$root', 'secondRoot' );
  45. editor.setData( 'foo' );
  46. expect( getData( editor.document, { rootName: 'main', withoutSelection: true } ) ).to.equal( 'foo' );
  47. } );
  48. } );
  49. describe( 'getData', () => {
  50. let editor;
  51. beforeEach( () => {
  52. return ModelTestEditor.create()
  53. .then( newEditor => {
  54. editor = newEditor;
  55. editor.document.schema.allow( { name: '$text', inside: '$root' } );
  56. } );
  57. } );
  58. it( 'should set data of the first root', () => {
  59. setData( editor.document, 'foo' );
  60. expect( editor.getData() ).to.equal( 'foo' );
  61. } );
  62. } );
  63. } );