automaticdecorators.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import AutomaticDecorators from '../../src/utils/automaticdecorators';
  6. describe( 'Automatic Decorators', () => {
  7. let automaticDecorators;
  8. beforeEach( () => {
  9. automaticDecorators = new AutomaticDecorators();
  10. } );
  11. describe( 'constructor()', () => {
  12. it( 'initialise with empty Set', () => {
  13. expect( automaticDecorators._definitions ).to.be.instanceOf( Set );
  14. } );
  15. } );
  16. it( 'has length equal 0 after initialization', () => {
  17. expect( automaticDecorators.length ).to.equal( 0 );
  18. } );
  19. describe( 'add()', () => {
  20. const tests = [
  21. {
  22. mode: 'automatic',
  23. callback: () => {},
  24. attributes: {
  25. foo: 'bar'
  26. }
  27. },
  28. {
  29. mode: 'automatic',
  30. callback: () => {},
  31. attributes: {
  32. bar: 'baz'
  33. }
  34. },
  35. {
  36. mode: 'automatic',
  37. callback: () => {},
  38. attributes: {
  39. test1: 'one',
  40. test2: 'two',
  41. test3: 'three'
  42. }
  43. }
  44. ];
  45. it( 'can accept single object', () => {
  46. expect( automaticDecorators.length ).to.equal( 0 );
  47. automaticDecorators.add( tests[ 0 ] );
  48. expect( automaticDecorators.length ).to.equal( 1 );
  49. const firstValue = automaticDecorators._definitions.values().next().value;
  50. expect( firstValue ).to.deep.include( {
  51. mode: 'automatic',
  52. attributes: {
  53. foo: 'bar'
  54. }
  55. } );
  56. expect( firstValue ).to.have.property( 'callback' );
  57. expect( firstValue.callback ).to.be.a( 'function' );
  58. } );
  59. it( 'can accept array of objects', () => {
  60. expect( automaticDecorators.length ).to.equal( 0 );
  61. automaticDecorators.add( tests );
  62. expect( automaticDecorators.length ).to.equal( 3 );
  63. const setIterator = automaticDecorators._definitions.values();
  64. setIterator.next();
  65. setIterator.next();
  66. const thirdValue = setIterator.next().value;
  67. expect( thirdValue ).to.deep.include( {
  68. mode: 'automatic',
  69. attributes: {
  70. test1: 'one',
  71. test2: 'two',
  72. test3: 'three'
  73. }
  74. } );
  75. expect( thirdValue ).to.have.property( 'callback' );
  76. expect( thirdValue.callback ).to.be.a( 'function' );
  77. } );
  78. } );
  79. describe( 'getDispatcher()', () => {
  80. it( 'should return a dispatcher function', () => {
  81. expect( automaticDecorators.getDispatcher() ).to.be.a( 'function' );
  82. } );
  83. } );
  84. } );