8
0

tableui.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import { _clear as clearTranslations, add as addTranslations } from '@ckeditor/ckeditor5-utils/src/translation-service';
  8. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  9. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  10. import TableEditing from '../src/tableediting';
  11. import TableUI from '../src/tableui';
  12. testUtils.createSinonSandbox();
  13. describe( 'TableUI', () => {
  14. let editor, element;
  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. } );
  32. } );
  33. afterEach( () => {
  34. element.remove();
  35. return editor.destroy();
  36. } );
  37. describe( 'insertTable button', () => {
  38. let insertTable;
  39. beforeEach( () => {
  40. insertTable = editor.ui.componentFactory.create( 'insertTable' );
  41. } );
  42. it( 'should register insertTable buton', () => {
  43. expect( insertTable ).to.be.instanceOf( ButtonView );
  44. expect( insertTable.isOn ).to.be.false;
  45. expect( insertTable.label ).to.equal( 'Insert table' );
  46. expect( insertTable.icon ).to.match( /<svg / );
  47. } );
  48. it( 'should bind to insertTable command', () => {
  49. const command = editor.commands.get( 'insertTable' );
  50. command.isEnabled = true;
  51. expect( insertTable.isOn ).to.be.false;
  52. expect( insertTable.isEnabled ).to.be.true;
  53. command.isEnabled = false;
  54. expect( insertTable.isEnabled ).to.be.false;
  55. } );
  56. it( 'should execute insertTable command on button execute event', () => {
  57. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  58. insertTable.fire( 'execute' );
  59. sinon.assert.calledOnce( executeSpy );
  60. sinon.assert.calledWithExactly( executeSpy, 'insertTable' );
  61. } );
  62. } );
  63. describe( 'insertRowBelow button', () => {
  64. let insertRow;
  65. beforeEach( () => {
  66. insertRow = editor.ui.componentFactory.create( 'insertRowBelow' );
  67. } );
  68. it( 'should register insertRowBelow button', () => {
  69. expect( insertRow ).to.be.instanceOf( ButtonView );
  70. expect( insertRow.isOn ).to.be.false;
  71. expect( insertRow.label ).to.equal( 'Insert row' );
  72. expect( insertRow.icon ).to.match( /<svg / );
  73. } );
  74. it( 'should bind to insertRow command', () => {
  75. const command = editor.commands.get( 'insertRowBelow' );
  76. command.isEnabled = true;
  77. expect( insertRow.isOn ).to.be.false;
  78. expect( insertRow.isEnabled ).to.be.true;
  79. command.isEnabled = false;
  80. expect( insertRow.isEnabled ).to.be.false;
  81. } );
  82. it( 'should execute insertRow command on button execute event', () => {
  83. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  84. insertRow.fire( 'execute' );
  85. sinon.assert.calledOnce( executeSpy );
  86. sinon.assert.calledWithExactly( executeSpy, 'insertRowBelow' );
  87. } );
  88. } );
  89. describe( 'insertColumnAfter button', () => {
  90. let insertColumn;
  91. beforeEach( () => {
  92. insertColumn = editor.ui.componentFactory.create( 'insertColumnAfter' );
  93. } );
  94. it( 'should register insertColumn buton', () => {
  95. expect( insertColumn ).to.be.instanceOf( ButtonView );
  96. expect( insertColumn.isOn ).to.be.false;
  97. expect( insertColumn.label ).to.equal( 'Insert column' );
  98. expect( insertColumn.icon ).to.match( /<svg / );
  99. } );
  100. it( 'should bind to insertColumn command', () => {
  101. const command = editor.commands.get( 'insertColumnAfter' );
  102. command.isEnabled = true;
  103. expect( insertColumn.isOn ).to.be.false;
  104. expect( insertColumn.isEnabled ).to.be.true;
  105. command.isEnabled = false;
  106. expect( insertColumn.isEnabled ).to.be.false;
  107. } );
  108. it( 'should execute insertColumn command on button execute event', () => {
  109. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  110. insertColumn.fire( 'execute' );
  111. sinon.assert.calledOnce( executeSpy );
  112. sinon.assert.calledWithExactly( executeSpy, 'insertColumnAfter' );
  113. } );
  114. } );
  115. } );