restrictededitingmodeui.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. /* global document */
  6. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  7. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  8. import RestrictedEditingModeEditing from './../src/restrictededitingmodeediting';
  9. import RestrictedEditingModeUI from './../src/restrictededitingmodeui';
  10. import lockIcon from '../theme/icons/contentlock.svg';
  11. describe( 'RestrictedEditingModeUI', () => {
  12. let editor, element, goToPreviousCommand, goToNextCommand;
  13. testUtils.createSinonSandbox();
  14. beforeEach( async () => {
  15. element = document.createElement( 'div' );
  16. document.body.appendChild( element );
  17. editor = await ClassicTestEditor.create( element, {
  18. plugins: [ RestrictedEditingModeEditing, RestrictedEditingModeUI ]
  19. } );
  20. goToPreviousCommand = editor.commands.get( 'goToPreviousRestrictedEditingException' );
  21. goToNextCommand = editor.commands.get( 'goToNextRestrictedEditingException' );
  22. } );
  23. afterEach( async () => {
  24. element.remove();
  25. await editor.destroy();
  26. } );
  27. describe( 'plugin', () => {
  28. it( 'should be named', () => {
  29. expect( RestrictedEditingModeUI.pluginName ).to.equal( 'RestrictedEditingModeUI' );
  30. } );
  31. it( 'should be loaded', () => {
  32. expect( editor.plugins.get( RestrictedEditingModeUI ) ).to.be.instanceOf( RestrictedEditingModeUI );
  33. } );
  34. } );
  35. describe( 'restricted editing dropdown', () => {
  36. let dropdown;
  37. beforeEach( () => {
  38. dropdown = editor.ui.componentFactory.create( 'restrictedEditing' );
  39. } );
  40. it( 'the button should have basic properties', () => {
  41. const button = dropdown.buttonView;
  42. expect( button ).to.have.property( 'label', 'Navigate editable regions' );
  43. expect( button ).to.have.property( 'tooltip', true );
  44. expect( button ).to.have.property( 'icon', lockIcon );
  45. expect( button ).to.have.property( 'isEnabled', true );
  46. expect( button ).to.have.property( 'isOn', false );
  47. } );
  48. describe( 'exceptions navigation buttons', () => {
  49. it( 'should have one that goes backward', () => {
  50. const list = dropdown.listView;
  51. const button = list.items.first.children.first;
  52. expect( button.isOn ).to.be.false;
  53. expect( button.withText ).to.be.true;
  54. expect( button.withKeystroke ).to.be.true;
  55. expect( button.label ).to.equal( 'Previous editable region' );
  56. expect( button.keystroke ).to.equal( 'Shift+Tab' );
  57. } );
  58. it( 'should have one that goes forward', () => {
  59. const list = dropdown.listView;
  60. const button = list.items.last.children.first;
  61. expect( button.isOn ).to.be.false;
  62. expect( button.withText ).to.be.true;
  63. expect( button.withKeystroke ).to.be.true;
  64. expect( button.label ).to.equal( 'Next editable region' );
  65. expect( button.keystroke ).to.equal( 'Tab' );
  66. } );
  67. it( 'should focus the view after executing the command', () => {
  68. const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
  69. const list = dropdown.listView;
  70. const goToPreviousButton = list.items.first.children.first;
  71. goToPreviousButton.fire( 'execute' );
  72. sinon.assert.calledOnce( focusSpy );
  73. } );
  74. it( 'be enabled just like their corresponding commands', () => {
  75. const listView = dropdown.listView;
  76. goToPreviousCommand.isEnabled = false;
  77. goToNextCommand.isEnabled = false;
  78. expect( listView.items.map( item => item.children.first.isEnabled ) ).to.deep.equal( [ false, false ] );
  79. goToPreviousCommand.isEnabled = true;
  80. expect( listView.items.map( item => item.children.first.isEnabled ) ).to.deep.equal( [ true, false ] );
  81. goToNextCommand.isEnabled = true;
  82. expect( listView.items.map( item => item.children.first.isEnabled ) ).to.deep.equal( [ true, true ] );
  83. } );
  84. it( 'should execute their corresponding commands', () => {
  85. const list = dropdown.listView;
  86. const goToPreviousButton = list.items.first.children.first;
  87. const goToNextButton = list.items.last.children.first;
  88. goToPreviousCommand.isEnabled = true;
  89. goToNextCommand.isEnabled = true;
  90. const spy = sinon.spy( editor, 'execute' );
  91. goToPreviousButton.fire( 'execute' );
  92. sinon.assert.calledWith( spy.firstCall, 'goToPreviousRestrictedEditingException' );
  93. goToNextButton.fire( 'execute' );
  94. sinon.assert.calledWith( spy.secondCall, 'goToNextRestrictedEditingException' );
  95. } );
  96. } );
  97. } );
  98. } );