8
0

specialcharacters.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 SpecialCharacters from '../src/specialcharacters';
  6. import SpecialCharactersUI from '../src/specialcharactersui';
  7. import SpecialCharactersEditing from '../src/specialcharactersediting';
  8. describe( 'SpecialCharacters', () => {
  9. let plugin;
  10. beforeEach( () => {
  11. plugin = new SpecialCharacters( {} );
  12. } );
  13. it( 'should require proper plugins', () => {
  14. expect( SpecialCharacters.requires ).to.deep.equal( [ SpecialCharactersEditing, SpecialCharactersUI ] );
  15. } );
  16. it( 'should be named', () => {
  17. expect( SpecialCharacters.pluginName ).to.equal( 'SpecialCharacters' );
  18. } );
  19. describe( 'addItems()', () => {
  20. it( 'adds special characters to the available symbols', () => {
  21. plugin.addItems( 'Arrows', [
  22. { title: 'arrow left', character: '←' },
  23. { title: 'arrow right', character: '→' }
  24. ] );
  25. expect( plugin._groups.size ).to.equal( 1 );
  26. expect( plugin._groups.has( 'Arrows' ) ).to.equal( true );
  27. expect( plugin._characters.size ).to.equal( 2 );
  28. expect( plugin._characters.has( 'arrow left' ) ).to.equal( true );
  29. expect( plugin._characters.has( 'arrow right' ) ).to.equal( true );
  30. } );
  31. } );
  32. describe( 'getGroups()', () => {
  33. it( 'returns iterator of defined groups', () => {
  34. plugin.addItems( 'Arrows', [
  35. { title: 'arrow left', character: '←' }
  36. ] );
  37. plugin.addItems( 'Mathematical', [
  38. { title: 'precedes', character: '≺' },
  39. { title: 'succeeds', character: '≻' }
  40. ] );
  41. const groups = [ ...plugin.getGroups() ];
  42. expect( groups ).to.deep.equal( [ 'Arrows', 'Mathematical' ] );
  43. } );
  44. } );
  45. describe( 'getCharactersForGroup()', () => {
  46. it( 'returns a collection of defined special characters names', () => {
  47. plugin.addItems( 'Mathematical', [
  48. { title: 'precedes', character: '≺' },
  49. { title: 'succeeds', character: '≻' }
  50. ] );
  51. const characters = plugin.getCharactersForGroup( 'Mathematical' );
  52. expect( characters.size ).to.equal( 2 );
  53. expect( characters.has( 'precedes' ) ).to.equal( true );
  54. expect( characters.has( 'succeeds' ) ).to.equal( true );
  55. } );
  56. it( 'returns undefined for non-existing group', () => {
  57. plugin.addItems( 'Mathematical', [
  58. { title: 'precedes', character: '≺' },
  59. { title: 'succeeds', character: '≻' }
  60. ] );
  61. const characters = plugin.getCharactersForGroup( 'Foo' );
  62. expect( characters ).to.be.undefined;
  63. } );
  64. } );
  65. describe( 'getCharacter()', () => {
  66. it( 'returns a collection of defined special characters names', () => {
  67. plugin.addItems( 'Mathematical', [
  68. { title: 'precedes', character: '≺' },
  69. { title: 'succeeds', character: '≻' }
  70. ] );
  71. expect( plugin.getCharacter( 'succeeds' ) ).to.equal( '≻' );
  72. } );
  73. it( 'returns undefined for non-existing character', () => {
  74. expect( plugin.getCharacter( 'succeeds' ) ).to.be.undefined;
  75. } );
  76. } );
  77. } );