8
0

charactergridview.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @license Copyright (c) 2003-2020, 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. const tile = view.createTile( 'ε', 'foo bar baz' );
  25. const tilesElement = view.element.firstChild;
  26. view.tiles.add( tile );
  27. expect( view.element.classList.contains( 'ck' ) ).to.be.true;
  28. expect( view.element.classList.contains( 'ck-character-grid' ) ).to.be.true;
  29. expect( tilesElement.classList.contains( 'ck' ) ).to.be.true;
  30. expect( tilesElement.classList.contains( 'ck-character-grid__tiles' ) ).to.be.true;
  31. expect( tile.element.parentNode ).to.equal( tilesElement );
  32. } );
  33. } );
  34. describe( 'createTile()', () => {
  35. it( 'creates a new tile button', () => {
  36. const tile = view.createTile( 'ε', 'foo bar baz' );
  37. expect( tile ).to.be.instanceOf( ButtonView );
  38. expect( tile.label ).to.equal( 'ε' );
  39. expect( tile.withText ).to.be.true;
  40. expect( tile.class ).to.equal( 'ck-character-grid__tile' );
  41. } );
  42. it( 'delegates #execute from the tile to the grid', () => {
  43. const tile = view.createTile( 'ε', 'foo bar baz' );
  44. const spy = sinon.spy();
  45. view.on( 'execute', spy );
  46. tile.fire( 'execute' );
  47. sinon.assert.calledOnce( spy );
  48. sinon.assert.calledWithExactly( spy, sinon.match.any, { name: 'foo bar baz', character: 'ε' } );
  49. } );
  50. it( 'delegates #tileHover from the tile to the grid on hover the tile', () => {
  51. const tile = view.createTile( 'ε', 'foo bar baz' );
  52. const spy = sinon.spy();
  53. view.on( 'tileHover', spy );
  54. tile.fire( 'mouseover' );
  55. sinon.assert.calledOnce( spy );
  56. sinon.assert.calledWithExactly( spy, sinon.match.any, { name: 'foo bar baz', character: 'ε' } );
  57. } );
  58. } );
  59. } );