8
0

marktosync.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: treeview */
  6. /* bender-include: ../_tools/tools.js */
  7. 'use strict';
  8. const modules = bender.amd.require(
  9. 'core/treeview/element',
  10. 'core/treeview/rootelement',
  11. 'core/treeview/text'
  12. );
  13. describe( 'Node.markToSync', () => {
  14. let ViewElement, ViewText, RootElement;
  15. let root, text, img;
  16. let markToSyncSpy;
  17. before( () => {
  18. ViewElement = modules[ 'core/treeview/element' ];
  19. ViewText = modules[ 'core/treeview/text' ];
  20. RootElement = modules[ 'core/treeview/rootelement' ];
  21. markToSyncSpy = sinon.spy();
  22. } );
  23. beforeEach( () => {
  24. text = new ViewText( 'foo' );
  25. img = new ViewElement( 'img' );
  26. img.setAttr( 'src', 'img.png' );
  27. root = new RootElement( 'p', { renderer: { markToSync: markToSyncSpy } } );
  28. root.appendChildren( [ text, img ] );
  29. markToSyncSpy.reset();
  30. } );
  31. describe( 'setAttr', () => {
  32. it( 'should mark attibutes to sync', () => {
  33. img.setAttr( 'width', 100 );
  34. sinon.assert.calledOnce( markToSyncSpy );
  35. sinon.assert.calledWith( markToSyncSpy, img, 'ATTRIBUTES_NEED_UPDATE' );
  36. } );
  37. } );
  38. describe( 'removeAttr', () => {
  39. it( 'should mark attibutes to sync', () => {
  40. img.removeAttr( 'src' );
  41. sinon.assert.calledOnce( markToSyncSpy );
  42. sinon.assert.calledWith( markToSyncSpy, img, 'ATTRIBUTES_NEED_UPDATE' );
  43. } );
  44. } );
  45. describe( 'insertChildren', () => {
  46. it( 'should mark children to sync', () => {
  47. root.insertChildren( 1, new ViewElement( 'img' ) );
  48. sinon.assert.calledOnce( markToSyncSpy );
  49. sinon.assert.calledWith( markToSyncSpy, root, 'CHILDREN_NEED_UPDATE' );
  50. } );
  51. } );
  52. describe( 'appendChildren', () => {
  53. it( 'should mark children to sync', () => {
  54. root.appendChildren( new ViewElement( 'img' ) );
  55. sinon.assert.calledOnce( markToSyncSpy );
  56. sinon.assert.calledWith( markToSyncSpy, root, 'CHILDREN_NEED_UPDATE' );
  57. } );
  58. } );
  59. describe( 'removeChildren', () => {
  60. it( 'should mark children to sync', () => {
  61. root.removeChildren( 1, 1 );
  62. sinon.assert.calledOnce( markToSyncSpy );
  63. sinon.assert.calledWith( markToSyncSpy, root, 'CHILDREN_NEED_UPDATE' );
  64. } );
  65. } );
  66. describe( 'removeChildren', () => {
  67. it( 'should mark children to sync', () => {
  68. text.setText( 'bar' );
  69. sinon.assert.calledOnce( markToSyncSpy );
  70. sinon.assert.calledWith( markToSyncSpy, text, 'TEXT_NEEDS_UPDATE' );
  71. } );
  72. } );
  73. } );