modeltesteditor.js 2.2 KB

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