Explorar el Código

Merge pull request #139 from ckeditor/t/138

Internal: Checkbox with a boolean checked attribute is properly converted to a checked todo list item. Closes #138.
Piotr Jasiun hace 6 años
padre
commit
c1adb11f0e

+ 1 - 1
packages/ckeditor5-list/src/todolistconverters.js

@@ -208,7 +208,7 @@ export function dataViewModelCheckmarkInsertion( evt, data, conversionApi ) {
 
 	writer.setAttribute( 'listType', 'todo', modelItem );
 
-	if ( data.viewItem.getAttribute( 'checked' ) == 'checked' ) {
+	if ( data.viewItem.hasAttribute( 'checked' ) ) {
 		writer.setAttribute( 'todoListChecked', true, modelItem );
 	}
 

+ 14 - 6
packages/ckeditor5-list/tests/todolistediting.js

@@ -545,17 +545,25 @@ describe( 'TodoListEditing', () => {
 	} );
 
 	describe( 'data pipeline v -> m', () => {
-		it( 'should convert li with checkbox inside before the first text node as todo list item', () => {
-			editor.setData( '<ul><li><span><input type="checkbox">Foo</span></li></ul>' );
+		it( 'should convert li with checkbox before the first text node as todo list item', () => {
+			editor.setData( '<ul><li><input type="checkbox">foo</li></ul>' );
 
-			expect( getModelData( model ) ).to.equal( '<listItem listIndent="0" listType="todo">[]Foo</listItem>' );
+			expect( getModelData( model ) ).to.equal( '<listItem listIndent="0" listType="todo">[]foo</listItem>' );
 		} );
 
-		it( 'should convert li with checked checkbox inside as checked todo list item', () => {
-			editor.setData( '<ul><li><span><input type="checkbox" checked="checked">Foo</span></li></ul>' );
+		it( 'should convert li with checked checkbox as checked todo list item', () => {
+			editor.setData(
+				'<ul>' +
+					'<li><input type="checkbox" checked="checked">a</li>' +
+					'<li><input type="checkbox" checked="anything">b</li>' +
+					'<li><input type="checkbox" checked>c</li>' +
+				'</ul>'
+			);
 
 			expect( getModelData( model ) ).to.equal(
-				'<listItem listIndent="0" listType="todo" todoListChecked="true">[]Foo</listItem>'
+				'<listItem listIndent="0" listType="todo" todoListChecked="true">[]a</listItem>' +
+				'<listItem listIndent="0" listType="todo" todoListChecked="true">b</listItem>' +
+				'<listItem listIndent="0" listType="todo" todoListChecked="true">c</listItem>'
 			);
 		} );