listui.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  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 editor, model, bulletedListButton, numberedListButton;
  15. beforeEach( () => {
  16. const 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. return editor.destroy();
  28. } );
  29. it( 'should be loaded', () => {
  30. expect( editor.plugins.get( ListUI ) ).to.be.instanceOf( ListUI );
  31. } );
  32. it( 'should set up buttons for bulleted list and numbered list', () => {
  33. expect( bulletedListButton ).to.be.instanceOf( ButtonView );
  34. expect( numberedListButton ).to.be.instanceOf( ButtonView );
  35. } );
  36. it( 'should execute proper commands when buttons are used', () => {
  37. sinon.spy( editor, 'execute' );
  38. bulletedListButton.fire( 'execute' );
  39. sinon.assert.calledWithExactly( editor.execute, 'bulletedList' );
  40. numberedListButton.fire( 'execute' );
  41. sinon.assert.calledWithExactly( editor.execute, 'numberedList' );
  42. } );
  43. it( 'should bind bulleted list button model to bulledList command', () => {
  44. setData( model, '<listItem listType="bulleted" listIndent="0">[]foo</listItem>' );
  45. const command = editor.commands.get( 'bulletedList' );
  46. expect( bulletedListButton.isOn ).to.be.true;
  47. expect( bulletedListButton.isEnabled ).to.be.true;
  48. command.value = false;
  49. expect( bulletedListButton.isOn ).to.be.false;
  50. command.isEnabled = false;
  51. expect( bulletedListButton.isEnabled ).to.be.false;
  52. } );
  53. it( 'should bind numbered list button model to numberedList command', () => {
  54. setData( model, '<listItem listType="bulleted" listIndent="0">[]foo</listItem>' );
  55. const command = editor.commands.get( 'numberedList' );
  56. // We are in UL, so numbered list is off.
  57. expect( numberedListButton.isOn ).to.be.false;
  58. expect( numberedListButton.isEnabled ).to.be.true;
  59. command.value = true;
  60. expect( numberedListButton.isOn ).to.be.true;
  61. command.isEnabled = false;
  62. expect( numberedListButton.isEnabled ).to.be.false;
  63. } );
  64. } );