tools.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 = function() {};
  8. let destroyFn3 = function() {};
  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()', function() {
  21. it( 'should register all creators', function() {
  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', function() {
  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', function() {
  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. } );