8
0

automaticdecorators.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * @license Copyright (c) 2003-2019, 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. describe( 'add()', () => {
  17. const tests = [
  18. {
  19. mode: 'automatic',
  20. callback: () => {},
  21. attributes: {
  22. foo: 'bar'
  23. }
  24. },
  25. {
  26. mode: 'automatic',
  27. callback: () => {},
  28. attributes: {
  29. bar: 'baz'
  30. }
  31. },
  32. {
  33. mode: 'automatic',
  34. callback: () => {},
  35. attributes: {
  36. test1: 'one',
  37. test2: 'two',
  38. test3: 'three'
  39. }
  40. }
  41. ];
  42. it( 'can accept single object', () => {
  43. expect( automaticDecorators._definitions.size ).to.equal( 0 );
  44. automaticDecorators.add( tests[ 0 ] );
  45. expect( automaticDecorators._definitions.size ).to.equal( 1 );
  46. const firstValue = automaticDecorators._definitions.values().next().value;
  47. expect( firstValue ).to.deep.include( {
  48. mode: 'automatic',
  49. attributes: {
  50. foo: 'bar'
  51. }
  52. } );
  53. expect( firstValue ).to.have.property( 'callback' );
  54. expect( firstValue.callback ).to.be.a( 'function' );
  55. } );
  56. it( 'can accept array of objects', () => {
  57. expect( automaticDecorators._definitions.size ).to.equal( 0 );
  58. automaticDecorators.add( tests );
  59. expect( automaticDecorators._definitions.size ).to.equal( 3 );
  60. const setIterator = automaticDecorators._definitions.values();
  61. setIterator.next();
  62. setIterator.next();
  63. const thirdValue = setIterator.next().value;
  64. expect( thirdValue ).to.deep.include( {
  65. mode: 'automatic',
  66. attributes: {
  67. test1: 'one',
  68. test2: 'two',
  69. test3: 'three'
  70. }
  71. } );
  72. expect( thirdValue ).to.have.property( 'callback' );
  73. expect( thirdValue.callback ).to.be.a( 'function' );
  74. } );
  75. } );
  76. describe( 'getDispatcher()', () => {
  77. it( 'should return a dispatcher function', () => {
  78. expect( automaticDecorators.getDispatcher() ).to.be.a( 'function' );
  79. } );
  80. } );
  81. } );