tools.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @license Copyright (c) 2003-2015, 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( 'creator', 'plugin!creator-test1', 'plugin!creator-test2', 'plugin!creator-test3' );
  19. ///////////////////
  20. describe( 'bender.tools.core.defineEditorCreatorMock()', () => {
  21. it( 'should register all creators', () => {
  22. const Creator = modules.creator;
  23. const TestCreator1 = modules[ 'plugin!creator-test1' ];
  24. const TestCreator2 = modules[ 'plugin!creator-test2' ];
  25. const TestCreator3 = modules[ 'plugin!creator-test3' ];
  26. expect( TestCreator1.prototype ).to.be.instanceof( Creator );
  27. expect( TestCreator2.prototype ).to.be.instanceof( Creator );
  28. expect( TestCreator3.prototype ).to.be.instanceof( Creator );
  29. } );
  30. it( 'should copy properties from the second argument', () => {
  31. const TestCreator = modules[ 'plugin!creator-test2' ];
  32. expect( TestCreator.prototype ).to.have.property( 'foo', 1 );
  33. expect( TestCreator.prototype ).to.have.property( 'bar', 2 );
  34. } );
  35. it( 'should create spies for create() and destroy() if not defined', () => {
  36. const TestCreator1 = modules[ 'plugin!creator-test1' ];
  37. const TestCreator2 = modules[ 'plugin!creator-test2' ];
  38. const TestCreator3 = modules[ 'plugin!creator-test3' ];
  39. expect( TestCreator1.prototype.create ).to.have.property( 'called', false, 'test1.create' );
  40. expect( TestCreator1.prototype.destroy ).to.have.property( 'called', false, 'test1.destroy' );
  41. expect( TestCreator2.prototype.create ).to.have.property( 'called', false, 'test2.create' );
  42. expect( TestCreator2.prototype.destroy ).to.have.property( 'called', false, 'test2.destroy' );
  43. // Not spies:
  44. expect( TestCreator3.prototype ).to.have.property( 'create', createFn3 );
  45. expect( TestCreator3.prototype ).to.have.property( 'destroy', destroyFn3 );
  46. } );
  47. } );
  48. describe( 'bender.tools.core.getIteratorCount()', () => {
  49. it( 'should returns number of editable items ', () => {
  50. const count = bender.tools.core.getIteratorCount( [ 1, 2, 3, 4, 5 ] );
  51. expect( count ).to.equal( 5 );
  52. } );
  53. } );