8
0

removeformatui.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 RemoveFormat from '../src/removeformat';
  7. import RemoveFormatUI from '../src/removeformatui';
  8. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  9. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  10. import {
  11. _clear as clearTranslations,
  12. add as addTranslations
  13. } from '@ckeditor/ckeditor5-utils/src/translation-service';
  14. describe( 'RemoveFormatUI', () => {
  15. let editor, command, element, button;
  16. testUtils.createSinonSandbox();
  17. before( () => {
  18. addTranslations( 'en', {
  19. 'Remove Format': 'Remove Format'
  20. } );
  21. addTranslations( 'pl', {
  22. 'Remove Format': 'Usuń formatowanie'
  23. } );
  24. } );
  25. after( () => {
  26. clearTranslations();
  27. } );
  28. beforeEach( () => {
  29. element = document.createElement( 'div' );
  30. document.body.appendChild( element );
  31. return ClassicTestEditor
  32. .create( element, {
  33. plugins: [ RemoveFormat, RemoveFormatUI ]
  34. } )
  35. .then( newEditor => {
  36. editor = newEditor;
  37. command = editor.commands.get( 'removeFormat' );
  38. button = editor.ui.componentFactory.create( 'removeFormat' );
  39. } );
  40. } );
  41. afterEach( () => {
  42. element.remove();
  43. return editor.destroy();
  44. } );
  45. describe( 'removeformat button', () => {
  46. describe( 'is bound to the command state', () => {
  47. it( 'isEnabled', () => {
  48. command.isEnabled = false;
  49. expect( button.isEnabled ).to.be.false;
  50. command.isEnabled = true;
  51. expect( button.isEnabled ).to.be.true;
  52. } );
  53. } );
  54. it( 'should change relay execute to the command', () => {
  55. const commandSpy = testUtils.sinon.spy( command, 'execute' );
  56. button.fire( 'execute' );
  57. sinon.assert.calledOnce( commandSpy );
  58. } );
  59. describe( 'localization', () => {
  60. beforeEach( () => {
  61. return localizedEditor();
  62. } );
  63. it( 'label localized correctly', () => {
  64. expect( button.label ).to.equal( 'Usuń formatowanie' );
  65. } );
  66. function localizedEditor() {
  67. const editorElement = document.createElement( 'div' );
  68. document.body.appendChild( editorElement );
  69. return ClassicTestEditor
  70. .create( editorElement, {
  71. plugins: [ RemoveFormat, RemoveFormatUI ],
  72. toolbar: [ 'removeFormat' ],
  73. language: 'pl'
  74. } )
  75. .then( newEditor => {
  76. button = newEditor.ui.componentFactory.create( 'removeFormat' );
  77. command = newEditor.commands.get( 'removeFormat' );
  78. editorElement.remove();
  79. return newEditor.destroy();
  80. } );
  81. }
  82. } );
  83. } );
  84. } );