charactergridview.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import CharacterGridView from '../../src/ui/charactergridview';
  6. import ViewCollection from '@ckeditor/ckeditor5-ui/src/viewcollection';
  7. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  8. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  9. describe( 'CharacterGridView', () => {
  10. let view;
  11. testUtils.createSinonSandbox();
  12. beforeEach( () => {
  13. view = new CharacterGridView();
  14. view.render();
  15. } );
  16. afterEach( () => {
  17. view.destroy();
  18. } );
  19. describe( 'constructor()', () => {
  20. it( 'creates view#tiles collection', () => {
  21. expect( view.tiles ).to.be.instanceOf( ViewCollection );
  22. } );
  23. it( 'creates #element from template', () => {
  24. expect( view.element.classList.contains( 'ck' ) ).to.be.true;
  25. expect( view.element.classList.contains( 'ck-character-grid' ) ).to.be.true;
  26. } );
  27. } );
  28. describe( 'createTile()', () => {
  29. it( 'creates a new tile button', () => {
  30. const tile = view.createTile( 'ε', 'foo bar baz' );
  31. expect( tile ).to.be.instanceOf( ButtonView );
  32. expect( tile.label ).to.equal( 'ε' );
  33. expect( tile.withText ).to.be.true;
  34. expect( tile.class ).to.equal( 'ck-character-grid__tile' );
  35. } );
  36. it( 'delegates #execute from the tile to the grid', () => {
  37. const tile = view.createTile( 'ε', 'foo bar baz' );
  38. const spy = sinon.spy();
  39. view.on( 'execute', spy );
  40. tile.fire( 'execute' );
  41. sinon.assert.calledOnce( spy );
  42. sinon.assert.calledWithExactly( spy, sinon.match.any, { name: 'foo bar baz' } );
  43. } );
  44. } );
  45. } );