tableui.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global document */
  6. import TableEditing from '../src/tableediting';
  7. import TableUI from '../src/tableui';
  8. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  9. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  10. import { _clear as clearTranslations, add as addTranslations } from '@ckeditor/ckeditor5-utils/src/translation-service';
  11. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  12. testUtils.createSinonSandbox();
  13. describe( 'TableUI', () => {
  14. let editor, element, insertTable;
  15. before( () => {
  16. addTranslations( 'en', {} );
  17. addTranslations( 'pl', {} );
  18. } );
  19. after( () => {
  20. clearTranslations();
  21. } );
  22. beforeEach( () => {
  23. element = document.createElement( 'div' );
  24. document.body.appendChild( element );
  25. return ClassicTestEditor
  26. .create( element, {
  27. plugins: [ TableEditing, TableUI ]
  28. } )
  29. .then( newEditor => {
  30. editor = newEditor;
  31. insertTable = editor.ui.componentFactory.create( 'insertTable' );
  32. } );
  33. } );
  34. afterEach( () => {
  35. element.remove();
  36. return editor.destroy();
  37. } );
  38. describe( 'insertTable button', () => {
  39. it( 'should register insertTable buton', () => {
  40. expect( insertTable ).to.be.instanceOf( ButtonView );
  41. expect( insertTable.isOn ).to.be.false;
  42. expect( insertTable.label ).to.equal( 'Insert table' );
  43. expect( insertTable.icon ).to.match( /<svg / );
  44. } );
  45. it( 'should bind to insertTable command', () => {
  46. const command = editor.commands.get( 'insertTable' );
  47. expect( insertTable.isOn ).to.be.false;
  48. expect( insertTable.isEnabled ).to.be.true;
  49. command.isEnabled = false;
  50. expect( insertTable.isEnabled ).to.be.false;
  51. } );
  52. it( 'should execute insertTable command on button execute event', () => {
  53. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  54. insertTable.fire( 'execute' );
  55. sinon.assert.calledOnce( executeSpy );
  56. sinon.assert.calledWithExactly( executeSpy, 'insertTable' );
  57. } );
  58. } );
  59. } );