8
0

specialcharactersui.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. /* global document */
  6. import SpecialCharacters from '../src/specialcharacters';
  7. import SpecialCharactersMathematical from '../src/specialcharactersmathematical';
  8. import SpecialCharactersArrows from '../src/specialcharactersarrows';
  9. import SpecialCharactersUI from '../src/specialcharactersui';
  10. import SpecialCharactersNavigationView from '../src/ui/specialcharactersnavigationview';
  11. import CharacterGridView from '../src/ui/charactergridview';
  12. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  13. import specialCharactersIcon from '../theme/icons/specialcharacters.svg';
  14. import EventInfo from '@ckeditor/ckeditor5-utils/src/eventinfo';
  15. describe( 'SpecialCharactersUI', () => {
  16. let editor, command, element;
  17. beforeEach( () => {
  18. element = document.createElement( 'div' );
  19. document.body.appendChild( element );
  20. return ClassicTestEditor
  21. .create( element, {
  22. plugins: [
  23. SpecialCharacters,
  24. SpecialCharactersMathematical,
  25. SpecialCharactersArrows,
  26. SpecialCharactersUI
  27. ]
  28. } )
  29. .then( newEditor => {
  30. editor = newEditor;
  31. command = editor.commands.get( 'insertSpecialCharacter' );
  32. } );
  33. } );
  34. afterEach( () => {
  35. element.remove();
  36. return editor.destroy();
  37. } );
  38. it( 'should be named', () => {
  39. expect( SpecialCharactersUI.pluginName ).to.equal( 'SpecialCharactersUI' );
  40. } );
  41. describe( '"specialCharacters" dropdown', () => {
  42. let dropdown;
  43. beforeEach( () => {
  44. dropdown = editor.ui.componentFactory.create( 'specialCharacters' );
  45. } );
  46. afterEach( () => {
  47. dropdown.destroy();
  48. } );
  49. it( 'has a navigation view', () => {
  50. expect( dropdown.panelView.children.first ).to.be.instanceOf( SpecialCharactersNavigationView );
  51. } );
  52. it( 'has a grid view', () => {
  53. expect( dropdown.panelView.children.last ).to.be.instanceOf( CharacterGridView );
  54. } );
  55. describe( '#buttonView', () => {
  56. it( 'should get basic properties', () => {
  57. expect( dropdown.buttonView.label ).to.equal( 'Special characters' );
  58. expect( dropdown.buttonView.icon ).to.equal( specialCharactersIcon );
  59. expect( dropdown.buttonView.tooltip ).to.be.true;
  60. } );
  61. it( 'should bind #isEnabled to the command', () => {
  62. expect( dropdown.isEnabled ).to.be.true;
  63. command.isEnabled = false;
  64. expect( dropdown.isEnabled ).to.be.false;
  65. command.isEnabled = true;
  66. } );
  67. } );
  68. it( 'executes a command and focuses the editing view', () => {
  69. const grid = dropdown.panelView.children.last;
  70. const executeSpy = sinon.stub( editor, 'execute' );
  71. const focusSpy = sinon.stub( editor.editing.view, 'focus' );
  72. grid.tiles.get( 2 ).fire( 'execute' );
  73. sinon.assert.calledOnce( executeSpy );
  74. sinon.assert.calledOnce( focusSpy );
  75. sinon.assert.calledWithExactly( executeSpy.firstCall, 'insertSpecialCharacter', {
  76. item: 'Less-than or equal to'
  77. } );
  78. } );
  79. describe( 'grid view', () => {
  80. let grid;
  81. beforeEach( () => {
  82. grid = dropdown.panelView.children.last;
  83. } );
  84. it( 'delegates #execute to the dropdown', () => {
  85. const spy = sinon.spy();
  86. dropdown.on( 'execute', spy );
  87. grid.fire( 'execute', { name: 'foo' } );
  88. sinon.assert.calledOnce( spy );
  89. } );
  90. it( 'has default contents', () => {
  91. expect( grid.tiles ).to.have.length.greaterThan( 10 );
  92. } );
  93. it( 'is updated when navigation view fires #execute', () => {
  94. const navigation = dropdown.panelView.children.first;
  95. expect( grid.tiles.get( 0 ).label ).to.equal( '<' );
  96. navigation.groupDropdownView.fire( new EventInfo( { label: 'Arrows' }, 'execute' ) );
  97. expect( grid.tiles.get( 0 ).label ).to.equal( '⇐' );
  98. } );
  99. } );
  100. } );
  101. } );