specialcharactersnavigationview.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 SpecialCharactersNavigationView from '../../src/ui/specialcharactersnavigationview';
  6. import LabelView from '@ckeditor/ckeditor5-ui/src/label/labelview';
  7. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  8. describe( 'SpecialCharactersNavigationView', () => {
  9. let view, locale;
  10. testUtils.createSinonSandbox();
  11. beforeEach( () => {
  12. locale = {
  13. t: val => val
  14. };
  15. view = new SpecialCharactersNavigationView( locale, [ 'groupA', 'groupB' ] );
  16. view.render();
  17. } );
  18. afterEach( () => {
  19. view.destroy();
  20. } );
  21. describe( 'constructor()', () => {
  22. it( 'creates #labelView', () => {
  23. expect( view.labelView ).to.be.instanceOf( LabelView );
  24. expect( view.labelView.text ).to.equal( 'Special characters' );
  25. } );
  26. it( 'creates #groupDropdownView', () => {
  27. } );
  28. it( 'creates #element from template', () => {
  29. expect( view.element.classList.contains( 'ck' ) ).to.be.true;
  30. expect( view.element.classList.contains( 'ck-special-characters-navigation' ) ).to.be.true;
  31. expect( view.element.firstChild ).to.equal( view.labelView.element );
  32. expect( view.element.lastChild ).to.equal( view.groupDropdownView.element );
  33. } );
  34. } );
  35. describe( 'currentGroupName()', () => {
  36. it( 'returns the #value of #groupDropdownView', () => {
  37. expect( view.currentGroupName ).to.equal( 'groupA' );
  38. view.groupDropdownView.listView.items.last.children.first.fire( 'execute' );
  39. expect( view.currentGroupName ).to.equal( 'groupB' );
  40. } );
  41. } );
  42. describe( '#groupDropdownView', () => {
  43. let groupDropdownView;
  44. beforeEach( () => {
  45. groupDropdownView = view.groupDropdownView;
  46. } );
  47. it( 'has a default #value', () => {
  48. expect( view.currentGroupName ).to.equal( 'groupA' );
  49. } );
  50. it( 'has a right #panelPosition (LTR)', () => {
  51. expect( groupDropdownView.panelPosition ).to.equal( 'sw' );
  52. } );
  53. it( 'has a right #panelPosition (RTL)', () => {
  54. const locale = {
  55. uiLanguageDirection: 'rtl',
  56. t: val => val
  57. };
  58. view = new SpecialCharactersNavigationView( locale, [ 'groupA', 'groupB' ] );
  59. view.render();
  60. expect( view.groupDropdownView.panelPosition ).to.equal( 'se' );
  61. view.destroy();
  62. } );
  63. it( 'binds its buttonView#label to #value', () => {
  64. expect( groupDropdownView.buttonView.label ).to.equal( 'groupA' );
  65. groupDropdownView.listView.items.last.children.first.fire( 'execute' );
  66. expect( groupDropdownView.buttonView.label ).to.equal( 'groupB' );
  67. } );
  68. it( 'configures the #buttonView', () => {
  69. expect( groupDropdownView.buttonView.isOn ).to.be.false;
  70. expect( groupDropdownView.buttonView.withText ).to.be.true;
  71. expect( groupDropdownView.buttonView.tooltip ).to.equal( 'Character categories' );
  72. } );
  73. it( 'delegates #execute to the naviation view', () => {
  74. const spy = sinon.spy();
  75. view.on( 'execute', spy );
  76. groupDropdownView.fire( 'execute' );
  77. sinon.assert.calledOnce( spy );
  78. } );
  79. describe( 'character group list items', () => {
  80. it( 'have basic properties', () => {
  81. expect( groupDropdownView.listView.items
  82. .map( item => {
  83. const { label, withText } = item.children.first;
  84. return { label, withText };
  85. } ) )
  86. .to.deep.equal( [
  87. { label: 'groupA', withText: true },
  88. { label: 'groupB', withText: true }
  89. ] );
  90. } );
  91. it( 'bind #isOn to the #value of the dropdown', () => {
  92. const firstButton = groupDropdownView.listView.items.first.children.last;
  93. const lastButton = groupDropdownView.listView.items.last.children.last;
  94. expect( firstButton.isOn ).to.be.true;
  95. expect( lastButton.isOn ).to.be.false;
  96. groupDropdownView.value = 'groupB';
  97. expect( firstButton.isOn ).to.be.false;
  98. expect( lastButton.isOn ).to.be.true;
  99. } );
  100. } );
  101. } );
  102. } );