specialcharacters.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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( 'addItems()', () => {
  46. it( 'works with subsequent calls to the same group', () => {
  47. plugin.addItems( 'Mathematical', [ {
  48. title: 'dot',
  49. character: '.'
  50. } ] );
  51. plugin.addItems( 'Mathematical', [ {
  52. title: ',',
  53. character: 'comma'
  54. } ] );
  55. const groups = [ ...plugin.getGroups() ];
  56. expect( groups ).to.deep.equal( [ 'Mathematical' ] );
  57. } );
  58. } );
  59. describe( 'getCharactersForGroup()', () => {
  60. it( 'returns a collection of defined special characters names', () => {
  61. plugin.addItems( 'Mathematical', [
  62. { title: 'precedes', character: '≺' },
  63. { title: 'succeeds', character: '≻' }
  64. ] );
  65. const characters = plugin.getCharactersForGroup( 'Mathematical' );
  66. expect( characters.size ).to.equal( 2 );
  67. expect( characters.has( 'precedes' ) ).to.equal( true );
  68. expect( characters.has( 'succeeds' ) ).to.equal( true );
  69. } );
  70. it( 'returns undefined for non-existing group', () => {
  71. plugin.addItems( 'Mathematical', [
  72. { title: 'precedes', character: '≺' },
  73. { title: 'succeeds', character: '≻' }
  74. ] );
  75. const characters = plugin.getCharactersForGroup( 'Foo' );
  76. expect( characters ).to.be.undefined;
  77. } );
  78. } );
  79. describe( 'getCharacter()', () => {
  80. it( 'returns a collection of defined special characters names', () => {
  81. plugin.addItems( 'Mathematical', [
  82. { title: 'precedes', character: '≺' },
  83. { title: 'succeeds', character: '≻' }
  84. ] );
  85. expect( plugin.getCharacter( 'succeeds' ) ).to.equal( '≻' );
  86. } );
  87. it( 'returns undefined for non-existing character', () => {
  88. expect( plugin.getCharacter( 'succeeds' ) ).to.be.undefined;
  89. } );
  90. } );
  91. } );