8
0

utils.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 testUtils from '/tests/ckeditor5/_utils/utils.js';
  7. import moduleTestUtils from '/tests/ckeditor5/_utils/module.js';
  8. import Creator from '/ckeditor5/creator/creator.js';
  9. let createFn3 = () => {};
  10. let destroyFn3 = () => {};
  11. testUtils.createSinonSandbox();
  12. testUtils.defineEditorCreatorMock( 'test1' );
  13. testUtils.defineEditorCreatorMock( 'test2', {
  14. foo: 1,
  15. bar: 2
  16. } );
  17. testUtils.defineEditorCreatorMock( 'test3', {
  18. create: createFn3,
  19. destroy: destroyFn3
  20. } );
  21. const modules = moduleTestUtils.require( {
  22. testCreator1: 'creator-test1/creator-test1',
  23. testCreator2: 'creator-test2/creator-test2',
  24. testCreator3: 'creator-test3/creator-test3'
  25. } );
  26. ///////////////////
  27. let TestCreator1, TestCreator2, TestCreator3;
  28. before( () => {
  29. TestCreator1 = modules.testCreator1;
  30. TestCreator2 = modules.testCreator2;
  31. TestCreator3 = modules.testCreator3;
  32. } );
  33. describe( 'testUtils.defineEditorCreatorMock()', () => {
  34. it( 'should register all creators', () => {
  35. expect( TestCreator1.prototype ).to.be.instanceof( Creator );
  36. expect( TestCreator2.prototype ).to.be.instanceof( Creator );
  37. expect( TestCreator3.prototype ).to.be.instanceof( Creator );
  38. } );
  39. it( 'should copy properties from the second argument', () => {
  40. expect( TestCreator2.prototype ).to.have.property( 'foo', 1 );
  41. expect( TestCreator2.prototype ).to.have.property( 'bar', 2 );
  42. expect( TestCreator3.prototype ).to.have.property( 'create', createFn3 );
  43. expect( TestCreator3.prototype ).to.have.property( 'destroy', destroyFn3 );
  44. } );
  45. } );
  46. describe( 'testUtils.createTestUIController()', () => {
  47. it( 'returns a promise', () => {
  48. expect( testUtils.createTestUIController() ).to.be.instanceof( Promise );
  49. } );
  50. describe( 'controller instance', () => {
  51. it( 'comes with a view', () => {
  52. const promise = testUtils.createTestUIController();
  53. return promise.then( controller => {
  54. expect( controller.view.element ).to.equal( document.body );
  55. } );
  56. } );
  57. it( 'creates collections and regions', () => {
  58. const promise = testUtils.createTestUIController( {
  59. foo: el => el.firstChild,
  60. bar: el => el.lastChild,
  61. } );
  62. promise.then( controller => {
  63. expect( controller.collections.get( 'foo' ) ).to.be.not.undefined;
  64. expect( controller.collections.get( 'bar' ) ).to.be.not.undefined;
  65. expect( controller.view.regions.get( 'foo' ).element ).to.equal( document.body.firstChild );
  66. expect( controller.view.regions.get( 'bar' ).element ).to.equal( document.body.lastChild );
  67. } );
  68. } );
  69. it( 'is ready', () => {
  70. const promise = testUtils.createTestUIController( {
  71. foo: el => el.firstChild,
  72. bar: el => el.lastChild,
  73. } );
  74. promise.then( controller => {
  75. expect( controller.ready ).to.be.true;
  76. } );
  77. } );
  78. } );
  79. } );