Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Added tests for TodoList and TodoListUI plugins.
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarwrobel committed Aug 7, 2019
1 parent 9353588 commit 0d448f1
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/todolist.js
Original file line number Diff line number Diff line change
@@ -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 changes: 61 additions & 0 deletions tests/todolistui.js
Original file line number Diff line number Diff line change
@@ -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;
} );
} );

0 comments on commit 0d448f1

Please sign in to comment.