Explorar o código

Tests: Fix current tests.

Maciej Gołaszewski %!s(int64=8) %!d(string=hai) anos
pai
achega
46fb164716

+ 1 - 1
packages/ckeditor5-font/src/fontfamily/fontfamilycommand.js

@@ -42,7 +42,7 @@ export default class FontFamilyCommand extends Command {
 	 * @param {Object} [options] Options for the executed command.
 	 * @param {Object} [options] Options for the executed command.
 	 * @param {String} [options.fontFamily] FontSize value to apply.
 	 * @param {String} [options.fontFamily] FontSize value to apply.
 	 */
 	 */
-	execute( options ) {
+	execute( options = {} ) {
 		const model = this.editor.model;
 		const model = this.editor.model;
 		const document = model.document;
 		const document = model.document;
 		const selection = document.selection;
 		const selection = document.selection;

+ 1 - 1
packages/ckeditor5-font/src/fontsize/fontsizecommand.js

@@ -41,7 +41,7 @@ export default class FontSizeCommand extends Command {
 	 * @param {Object} [options] Options for the executed command.
 	 * @param {Object} [options] Options for the executed command.
 	 * @param {String} [options.fontSize] FontSize value to apply.
 	 * @param {String} [options.fontSize] FontSize value to apply.
 	 */
 	 */
-	execute( options ) {
+	execute( options = {} ) {
 		const model = this.editor.model;
 		const model = this.editor.model;
 		const document = model.document;
 		const document = model.document;
 		const selection = document.selection;
 		const selection = document.selection;

+ 3 - 2
packages/ckeditor5-font/tests/fontfamily.js

@@ -5,10 +5,11 @@
 
 
 import FontFamily from './../src/fontfamily';
 import FontFamily from './../src/fontfamily';
 import FontFamilyEditing from './../src/fontfamily/fontfamilyediting';
 import FontFamilyEditing from './../src/fontfamily/fontfamilyediting';
+import FontFamilyUI from '../src/fontfamily/fontfamilyui';
 
 
 describe( 'FontFamily', () => {
 describe( 'FontFamily', () => {
-	it( 'requires FontFamilyEditing', () => {
-		expect( FontFamily.requires ).to.deep.equal( [ FontFamilyEditing ] );
+	it( 'requires FontFamilyEditing and FontFamilyUI', () => {
+		expect( FontFamily.requires ).to.deep.equal( [ FontFamilyEditing, FontFamilyUI ] );
 	} );
 	} );
 
 
 	it( 'defines plugin name', () => {
 	it( 'defines plugin name', () => {

+ 34 - 14
packages/ckeditor5-font/tests/fontfamily/fontfamilycommand.js

@@ -18,7 +18,7 @@ describe( 'FontFamilyCommand', () => {
 				editor = newEditor;
 				editor = newEditor;
 				model = editor.model;
 				model = editor.model;
 
 
-				command = new FontFamilyCommand( editor, 'arial' );
+				command = new FontFamilyCommand( editor );
 				editor.commands.add( 'fontFamily', command );
 				editor.commands.add( 'fontFamily', command );
 
 
 				model.schema.registerItem( 'paragraph', '$block' );
 				model.schema.registerItem( 'paragraph', '$block' );
@@ -36,16 +36,16 @@ describe( 'FontFamilyCommand', () => {
 	} );
 	} );
 
 
 	describe( 'value', () => {
 	describe( 'value', () => {
-		it( 'is set to true when selection is in text with fontFamily attribute', () => {
+		it( 'is set to fontFamily value when selection is in text with fontFamily attribute', () => {
 			setData( model, '<paragraph><$text fontFamily="arial">fo[]o</$text></paragraph>' );
 			setData( model, '<paragraph><$text fontFamily="arial">fo[]o</$text></paragraph>' );
 
 
-			expect( command ).to.have.property( 'value', true );
+			expect( command ).to.have.property( 'value', 'arial' );
 		} );
 		} );
 
 
 		it( 'is undefined when selection is not in text with fontFamily attribute', () => {
 		it( 'is undefined when selection is not in text with fontFamily attribute', () => {
 			setData( model, '<paragraph>fo[]o</paragraph>' );
 			setData( model, '<paragraph>fo[]o</paragraph>' );
 
 
-			expect( command ).to.have.property( 'value', false );
+			expect( command ).to.have.property( 'value', undefined );
 		} );
 		} );
 	} );
 	} );
 
 
@@ -61,11 +61,11 @@ describe( 'FontFamilyCommand', () => {
 		it( 'should add fontFamily attribute on selected text', () => {
 		it( 'should add fontFamily attribute on selected text', () => {
 			setData( model, '<paragraph>a[bc<$text fontFamily="arial">fo]obar</$text>xyz</paragraph>' );
 			setData( model, '<paragraph>a[bc<$text fontFamily="arial">fo]obar</$text>xyz</paragraph>' );
 
 
-			expect( command.value ).to.be.false;
+			expect( command.value ).to.be.undefined;
 
 
-			command.execute();
+			command.execute( { fontFamily: 'arial' } );
 
 
-			expect( command.value ).to.be.true;
+			expect( command.value ).to.equal( 'arial' );
 
 
 			expect( getData( model ) ).to.equal( '<paragraph>a[<$text fontFamily="arial">bcfo]obar</$text>xyz</paragraph>' );
 			expect( getData( model ) ).to.equal( '<paragraph>a[<$text fontFamily="arial">bcfo]obar</$text>xyz</paragraph>' );
 		} );
 		} );
@@ -78,9 +78,9 @@ describe( 'FontFamilyCommand', () => {
 				'<paragraph>barbar]bar</paragraph>'
 				'<paragraph>barbar]bar</paragraph>'
 			);
 			);
 
 
-			command.execute();
+			command.execute( { fontFamily: 'arial' } );
 
 
-			expect( command.value ).to.be.true;
+			expect( command.value ).to.equal( 'arial' );
 
 
 			expect( getData( model ) ).to.equal(
 			expect( getData( model ) ).to.equal(
 				'<paragraph>abcabc[<$text fontFamily="arial">abc</$text></paragraph>' +
 				'<paragraph>abcabc[<$text fontFamily="arial">abc</$text></paragraph>' +
@@ -97,9 +97,9 @@ describe( 'FontFamilyCommand', () => {
 				'<paragraph><$text fontFamily="text-small">bar]bar</$text>bar</paragraph>'
 				'<paragraph><$text fontFamily="text-small">bar]bar</$text>bar</paragraph>'
 			);
 			);
 
 
-			command.execute();
+			command.execute( { fontFamily: 'arial' } );
 
 
-			expect( command.value ).to.be.true;
+			expect( command.value ).to.equal( 'arial' );
 
 
 			expect( getData( model ) ).to.equal(
 			expect( getData( model ) ).to.equal(
 				'<paragraph>abc[<$text fontFamily="arial">abcabc</$text></paragraph>' +
 				'<paragraph>abc[<$text fontFamily="arial">abcabc</$text></paragraph>' +
@@ -111,13 +111,33 @@ describe( 'FontFamilyCommand', () => {
 		it( 'should do nothing on collapsed range', () => {
 		it( 'should do nothing on collapsed range', () => {
 			setData( model, '<paragraph>abc<$text fontFamily="arial">foo[]bar</$text>xyz</paragraph>' );
 			setData( model, '<paragraph>abc<$text fontFamily="arial">foo[]bar</$text>xyz</paragraph>' );
 
 
-			expect( command.value ).to.be.true;
+			expect( command.value ).to.equal( 'arial' );
 
 
-			command.execute();
+			command.execute( { fontFamily: 'arial' } );
 
 
 			expect( getData( model ) ).to.equal( '<paragraph>abc<$text fontFamily="arial">foo[]bar</$text>xyz</paragraph>' );
 			expect( getData( model ) ).to.equal( '<paragraph>abc<$text fontFamily="arial">foo[]bar</$text>xyz</paragraph>' );
 
 
-			expect( command.value ).to.be.true;
+			expect( command.value ).to.equal( 'arial' );
+		} );
+
+		it( 'should remove fontFamily attribute on selected nodes when passing undefined fontFamily param', () => {
+			setData(
+				model,
+				'<paragraph>abcabc[<$text fontFamily="arial">abc</$text></paragraph>' +
+				'<paragraph><$text fontFamily="arial">foofoofoo</$text></paragraph>' +
+				'<paragraph><$text fontFamily="arial">barbar</$text>]bar</paragraph>'
+			);
+			expect( command.value ).to.equal( 'arial' );
+
+			command.execute();
+
+			expect( command.value ).to.be.undefined;
+
+			expect( getData( model ) ).to.equal(
+				'<paragraph>abcabc[abc</paragraph>' +
+				'<paragraph>foofoofoo</paragraph>' +
+				'<paragraph>barbar]bar</paragraph>'
+			);
 		} );
 		} );
 	} );
 	} );
 } );
 } );

+ 10 - 9
packages/ckeditor5-font/tests/fontfamily/fontfamilyediting.js

@@ -38,6 +38,7 @@ describe( 'FontFamilyEditing', () => {
 		describe( 'default value', () => {
 		describe( 'default value', () => {
 			it( 'should be set', () => {
 			it( 'should be set', () => {
 				expect( editor.config.get( 'fontFamily.items' ) ).to.deep.equal( [
 				expect( editor.config.get( 'fontFamily.items' ) ).to.deep.equal( [
+					'default',
 					'Arial, Helvetica, sans-serif',
 					'Arial, Helvetica, sans-serif',
 					'Courier New, Courier, monospace',
 					'Courier New, Courier, monospace',
 					'Georgia, serif',
 					'Georgia, serif',
@@ -76,7 +77,7 @@ describe( 'FontFamilyEditing', () => {
 					fontFamily: {
 					fontFamily: {
 						items: [
 						items: [
 							{
 							{
-								label: 'Comic Sans',
+								title: 'Comic Sans',
 								model: 'comic',
 								model: 'comic',
 								view: {
 								view: {
 									name: 'span',
 									name: 'span',
@@ -95,7 +96,7 @@ describe( 'FontFamilyEditing', () => {
 
 
 					expect( plugin.configuredItems ).to.deep.equal( [
 					expect( plugin.configuredItems ).to.deep.equal( [
 						{
 						{
-							label: 'Comic Sans',
+							title: 'Comic Sans',
 							model: 'comic',
 							model: 'comic',
 							view: {
 							view: {
 								name: 'span',
 								name: 'span',
@@ -128,7 +129,7 @@ describe( 'FontFamilyEditing', () => {
 
 
 						expect( plugin.configuredItems ).to.deep.equal( [
 						expect( plugin.configuredItems ).to.deep.equal( [
 							{
 							{
-								label: 'Arial',
+								title: 'Arial',
 								model: 'Arial',
 								model: 'Arial',
 								view: {
 								view: {
 									name: 'span',
 									name: 'span',
@@ -146,7 +147,7 @@ describe( 'FontFamilyEditing', () => {
 								]
 								]
 							},
 							},
 							{
 							{
-								label: 'Comic Sans MS',
+								title: 'Comic Sans MS',
 								model: 'Comic Sans MS',
 								model: 'Comic Sans MS',
 								view: {
 								view: {
 									name: 'span',
 									name: 'span',
@@ -167,7 +168,7 @@ describe( 'FontFamilyEditing', () => {
 								]
 								]
 							},
 							},
 							{
 							{
-								label: 'Lucida Console',
+								title: 'Lucida Console',
 								model: 'Lucida Console',
 								model: 'Lucida Console',
 								view: {
 								view: {
 									name: 'span',
 									name: 'span',
@@ -205,7 +206,7 @@ describe( 'FontFamilyEditing', () => {
 							'Arial',
 							'Arial',
 							'Lucida Sans Unicode, Lucida Grande, sans-serif',
 							'Lucida Sans Unicode, Lucida Grande, sans-serif',
 							{
 							{
-								label: 'My font',
+								title: 'My font',
 								model: 'my',
 								model: 'my',
 								view: {
 								view: {
 									name: 'mark',
 									name: 'mark',
@@ -257,7 +258,7 @@ describe( 'FontFamilyEditing', () => {
 						items: [
 						items: [
 							'Lucida Sans Unicode, Lucida Grande, sans-serif',
 							'Lucida Sans Unicode, Lucida Grande, sans-serif',
 							{
 							{
-								label: 'My other setting',
+								title: 'My other setting',
 								model: 'my-other',
 								model: 'my-other',
 								view: {
 								view: {
 									name: 'span',
 									name: 'span',
@@ -265,7 +266,7 @@ describe( 'FontFamilyEditing', () => {
 								}
 								}
 							},
 							},
 							{
 							{
-								label: 'My setting',
+								title: 'My setting',
 								model: 'my',
 								model: 'my',
 								view: {
 								view: {
 									name: 'mark',
 									name: 'mark',
@@ -274,7 +275,7 @@ describe( 'FontFamilyEditing', () => {
 								}
 								}
 							},
 							},
 							{
 							{
-								label: 'Hybrid',
+								title: 'Hybrid',
 								model: 'complex',
 								model: 'complex',
 								view: {
 								view: {
 									name: 'span',
 									name: 'span',

+ 44 - 24
packages/ckeditor5-font/tests/fontsize/fontsizecommand.js

@@ -18,7 +18,7 @@ describe( 'FontSizeCommand', () => {
 				editor = newEditor;
 				editor = newEditor;
 				model = editor.model;
 				model = editor.model;
 
 
-				command = new FontSizeCommand( editor, 'text-huge' );
+				command = new FontSizeCommand( editor );
 				editor.commands.add( 'fontSize', command );
 				editor.commands.add( 'fontSize', command );
 
 
 				model.schema.registerItem( 'paragraph', '$block' );
 				model.schema.registerItem( 'paragraph', '$block' );
@@ -36,16 +36,16 @@ describe( 'FontSizeCommand', () => {
 	} );
 	} );
 
 
 	describe( 'value', () => {
 	describe( 'value', () => {
-		it( 'is set to true when selection is in text with fontSize attribute', () => {
-			setData( model, '<paragraph><$text fontSize="text-huge">fo[]o</$text></paragraph>' );
+		it( 'is set to fontSize value when selection is in text with fontSize attribute', () => {
+			setData( model, '<paragraph><$text fontSize="huge">fo[]o</$text></paragraph>' );
 
 
-			expect( command ).to.have.property( 'value', true );
+			expect( command ).to.have.property( 'value', 'huge' );
 		} );
 		} );
 
 
 		it( 'is undefined when selection is not in text with fontSize attribute', () => {
 		it( 'is undefined when selection is not in text with fontSize attribute', () => {
 			setData( model, '<paragraph>fo[]o</paragraph>' );
 			setData( model, '<paragraph>fo[]o</paragraph>' );
 
 
-			expect( command ).to.have.property( 'value', false );
+			expect( command ).to.have.property( 'value', undefined );
 		} );
 		} );
 	} );
 	} );
 
 
@@ -59,15 +59,15 @@ describe( 'FontSizeCommand', () => {
 
 
 	describe( 'execute()', () => {
 	describe( 'execute()', () => {
 		it( 'should add fontSize attribute on selected text', () => {
 		it( 'should add fontSize attribute on selected text', () => {
-			setData( model, '<paragraph>a[bc<$text fontSize="text-huge">fo]obar</$text>xyz</paragraph>' );
+			setData( model, '<paragraph>a[bc<$text fontSize="huge">fo]obar</$text>xyz</paragraph>' );
 
 
-			expect( command.value ).to.be.false;
+			expect( command.value ).to.be.undefined;
 
 
-			command.execute();
+			command.execute( { fontSize: 'huge' } );
 
 
-			expect( command.value ).to.be.true;
+			expect( command.value ).to.equal( 'huge' );
 
 
-			expect( getData( model ) ).to.equal( '<paragraph>a[<$text fontSize="text-huge">bcfo]obar</$text>xyz</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>a[<$text fontSize="huge">bcfo]obar</$text>xyz</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should add fontSize attribute on selected nodes (multiple nodes)', () => {
 		it( 'should add fontSize attribute on selected nodes (multiple nodes)', () => {
@@ -78,14 +78,14 @@ describe( 'FontSizeCommand', () => {
 				'<paragraph>barbar]bar</paragraph>'
 				'<paragraph>barbar]bar</paragraph>'
 			);
 			);
 
 
-			command.execute();
+			command.execute( { fontSize: 'huge' } );
 
 
-			expect( command.value ).to.be.true;
+			expect( command.value ).to.equal( 'huge' );
 
 
 			expect( getData( model ) ).to.equal(
 			expect( getData( model ) ).to.equal(
-				'<paragraph>abcabc[<$text fontSize="text-huge">abc</$text></paragraph>' +
-				'<paragraph><$text fontSize="text-huge">foofoofoo</$text></paragraph>' +
-				'<paragraph><$text fontSize="text-huge">barbar</$text>]bar</paragraph>'
+				'<paragraph>abcabc[<$text fontSize="huge">abc</$text></paragraph>' +
+				'<paragraph><$text fontSize="huge">foofoofoo</$text></paragraph>' +
+				'<paragraph><$text fontSize="huge">barbar</$text>]bar</paragraph>'
 			);
 			);
 		} );
 		} );
 
 
@@ -97,27 +97,47 @@ describe( 'FontSizeCommand', () => {
 				'<paragraph><$text fontSize="text-small">bar]bar</$text>bar</paragraph>'
 				'<paragraph><$text fontSize="text-small">bar]bar</$text>bar</paragraph>'
 			);
 			);
 
 
-			command.execute();
+			command.execute( { fontSize: 'huge' } );
 
 
-			expect( command.value ).to.be.true;
+			expect( command.value ).to.equal( 'huge' );
 
 
 			expect( getData( model ) ).to.equal(
 			expect( getData( model ) ).to.equal(
-				'<paragraph>abc[<$text fontSize="text-huge">abcabc</$text></paragraph>' +
-				'<paragraph><$text fontSize="text-huge">foofoofoo</$text></paragraph>' +
-				'<paragraph><$text fontSize="text-huge">bar</$text>]<$text fontSize="text-small">bar</$text>bar</paragraph>'
+				'<paragraph>abc[<$text fontSize="huge">abcabc</$text></paragraph>' +
+				'<paragraph><$text fontSize="huge">foofoofoo</$text></paragraph>' +
+				'<paragraph><$text fontSize="huge">bar</$text>]<$text fontSize="text-small">bar</$text>bar</paragraph>'
 			);
 			);
 		} );
 		} );
 
 
 		it( 'should do nothing on collapsed range', () => {
 		it( 'should do nothing on collapsed range', () => {
-			setData( model, '<paragraph>abc<$text fontSize="text-huge">foo[]bar</$text>xyz</paragraph>' );
+			setData( model, '<paragraph>abc<$text fontSize="huge">foo[]bar</$text>xyz</paragraph>' );
 
 
-			expect( command.value ).to.be.true;
+			expect( command.value ).to.equal( 'huge' );
 
 
 			command.execute();
 			command.execute();
 
 
-			expect( getData( model ) ).to.equal( '<paragraph>abc<$text fontSize="text-huge">foo[]bar</$text>xyz</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>abc<$text fontSize="huge">foo[]bar</$text>xyz</paragraph>' );
+
+			expect( command.value ).to.equal( 'huge' );
+		} );
+
+		it( 'should remove fontSize attribute on selected nodes when passing undefined fontSize param', () => {
+			setData(
+				model,
+				'<paragraph>abcabc[<$text fontSize="huge">abc</$text></paragraph>' +
+				'<paragraph><$text fontSize="huge">foofoofoo</$text></paragraph>' +
+				'<paragraph><$text fontSize="huge">barbar</$text>]bar</paragraph>'
+			);
+			expect( command.value ).to.equal( 'huge' );
 
 
-			expect( command.value ).to.be.true;
+			command.execute();
+
+			expect( command.value ).to.be.undefined;
+
+			expect( getData( model ) ).to.equal(
+				'<paragraph>abcabc[abc</paragraph>' +
+				'<paragraph>foofoofoo</paragraph>' +
+				'<paragraph>barbar]bar</paragraph>'
+			);
 		} );
 		} );
 	} );
 	} );
 } );
 } );