8
0

textproxy.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: model */
  6. 'use strict';
  7. import Element from '/ckeditor5/engine/model/element.js';
  8. import Text from '/ckeditor5/engine/model/text.js';
  9. import TextProxy from '/ckeditor5/engine/model/textproxy.js';
  10. import Document from '/ckeditor5/engine/model/document.js';
  11. describe( 'TextProxy', () => {
  12. let doc, text, element, textProxy, root;
  13. beforeEach( () => {
  14. doc = new Document();
  15. root = doc.createRoot();
  16. element = new Element( 'div' );
  17. root.insertChildren( 0, element );
  18. text = new Text( 'foobar', { foo: 'bar' } );
  19. element.insertChildren( 0, text );
  20. textProxy = new TextProxy( text, 2, 3 );
  21. } );
  22. it( 'should have data property', () => {
  23. expect( textProxy ).to.have.property( 'data' ).that.equals( 'oba' );
  24. } );
  25. it( 'should have root', () => {
  26. expect( textProxy ).to.have.property( 'root' ).that.equals( root );
  27. } );
  28. it( 'should have document', () => {
  29. expect( textProxy ).to.have.property( 'document' ).that.equals( doc );
  30. } );
  31. describe( 'getPath', () => {
  32. it( 'should return path to the text proxy', () => {
  33. expect( textProxy.getPath() ).to.deep.equal( [ 0, 2 ] );
  34. } );
  35. } );
  36. describe( 'attributes interface', () => {
  37. describe( 'hasAttribute', () => {
  38. it( 'should return true if text proxy has attribute with given key', () => {
  39. expect( textProxy.hasAttribute( 'foo' ) ).to.be.true;
  40. } );
  41. it( 'should return false if text proxy does not have attribute with given key', () => {
  42. expect( textProxy.hasAttribute( 'abc' ) ).to.be.false;
  43. } );
  44. } );
  45. describe( 'getAttribute', () => {
  46. it( 'should return attribute with given key if text proxy has given attribute', () => {
  47. expect( textProxy.getAttribute( 'foo' ) ).to.equal( 'bar' );
  48. } );
  49. it( 'should return undefined if text proxy does not have given attribute', () => {
  50. expect( textProxy.getAttribute( 'bar' ) ).to.be.undefined;
  51. } );
  52. } );
  53. describe( 'getAttributes', () => {
  54. it( 'should return an iterator that iterates over all attributes set on the text proxy', () => {
  55. let attrs = Array.from( textProxy.getAttributes() );
  56. expect( attrs ).to.deep.equal( [ [ 'foo', 'bar' ] ] );
  57. } );
  58. } );
  59. } );
  60. } );