utils.js 2.3 KB

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