8
0
Просмотр исходного кода

Added tests for TodoList and TodoListUI plugins.

Oskar Wróbel 6 лет назад
Родитель
Сommit
68a66194dd
2 измененных файлов с 79 добавлено и 0 удалено
  1. 18 0
      packages/ckeditor5-list/tests/todolist.js
  2. 61 0
      packages/ckeditor5-list/tests/todolistui.js

+ 18 - 0
packages/ckeditor5-list/tests/todolist.js

@@ -0,0 +1,18 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+import TodoList from '../src/todolist';
+import TodoListEditing from '../src/todolistediting';
+import TodoListUI from '../src/todolistui';
+
+describe( 'TodoList', () => {
+	it( 'should be named', () => {
+		expect( TodoList.pluginName ).to.equal( 'TodoList' );
+	} );
+
+	it( 'should require TodoListEditing and TodoListUI', () => {
+		expect( TodoList.requires ).to.deep.equal( [ TodoListEditing, TodoListUI ] );
+	} );
+} );

+ 61 - 0
packages/ckeditor5-list/tests/todolistui.js

@@ -0,0 +1,61 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+/* globals document */
+
+import TodoListEditing from '../src/todolistediting';
+import TodoListUI from '../src/todolistui';
+
+import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
+import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+
+describe( 'TodoListUI', () => {
+	let editor, model, button;
+
+	beforeEach( () => {
+		const editorElement = document.createElement( 'div' );
+		document.body.appendChild( editorElement );
+
+		return ClassicTestEditor.create( editorElement, { plugins: [ Paragraph, TodoListEditing, TodoListUI ] } )
+			.then( newEditor => {
+				editor = newEditor;
+				model = editor.model;
+
+				button = editor.ui.componentFactory.create( 'todoList' );
+			} );
+	} );
+
+	afterEach( () => {
+		return editor.destroy();
+	} );
+
+	it( 'should set up buttons for bulleted list and numbered list', () => {
+		expect( button ).to.be.instanceOf( ButtonView );
+	} );
+
+	it( 'should execute proper commands when buttons are used', () => {
+		sinon.spy( editor, 'execute' );
+
+		button.fire( 'execute' );
+		sinon.assert.calledWithExactly( editor.execute, 'todoList' );
+	} );
+
+	it( 'should bind button to command', () => {
+		setData( model, '<listItem listType="todo" listIndent="0">[]foo</listItem>' );
+
+		const command = editor.commands.get( 'todoList' );
+
+		expect( button.isOn ).to.be.true;
+		expect( button.isEnabled ).to.be.true;
+
+		command.value = false;
+		expect( button.isOn ).to.be.false;
+
+		command.isEnabled = false;
+		expect( button.isEnabled ).to.be.false;
+	} );
+} );