todolistui.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 TodoListEditing from '../src/todolistediting';
  7. import TodoListUI from '../src/todolistui';
  8. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  9. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  10. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  11. import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  12. describe( 'TodoListUI', () => {
  13. let editorElement, editor, model, button;
  14. beforeEach( () => {
  15. editorElement = document.createElement( 'div' );
  16. document.body.appendChild( editorElement );
  17. return ClassicTestEditor.create( editorElement, { plugins: [ Paragraph, TodoListEditing, TodoListUI ] } )
  18. .then( newEditor => {
  19. editor = newEditor;
  20. model = editor.model;
  21. button = editor.ui.componentFactory.create( 'todoList' );
  22. } );
  23. } );
  24. afterEach( () => {
  25. editorElement.remove();
  26. return editor.destroy();
  27. } );
  28. it( 'should set up buttons for bulleted list and numbered list', () => {
  29. expect( button ).to.be.instanceOf( ButtonView );
  30. } );
  31. it( 'should execute proper commands when buttons are used', () => {
  32. sinon.spy( editor, 'execute' );
  33. button.fire( 'execute' );
  34. sinon.assert.calledWithExactly( editor.execute, 'todoList' );
  35. } );
  36. it( 'should bind button to command', () => {
  37. setData( model, '<listItem listType="todo" listIndent="0">[]foo</listItem>' );
  38. const command = editor.commands.get( 'todoList' );
  39. expect( button.isOn ).to.be.true;
  40. expect( button.isEnabled ).to.be.true;
  41. command.value = false;
  42. expect( button.isOn ).to.be.false;
  43. command.isEnabled = false;
  44. expect( button.isEnabled ).to.be.false;
  45. } );
  46. } );