listui.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. /* globals document */
  6. import ListEditing from '../src/listediting';
  7. import ListUI from '../src/listui';
  8. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  9. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  10. import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote';
  11. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  12. import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  13. describe( 'ListUI', () => {
  14. let editorElement, editor, model, bulletedListButton, numberedListButton;
  15. beforeEach( () => {
  16. editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. return ClassicTestEditor.create( editorElement, { plugins: [ Paragraph, BlockQuote, ListEditing, ListUI ] } )
  19. .then( newEditor => {
  20. editor = newEditor;
  21. model = editor.model;
  22. bulletedListButton = editor.ui.componentFactory.create( 'bulletedList' );
  23. numberedListButton = editor.ui.componentFactory.create( 'numberedList' );
  24. } );
  25. } );
  26. afterEach( () => {
  27. editorElement.remove();
  28. return editor.destroy();
  29. } );
  30. it( 'should be loaded', () => {
  31. expect( editor.plugins.get( ListUI ) ).to.be.instanceOf( ListUI );
  32. } );
  33. it( 'should set up buttons for bulleted list and numbered list', () => {
  34. expect( bulletedListButton ).to.be.instanceOf( ButtonView );
  35. expect( bulletedListButton.isToggleable ).to.be.true;
  36. expect( numberedListButton ).to.be.instanceOf( ButtonView );
  37. expect( numberedListButton.isToggleable ).to.be.true;
  38. } );
  39. it( 'should execute proper commands when buttons are used', () => {
  40. sinon.spy( editor, 'execute' );
  41. bulletedListButton.fire( 'execute' );
  42. sinon.assert.calledWithExactly( editor.execute, 'bulletedList' );
  43. numberedListButton.fire( 'execute' );
  44. sinon.assert.calledWithExactly( editor.execute, 'numberedList' );
  45. } );
  46. it( 'should bind bulleted list button model to bulledList command', () => {
  47. setData( model, '<listItem listType="bulleted" listIndent="0">[]foo</listItem>' );
  48. const command = editor.commands.get( 'bulletedList' );
  49. expect( bulletedListButton.isOn ).to.be.true;
  50. expect( bulletedListButton.isEnabled ).to.be.true;
  51. command.value = false;
  52. expect( bulletedListButton.isOn ).to.be.false;
  53. command.isEnabled = false;
  54. expect( bulletedListButton.isEnabled ).to.be.false;
  55. } );
  56. it( 'should bind numbered list button model to numberedList command', () => {
  57. setData( model, '<listItem listType="bulleted" listIndent="0">[]foo</listItem>' );
  58. const command = editor.commands.get( 'numberedList' );
  59. // We are in UL, so numbered list is off.
  60. expect( numberedListButton.isOn ).to.be.false;
  61. expect( numberedListButton.isEnabled ).to.be.true;
  62. command.value = true;
  63. expect( numberedListButton.isOn ).to.be.true;
  64. command.isEnabled = false;
  65. expect( numberedListButton.isEnabled ).to.be.false;
  66. } );
  67. } );