tools.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-include: ../_tools/tools.js */
  6. 'use strict';
  7. let createFn3 = () => {};
  8. let destroyFn3 = () => {};
  9. bender.tools.core.defineEditorCreatorMock( 'test1' );
  10. bender.tools.core.defineEditorCreatorMock( 'test2', {
  11. foo: 1,
  12. bar: 2
  13. } );
  14. bender.tools.core.defineEditorCreatorMock( 'test3', {
  15. create: createFn3,
  16. destroy: destroyFn3
  17. } );
  18. const modules = bender.amd.require( 'core/creator', 'creator-test1', 'creator-test2', 'creator-test3' );
  19. let Creator;
  20. ///////////////////
  21. before( () => {
  22. Creator = modules[ 'core/creator' ];
  23. } );
  24. describe( 'bender.tools.core.defineEditorCreatorMock()', () => {
  25. it( 'should register all creators', () => {
  26. const TestCreator1 = modules[ 'creator-test1' ];
  27. const TestCreator2 = modules[ 'creator-test2' ];
  28. const TestCreator3 = modules[ 'creator-test3' ];
  29. expect( TestCreator1.prototype ).to.be.instanceof( Creator );
  30. expect( TestCreator2.prototype ).to.be.instanceof( Creator );
  31. expect( TestCreator3.prototype ).to.be.instanceof( Creator );
  32. } );
  33. it( 'should copy properties from the second argument', () => {
  34. const TestCreator = modules[ 'creator-test2' ];
  35. expect( TestCreator.prototype ).to.have.property( 'foo', 1 );
  36. expect( TestCreator.prototype ).to.have.property( 'bar', 2 );
  37. } );
  38. it( 'should create spies for create() and destroy() if not defined', () => {
  39. const TestCreator1 = modules[ 'creator-test1' ];
  40. const TestCreator2 = modules[ 'creator-test2' ];
  41. const TestCreator3 = modules[ 'creator-test3' ];
  42. expect( TestCreator1.prototype.create ).to.have.property( 'called', false, 'test1.create' );
  43. expect( TestCreator1.prototype.destroy ).to.have.property( 'called', false, 'test1.destroy' );
  44. expect( TestCreator2.prototype.create ).to.have.property( 'called', false, 'test2.create' );
  45. expect( TestCreator2.prototype.destroy ).to.have.property( 'called', false, 'test2.destroy' );
  46. // Not spies:
  47. expect( TestCreator3.prototype ).to.have.property( 'create', createFn3 );
  48. expect( TestCreator3.prototype ).to.have.property( 'destroy', destroyFn3 );
  49. } );
  50. } );
  51. describe( 'bender.tools.core.getIteratorCount()', () => {
  52. it( 'should returns number of editable items ', () => {
  53. const count = bender.tools.core.getIteratorCount( [ 1, 2, 3, 4, 5 ] );
  54. expect( count ).to.equal( 5 );
  55. } );
  56. } );