Преглед изворни кода

Tests: Added `describe` to better group tests so they are easier to find using tests log.

Szymon Cofalik пре 6 година
родитељ
комит
2437f4444a

+ 56 - 54
packages/ckeditor5-paste-from-office/tests/data/integration.js

@@ -22,62 +22,64 @@ import { generateTests } from '../_utils/utils';
 
 const browsers = [ 'chrome', 'firefox', 'safari', 'edge' ];
 
-generateTests( {
-	input: 'basic-styles',
-	type: 'integration',
-	browsers,
-	editorConfig: {
-		plugins: [ Clipboard, Paragraph, Heading, Bold, Italic, Underline, Strikethrough, PasteFromOffice ]
-	},
-	skip: {
-		safari: [ 'italicStartingText', 'multipleStylesSingleLine', 'multipleStylesMultiline' ] // Skip due to spacing issue (#13).
-	}
-} );
+describe( 'Paste from Office', () => {
+	generateTests( {
+		input: 'basic-styles',
+		type: 'integration',
+		browsers,
+		editorConfig: {
+			plugins: [ Clipboard, Paragraph, Heading, Bold, Italic, Underline, Strikethrough, PasteFromOffice ]
+		},
+		skip: {
+			safari: [ 'italicStartingText', 'multipleStylesSingleLine', 'multipleStylesMultiline' ] // Skip due to spacing issue (#13).
+		}
+	} );
 
-generateTests( {
-	input: 'image',
-	type: 'integration',
-	browsers,
-	editorConfig: {
-		plugins: [ Clipboard, Paragraph, Image, Table, PasteFromOffice ]
-	},
-	skip: {
-		chrome: ( env.isEdge ? [ 'adjacentGroups' ] : [] ),
-		firefox: ( env.isEdge ? [ 'adjacentGroups' ] : [] ),
-		safari: ( env.isEdge ? [ 'adjacentGroups' ] : [] ),
-		edge: ( env.isEdge ? [] : [ 'adjacentGroups' ] )
-	}
-} );
+	generateTests( {
+		input: 'image',
+		type: 'integration',
+		browsers,
+		editorConfig: {
+			plugins: [ Clipboard, Paragraph, Image, Table, PasteFromOffice ]
+		},
+		skip: {
+			chrome: ( env.isEdge ? [ 'adjacentGroups' ] : [] ),
+			firefox: ( env.isEdge ? [ 'adjacentGroups' ] : [] ),
+			safari: ( env.isEdge ? [ 'adjacentGroups' ] : [] ),
+			edge: ( env.isEdge ? [] : [ 'adjacentGroups' ] )
+		}
+	} );
 
-generateTests( {
-	input: 'link',
-	type: 'integration',
-	browsers,
-	editorConfig: {
-		plugins: [ Clipboard, Paragraph, Heading, Bold, Link, ShiftEnter, PasteFromOffice ]
-	},
-	skip: {
-		safari: [ 'combined' ] // Skip due to spacing issue (#13).
-	}
-} );
+	generateTests( {
+		input: 'link',
+		type: 'integration',
+		browsers,
+		editorConfig: {
+			plugins: [ Clipboard, Paragraph, Heading, Bold, Link, ShiftEnter, PasteFromOffice ]
+		},
+		skip: {
+			safari: [ 'combined' ] // Skip due to spacing issue (#13).
+		}
+	} );
 
-generateTests( {
-	input: 'list',
-	type: 'integration',
-	browsers,
-	editorConfig: {
-		plugins: [ Clipboard, Paragraph, Heading, Bold, Italic, Underline, Link, List, PasteFromOffice ]
-	},
-	skip: {
-		safari: [ 'heading3Styled' ] // Skip due to spacing issue (#13).
-	}
-} );
+	generateTests( {
+		input: 'list',
+		type: 'integration',
+		browsers,
+		editorConfig: {
+			plugins: [ Clipboard, Paragraph, Heading, Bold, Italic, Underline, Link, List, PasteFromOffice ]
+		},
+		skip: {
+			safari: [ 'heading3Styled' ] // Skip due to spacing issue (#13).
+		}
+	} );
 
-generateTests( {
-	input: 'spacing',
-	type: 'integration',
-	browsers,
-	editorConfig: {
-		plugins: [ Clipboard, Paragraph, Bold, Italic, Underline, PasteFromOffice ]
-	}
+	generateTests( {
+		input: 'spacing',
+		type: 'integration',
+		browsers,
+		editorConfig: {
+			plugins: [ Clipboard, Paragraph, Bold, Italic, Underline, PasteFromOffice ]
+		}
+	} );
 } );

+ 35 - 33
packages/ckeditor5-paste-from-office/tests/data/normalization.js

@@ -14,37 +14,39 @@ const editorConfig = {
 	plugins: [ Clipboard, PasteFromOffice ]
 };
 
-generateTests( {
-	input: 'basic-styles',
-	type: 'normalization',
-	browsers,
-	editorConfig
-} );
-
-generateTests( {
-	input: 'image',
-	type: 'normalization',
-	browsers,
-	editorConfig
-} );
-
-generateTests( {
-	input: 'link',
-	type: 'normalization',
-	browsers,
-	editorConfig
-} );
-
-generateTests( {
-	input: 'list',
-	type: 'normalization',
-	browsers,
-	editorConfig
-} );
-
-generateTests( {
-	input: 'spacing',
-	type: 'normalization',
-	browsers,
-	editorConfig
+describe( 'Paste from Office', () => {
+	generateTests( {
+		input: 'basic-styles',
+		type: 'normalization',
+		browsers,
+		editorConfig
+	} );
+
+	generateTests( {
+		input: 'image',
+		type: 'normalization',
+		browsers,
+		editorConfig
+	} );
+
+	generateTests( {
+		input: 'link',
+		type: 'normalization',
+		browsers,
+		editorConfig
+	} );
+
+	generateTests( {
+		input: 'list',
+		type: 'normalization',
+		browsers,
+		editorConfig
+	} );
+
+	generateTests( {
+		input: 'spacing',
+		type: 'normalization',
+		browsers,
+		editorConfig
+	} );
 } );

+ 77 - 75
packages/ckeditor5-paste-from-office/tests/filters/image.js

@@ -12,96 +12,98 @@ import { parseHtml } from '../../src/filters/parse';
 import { replaceImagesSourceWithBase64, _convertHexToBase64 } from '../../src/filters/image';
 import { browserFixtures } from '../_data/image/index';
 
-describe( 'Filters', () => {
-	describe( 'image', () => {
-		let editor;
-
-		describe( 'replaceImagesSourceWithBase64()', () => {
-			describe( 'with RTF', () => {
-				beforeEach( () => {
-					return VirtualTestEditor
-						.create( {} )
-						.then( editorInstance => {
-							editor = editorInstance;
-						} );
+describe( 'Paste from Office', () => {
+	describe( 'Filters', () => {
+		describe( 'image', () => {
+			let editor;
+
+			describe( 'replaceImagesSourceWithBase64()', () => {
+				describe( 'with RTF', () => {
+					beforeEach( () => {
+						return VirtualTestEditor
+							.create( {} )
+							.then( editorInstance => {
+								editor = editorInstance;
+							} );
+					} );
+
+					afterEach( () => {
+						editor.destroy();
+					} );
+
+					it( 'should handle correctly empty RTF data', () => {
+						const input = '<p>Foo <img src="file://test.jpg" /></p>';
+						const rtfString = '';
+						const { body } = parseHtml( input );
+
+						replaceImagesSourceWithBase64( body, rtfString, editor.editing.model );
+
+						expect( stringifyView( body ) ).to.equal( normalizeHtml( input ) );
+					} );
+
+					it( 'should not change image with "http://" source', () => {
+						const input = '<p>Foo <img src="http://ckeditor.com/logo.jpg" /></p>';
+						const rtfString = browserFixtures.chrome.inputRtf.onlineOffline;
+						const { body } = parseHtml( input );
+
+						replaceImagesSourceWithBase64( body, rtfString, editor.editing.model );
+
+						expect( stringifyView( body ) ).to.equal( normalizeHtml( input ) );
+					} );
+
+					it( 'should not change image with "file://" source if not images in RTF data', () => {
+						const input = '<p>Foo <img src="file://test.jpg" /></p>';
+						const rtfString = '{\\rtf1\\adeflang1025\\ansi\\ansicpg1252\\uc1\\adeff31507}';
+						const { body } = parseHtml( input );
+
+						replaceImagesSourceWithBase64( body, rtfString, editor.editing.model );
+
+						expect( stringifyView( body ) ).to.equal( normalizeHtml( input ) );
+					} );
 				} );
+			} );
 
-				afterEach( () => {
-					editor.destroy();
-				} );
-
-				it( 'should handle correctly empty RTF data', () => {
-					const input = '<p>Foo <img src="file://test.jpg" /></p>';
-					const rtfString = '';
-					const { body } = parseHtml( input );
-
-					replaceImagesSourceWithBase64( body, rtfString, editor.editing.model );
+			describe( '_convertHexToBase64()', () => {
+				it( '#1', () => {
+					const hex = '48656c6c6f20576f726c6421';
+					const base64 = 'SGVsbG8gV29ybGQh';
 
-					expect( stringifyView( body ) ).to.equal( normalizeHtml( input ) );
+					expect( _convertHexToBase64( hex ) ).to.equal( base64 );
 				} );
 
-				it( 'should not change image with "http://" source', () => {
-					const input = '<p>Foo <img src="http://ckeditor.com/logo.jpg" /></p>';
-					const rtfString = browserFixtures.chrome.inputRtf.onlineOffline;
-					const { body } = parseHtml( input );
-
-					replaceImagesSourceWithBase64( body, rtfString, editor.editing.model );
+				it( '#2', () => {
+					const hex = '466f6f204261722042617a';
+					const base64 = 'Rm9vIEJhciBCYXo=';
 
-					expect( stringifyView( body ) ).to.equal( normalizeHtml( input ) );
+					expect( _convertHexToBase64( hex ) ).to.equal( base64 );
 				} );
 
-				it( 'should not change image with "file://" source if not images in RTF data', () => {
-					const input = '<p>Foo <img src="file://test.jpg" /></p>';
-					const rtfString = '{\\rtf1\\adeflang1025\\ansi\\ansicpg1252\\uc1\\adeff31507}';
-					const { body } = parseHtml( input );
+				it( '#3', () => {
+					const hex = '687474703a2f2f636b656469746f722e636f6d';
+					const base64 = 'aHR0cDovL2NrZWRpdG9yLmNvbQ==';
 
-					replaceImagesSourceWithBase64( body, rtfString, editor.editing.model );
-
-					expect( stringifyView( body ) ).to.equal( normalizeHtml( input ) );
+					expect( _convertHexToBase64( hex ) ).to.equal( base64 );
 				} );
-			} );
-		} );
-
-		describe( '_convertHexToBase64()', () => {
-			it( '#1', () => {
-				const hex = '48656c6c6f20576f726c6421';
-				const base64 = 'SGVsbG8gV29ybGQh';
-
-				expect( _convertHexToBase64( hex ) ).to.equal( base64 );
-			} );
-
-			it( '#2', () => {
-				const hex = '466f6f204261722042617a';
-				const base64 = 'Rm9vIEJhciBCYXo=';
-
-				expect( _convertHexToBase64( hex ) ).to.equal( base64 );
-			} );
-
-			it( '#3', () => {
-				const hex = '687474703a2f2f636b656469746f722e636f6d';
-				const base64 = 'aHR0cDovL2NrZWRpdG9yLmNvbQ==';
 
-				expect( _convertHexToBase64( hex ) ).to.equal( base64 );
-			} );
-
-			it( '#4', () => {
-				const hex = '434B456469746F72203520697320746865206265737421';
-				const base64 = 'Q0tFZGl0b3IgNSBpcyB0aGUgYmVzdCE=';
+				it( '#4', () => {
+					const hex = '434B456469746F72203520697320746865206265737421';
+					const base64 = 'Q0tFZGl0b3IgNSBpcyB0aGUgYmVzdCE=';
 
-				expect( _convertHexToBase64( hex ) ).to.equal( base64 );
-			} );
+					expect( _convertHexToBase64( hex ) ).to.equal( base64 );
+				} );
 
-			it( '#5', () => {
-				const hex = '496E74726F6475636564204D6564696120656D6265642C20626C6F636B20636F6E74656E7420696E207461626' +
-					'C657320616E6420696E746567726174696F6E73207769746820416E67756C617220322B20616E642052656163742E2046' +
-					'696E64206F7574206D6F726520696E2074686520434B456469746F722035207631312E312E302072656C6561736564206' +
-					'26C6F6720706F73742E';
+				it( '#5', () => {
+					const hex = '496E74726F6475636564204D6564696120656D6265642C20626C6F636B20636F6E74656E7420696E207461626' +
+						'C657320616E6420696E746567726174696F6E73207769746820416E67756C617220322B20616E642052656163742E2046' +
+						'696E64206F7574206D6F726520696E2074686520434B456469746F722035207631312E312E302072656C6561736564206' +
+						'26C6F6720706F73742E';
 
-				const base64 = 'SW50cm9kdWNlZCBNZWRpYSBlbWJlZCwgYmxvY2sgY29udGVudCBpbiB0YWJsZXMgYW5kIGludGVncmF0aW9ucy' +
-					'B3aXRoIEFuZ3VsYXIgMisgYW5kIFJlYWN0LiBGaW5kIG91dCBtb3JlIGluIHRoZSBDS0VkaXRvciA1IHYxMS4xLjAgcmVsZWF' +
-					'zZWQgYmxvZyBwb3N0Lg==';
+					const base64 = 'SW50cm9kdWNlZCBNZWRpYSBlbWJlZCwgYmxvY2sgY29udGVudCBpbiB0YWJsZXMgYW5kIGludGVncmF0aW9ucy' +
+						'B3aXRoIEFuZ3VsYXIgMisgYW5kIFJlYWN0LiBGaW5kIG91dCBtb3JlIGluIHRoZSBDS0VkaXRvciA1IHYxMS4xLjAgcmVsZWF' +
+						'zZWQgYmxvZyBwb3N0Lg==';
 
-				expect( _convertHexToBase64( hex ) ).to.equal( base64 );
+					expect( _convertHexToBase64( hex ) ).to.equal( base64 );
+				} );
 			} );
 		} );
 	} );

+ 42 - 40
packages/ckeditor5-paste-from-office/tests/filters/list.js

@@ -9,61 +9,63 @@ import View from '@ckeditor/ckeditor5-engine/src/view/view';
 
 import { transformListItemLikeElementsIntoLists } from '../../src/filters/list';
 
-describe( 'Filters', () => {
-	describe( 'list', () => {
-		const htmlDataProcessor = new HtmlDataProcessor();
+describe( 'Paste from Office', () => {
+	describe( 'Filters', () => {
+		describe( 'list', () => {
+			const htmlDataProcessor = new HtmlDataProcessor();
 
-		describe( 'transformListItemLikeElementsIntoLists()', () => {
-			it( 'replaces list-like elements with semantic lists', () => {
-				const html = '<p style="mso-list:l0 level1 lfo0"><span style="mso-list:Ignore">1.</span>Item 1</p>';
-				const view = htmlDataProcessor.toView( html );
+			describe( 'transformListItemLikeElementsIntoLists()', () => {
+				it( 'replaces list-like elements with semantic lists', () => {
+					const html = '<p style="mso-list:l0 level1 lfo0"><span style="mso-list:Ignore">1.</span>Item 1</p>';
+					const view = htmlDataProcessor.toView( html );
 
-				transformListItemLikeElementsIntoLists( view, '', new View() );
+					transformListItemLikeElementsIntoLists( view, '', new View() );
 
-				expect( view.childCount ).to.equal( 1 );
-				expect( view.getChild( 0 ).name ).to.equal( 'ol' );
-				expect( stringify( view ) ).to.equal( '<ol><li style="mso-list:l0 level1 lfo0">Item 1</li></ol>' );
-			} );
+					expect( view.childCount ).to.equal( 1 );
+					expect( view.getChild( 0 ).name ).to.equal( 'ol' );
+					expect( stringify( view ) ).to.equal( '<ol><li style="mso-list:l0 level1 lfo0">Item 1</li></ol>' );
+				} );
 
-			it( 'replaces list-like elements with semantic lists with proper bullet type based on styles', () => {
-				const html = '<p style="mso-list:l0 level1 lfo0"><span style="mso-list:Ignore">1.</span>Item 1</p>';
-				const view = htmlDataProcessor.toView( html );
+				it( 'replaces list-like elements with semantic lists with proper bullet type based on styles', () => {
+					const html = '<p style="mso-list:l0 level1 lfo0"><span style="mso-list:Ignore">1.</span>Item 1</p>';
+					const view = htmlDataProcessor.toView( html );
 
-				transformListItemLikeElementsIntoLists( view, '@list l0:level1 { mso-level-number-format: bullet; }', new View() );
+					transformListItemLikeElementsIntoLists( view, '@list l0:level1 { mso-level-number-format: bullet; }', new View() );
 
-				expect( view.childCount ).to.equal( 1 );
-				expect( view.getChild( 0 ).name ).to.equal( 'ul' );
-				expect( stringify( view ) ).to.equal( '<ul><li style="mso-list:l0 level1 lfo0">Item 1</li></ul>' );
-			} );
+					expect( view.childCount ).to.equal( 1 );
+					expect( view.getChild( 0 ).name ).to.equal( 'ul' );
+					expect( stringify( view ) ).to.equal( '<ul><li style="mso-list:l0 level1 lfo0">Item 1</li></ul>' );
+				} );
 
-			it( 'does not modify the view if there are no list-like elements', () => {
-				const html = '<h1>H1</h1><p>Foo Bar</p>';
-				const view = htmlDataProcessor.toView( html );
+				it( 'does not modify the view if there are no list-like elements', () => {
+					const html = '<h1>H1</h1><p>Foo Bar</p>';
+					const view = htmlDataProcessor.toView( html );
 
-				transformListItemLikeElementsIntoLists( view, '', new View() );
+					transformListItemLikeElementsIntoLists( view, '', new View() );
 
-				expect( view.childCount ).to.equal( 2 );
-				expect( stringify( view ) ).to.equal( html );
-			} );
+					expect( view.childCount ).to.equal( 2 );
+					expect( stringify( view ) ).to.equal( html );
+				} );
 
-			it( 'handles empty `mso-list` style correctly', () => {
-				const html = '<p style="mso-list:"><span style="mso-list:Ignore">1.</span>Item 1</p>';
-				const view = htmlDataProcessor.toView( html );
+				it( 'handles empty `mso-list` style correctly', () => {
+					const html = '<p style="mso-list:"><span style="mso-list:Ignore">1.</span>Item 1</p>';
+					const view = htmlDataProcessor.toView( html );
 
-				transformListItemLikeElementsIntoLists( view, '', new View() );
+					transformListItemLikeElementsIntoLists( view, '', new View() );
 
-				expect( view.childCount ).to.equal( 1 );
-				expect( view.getChild( 0 ).name ).to.equal( 'ol' );
-				expect( stringify( view ) ).to.equal( '<ol><li style="mso-list:">Item 1</li></ol>' );
-			} );
+					expect( view.childCount ).to.equal( 1 );
+					expect( view.getChild( 0 ).name ).to.equal( 'ol' );
+					expect( stringify( view ) ).to.equal( '<ol><li style="mso-list:">Item 1</li></ol>' );
+				} );
 
-			it( 'handles empty body correctly', () => {
-				const view = htmlDataProcessor.toView( '' );
+				it( 'handles empty body correctly', () => {
+					const view = htmlDataProcessor.toView( '' );
 
-				transformListItemLikeElementsIntoLists( view, '', new View() );
+					transformListItemLikeElementsIntoLists( view, '', new View() );
 
-				expect( view.childCount ).to.equal( 0 );
-				expect( stringify( view ) ).to.equal( '' );
+					expect( view.childCount ).to.equal( 0 );
+					expect( stringify( view ) ).to.equal( '' );
+				} );
 			} );
 		} );
 	} );

+ 104 - 102
packages/ckeditor5-paste-from-office/tests/filters/parse.js

@@ -9,157 +9,159 @@ import DocumentFragment from '@ckeditor/ckeditor5-engine/src/view/documentfragme
 
 import { parseHtml } from '../../src/filters/parse';
 
-describe( 'Filters', () => {
-	describe( 'parse', () => {
-		describe( 'parseHtml()', () => {
-			it( 'correctly parses HTML with body and one style tag', () => {
-				const html = '<head><style>p { color: red; } a { font-size: 12px; }</style></head><body><p>Foo Bar</p></body>';
-				const { body, bodyString, styles, stylesString } = parseHtml( html );
+describe( 'Paste from Office', () => {
+	describe( 'Filters', () => {
+		describe( 'parse', () => {
+			describe( 'parseHtml()', () => {
+				it( 'correctly parses HTML with body and one style tag', () => {
+					const html = '<head><style>p { color: red; } a { font-size: 12px; }</style></head><body><p>Foo Bar</p></body>';
+					const { body, bodyString, styles, stylesString } = parseHtml( html );
 
-				expect( body ).to.instanceof( DocumentFragment );
-				expect( body.childCount ).to.equal( 1, 'body.childCount' );
+					expect( body ).to.instanceof( DocumentFragment );
+					expect( body.childCount ).to.equal( 1, 'body.childCount' );
 
-				expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
+					expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
 
-				expect( styles.length ).to.equal( 1, 'styles.length' );
-				expect( styles[ 0 ] ).to.instanceof( CSSStyleSheet );
-				expect( styles[ 0 ].cssRules.length ).to.equal( 2 );
-				expect( styles[ 0 ].cssRules[ 0 ].style.color ).to.equal( 'red' );
-				expect( styles[ 0 ].cssRules[ 1 ].style[ 'font-size' ] ).to.equal( '12px' );
+					expect( styles.length ).to.equal( 1, 'styles.length' );
+					expect( styles[ 0 ] ).to.instanceof( CSSStyleSheet );
+					expect( styles[ 0 ].cssRules.length ).to.equal( 2 );
+					expect( styles[ 0 ].cssRules[ 0 ].style.color ).to.equal( 'red' );
+					expect( styles[ 0 ].cssRules[ 1 ].style[ 'font-size' ] ).to.equal( '12px' );
 
-				expect( stylesString ).to.equal( 'p { color: red; } a { font-size: 12px; }' );
-			} );
+					expect( stylesString ).to.equal( 'p { color: red; } a { font-size: 12px; }' );
+				} );
 
-			it( 'correctly parses HTML with body contents only', () => {
-				const html = '<p>Foo Bar</p>';
-				const { body, bodyString, styles, stylesString } = parseHtml( html );
+				it( 'correctly parses HTML with body contents only', () => {
+					const html = '<p>Foo Bar</p>';
+					const { body, bodyString, styles, stylesString } = parseHtml( html );
 
-				expect( body ).to.instanceof( DocumentFragment );
-				expect( body.childCount ).to.equal( 1 );
+					expect( body ).to.instanceof( DocumentFragment );
+					expect( body.childCount ).to.equal( 1 );
 
-				expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
+					expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
 
-				expect( styles.length ).to.equal( 0 );
+					expect( styles.length ).to.equal( 0 );
 
-				expect( stylesString ).to.equal( '' );
-			} );
+					expect( stylesString ).to.equal( '' );
+				} );
 
-			it( 'correctly parses HTML with no body and multiple style tags', () => {
-				const html = '<html><head><style>p { color: blue; }</style><style>a { color: green; }</style></head></html>';
-				const { body, bodyString, styles, stylesString } = parseHtml( html );
+				it( 'correctly parses HTML with no body and multiple style tags', () => {
+					const html = '<html><head><style>p { color: blue; }</style><style>a { color: green; }</style></head></html>';
+					const { body, bodyString, styles, stylesString } = parseHtml( html );
 
-				expect( body ).to.instanceof( DocumentFragment );
-				expect( body.childCount ).to.equal( 0 );
+					expect( body ).to.instanceof( DocumentFragment );
+					expect( body.childCount ).to.equal( 0 );
 
-				expect( bodyString ).to.equal( '' );
+					expect( bodyString ).to.equal( '' );
 
-				expect( styles.length ).to.equal( 2 );
-				expect( styles[ 0 ] ).to.instanceof( CSSStyleSheet );
-				expect( styles[ 1 ] ).to.instanceof( CSSStyleSheet );
-				expect( styles[ 0 ].cssRules.length ).to.equal( 1 );
-				expect( styles[ 1 ].cssRules.length ).to.equal( 1 );
-				expect( styles[ 0 ].cssRules[ 0 ].style.color ).to.equal( 'blue' );
-				expect( styles[ 1 ].cssRules[ 0 ].style.color ).to.equal( 'green' );
+					expect( styles.length ).to.equal( 2 );
+					expect( styles[ 0 ] ).to.instanceof( CSSStyleSheet );
+					expect( styles[ 1 ] ).to.instanceof( CSSStyleSheet );
+					expect( styles[ 0 ].cssRules.length ).to.equal( 1 );
+					expect( styles[ 1 ].cssRules.length ).to.equal( 1 );
+					expect( styles[ 0 ].cssRules[ 0 ].style.color ).to.equal( 'blue' );
+					expect( styles[ 1 ].cssRules[ 0 ].style.color ).to.equal( 'green' );
 
-				expect( stylesString ).to.equal( 'p { color: blue; } a { color: green; }' );
-			} );
+					expect( stylesString ).to.equal( 'p { color: blue; } a { color: green; }' );
+				} );
 
-			it( 'correctly parses HTML with no body and no style tags', () => {
-				const html = '<html><head><meta name="Foo" content="Bar"></head></html>';
-				const { body, bodyString, styles, stylesString } = parseHtml( html );
+				it( 'correctly parses HTML with no body and no style tags', () => {
+					const html = '<html><head><meta name="Foo" content="Bar"></head></html>';
+					const { body, bodyString, styles, stylesString } = parseHtml( html );
 
-				expect( body ).to.instanceof( DocumentFragment );
-				expect( body.childCount ).to.equal( 0 );
+					expect( body ).to.instanceof( DocumentFragment );
+					expect( body.childCount ).to.equal( 0 );
 
-				expect( bodyString ).to.equal( '' );
+					expect( bodyString ).to.equal( '' );
 
-				expect( styles.length ).to.equal( 0 );
+					expect( styles.length ).to.equal( 0 );
 
-				expect( stylesString ).to.equal( '' );
-			} );
+					expect( stylesString ).to.equal( '' );
+				} );
 
-			it( 'correctly parses HTML with body contents and empty style tag', () => {
-				const html = '<head><style></style></head><body><p>Foo Bar</p></body>';
-				const { body, bodyString, styles, stylesString } = parseHtml( html );
+				it( 'correctly parses HTML with body contents and empty style tag', () => {
+					const html = '<head><style></style></head><body><p>Foo Bar</p></body>';
+					const { body, bodyString, styles, stylesString } = parseHtml( html );
 
-				expect( body ).to.instanceof( DocumentFragment );
-				expect( body.childCount ).to.equal( 1 );
+					expect( body ).to.instanceof( DocumentFragment );
+					expect( body.childCount ).to.equal( 1 );
 
-				expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
+					expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
 
-				expect( styles.length ).to.equal( 0 );
+					expect( styles.length ).to.equal( 0 );
 
-				expect( stylesString ).to.equal( '' );
-			} );
+					expect( stylesString ).to.equal( '' );
+				} );
 
-			it( 'should remove any content after body closing tag - plain', () => {
-				const html = '<html><head></head><body><p>Foo Bar</p></body>Ba</html>';
-				const { body, bodyString, styles, stylesString } = parseHtml( html );
+				it( 'should remove any content after body closing tag - plain', () => {
+					const html = '<html><head></head><body><p>Foo Bar</p></body>Ba</html>';
+					const { body, bodyString, styles, stylesString } = parseHtml( html );
 
-				expect( body ).to.instanceof( DocumentFragment );
-				expect( body.childCount ).to.equal( 1, 'body.childCount' );
+					expect( body ).to.instanceof( DocumentFragment );
+					expect( body.childCount ).to.equal( 1, 'body.childCount' );
 
-				expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
+					expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
 
-				expect( styles.length ).to.equal( 0 );
+					expect( styles.length ).to.equal( 0 );
 
-				expect( stylesString ).to.equal( '' );
-			} );
+					expect( stylesString ).to.equal( '' );
+				} );
 
-			it( 'should remove any content after body closing tag - inline', () => {
-				const html = '<html><head></head><body><p>Foo Bar</p></body><span>Fo</span></html>';
-				const { body, bodyString, styles, stylesString } = parseHtml( html );
+				it( 'should remove any content after body closing tag - inline', () => {
+					const html = '<html><head></head><body><p>Foo Bar</p></body><span>Fo</span></html>';
+					const { body, bodyString, styles, stylesString } = parseHtml( html );
 
-				expect( body ).to.instanceof( DocumentFragment );
-				expect( body.childCount ).to.equal( 1, 'body.childCount' );
+					expect( body ).to.instanceof( DocumentFragment );
+					expect( body.childCount ).to.equal( 1, 'body.childCount' );
 
-				expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
+					expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
 
-				expect( styles.length ).to.equal( 0 );
+					expect( styles.length ).to.equal( 0 );
 
-				expect( stylesString ).to.equal( '' );
-			} );
+					expect( stylesString ).to.equal( '' );
+				} );
 
-			it( 'should remove any content after body closing tag - block', () => {
-				const html = '<html><head></head><body><p>Foo Bar</p></body><p>ar</p></html>';
-				const { body, bodyString, styles, stylesString } = parseHtml( html );
+				it( 'should remove any content after body closing tag - block', () => {
+					const html = '<html><head></head><body><p>Foo Bar</p></body><p>ar</p></html>';
+					const { body, bodyString, styles, stylesString } = parseHtml( html );
 
-				expect( body ).to.instanceof( DocumentFragment );
-				expect( body.childCount ).to.equal( 1, 'body.childCount' );
+					expect( body ).to.instanceof( DocumentFragment );
+					expect( body.childCount ).to.equal( 1, 'body.childCount' );
 
-				expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
+					expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
 
-				expect( styles.length ).to.equal( 0 );
+					expect( styles.length ).to.equal( 0 );
 
-				expect( stylesString ).to.equal( '' );
-			} );
+					expect( stylesString ).to.equal( '' );
+				} );
 
-			it( 'should remove any content after body closing tag - no html tag', () => {
-				const html = '<head></head><body><p>Foo Bar</p></body>oo';
-				const { body, bodyString, styles, stylesString } = parseHtml( html );
+				it( 'should remove any content after body closing tag - no html tag', () => {
+					const html = '<head></head><body><p>Foo Bar</p></body>oo';
+					const { body, bodyString, styles, stylesString } = parseHtml( html );
 
-				expect( body ).to.instanceof( DocumentFragment );
-				expect( body.childCount ).to.equal( 1, 'body.childCount' );
+					expect( body ).to.instanceof( DocumentFragment );
+					expect( body.childCount ).to.equal( 1, 'body.childCount' );
 
-				expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
+					expect( bodyString ).to.equal( '<p>Foo Bar</p>' );
 
-				expect( styles.length ).to.equal( 0 );
+					expect( styles.length ).to.equal( 0 );
 
-				expect( stylesString ).to.equal( '' );
-			} );
+					expect( stylesString ).to.equal( '' );
+				} );
 
-			it( 'should not remove any content if no body tag', () => {
-				const html = '<p>Foo Bar</p>Baz';
-				const { body, bodyString, styles, stylesString } = parseHtml( html );
+				it( 'should not remove any content if no body tag', () => {
+					const html = '<p>Foo Bar</p>Baz';
+					const { body, bodyString, styles, stylesString } = parseHtml( html );
 
-				expect( body ).to.instanceof( DocumentFragment );
-				expect( body.childCount ).to.equal( 2, 'body.childCount' );
+					expect( body ).to.instanceof( DocumentFragment );
+					expect( body.childCount ).to.equal( 2, 'body.childCount' );
 
-				expect( bodyString ).to.equal( '<p>Foo Bar</p>Baz' );
+					expect( bodyString ).to.equal( '<p>Foo Bar</p>Baz' );
 
-				expect( styles.length ).to.equal( 0 );
+					expect( styles.length ).to.equal( 0 );
 
-				expect( stylesString ).to.equal( '' );
+					expect( stylesString ).to.equal( '' );
+				} );
 			} );
 		} );
 	} );

+ 67 - 64
packages/ckeditor5-paste-from-office/tests/filters/space.js

@@ -6,97 +6,100 @@
 /* globals DOMParser */
 
 import { normalizeSpacing, normalizeSpacerunSpans } from '../../src/filters/space';
+describe( 'Paste from Office', () => {
+	describe( 'Filters', () => {
+		describe( 'space', () => {
+			describe( 'normalizeSpacing()', () => {
+				it( 'should replace last space before closing tag with NBSP', () => {
+					const input = '<p>Foo </p><p><span> Bar  </span> Baz </p>';
+					const expected = '<p>Foo\u00A0</p><p><span> Bar \u00A0</span> Baz\u00A0</p>';
 
-describe( 'Filters', () => {
-	describe( 'space', () => {
-		describe( 'normalizeSpacing()', () => {
-			it( 'should replace last space before closing tag with NBSP', () => {
-				const input = '<p>Foo </p><p><span> Bar  </span> Baz </p>';
-				const expected = '<p>Foo\u00A0</p><p><span> Bar \u00A0</span> Baz\u00A0</p>';
+					expect( normalizeSpacing( input ) ).to.equal( expected );
+				} );
 
-				expect( normalizeSpacing( input ) ).to.equal( expected );
-			} );
+				it( 'should replace last space before special "o:p" tag with NBSP', () => {
+					const input = '<p>Foo  <o:p></o:p><span> <o:p></o:p> Bar</span></p>';
+					const expected = '<p>Foo \u00A0<o:p></o:p><span>\u00A0<o:p></o:p> Bar</span></p>';
 
-			it( 'should replace last space before special "o:p" tag with NBSP', () => {
-				const input = '<p>Foo  <o:p></o:p><span> <o:p></o:p> Bar</span></p>';
-				const expected = '<p>Foo \u00A0<o:p></o:p><span>\u00A0<o:p></o:p> Bar</span></p>';
+					expect( normalizeSpacing( input ) ).to.equal( expected );
+				} );
 
-				expect( normalizeSpacing( input ) ).to.equal( expected );
-			} );
+				it( 'should remove newlines from spacerun spans #1', () => {
+					const input = '<span style=\'mso-spacerun:yes\'>  \n</span>';
+					const expected = '<span style=\'mso-spacerun:yes\'> \u00A0</span>';
 
-			it( 'should remove newlines from spacerun spans #1', () => {
-				const input = '<span style=\'mso-spacerun:yes\'>  \n</span>';
-				const expected = '<span style=\'mso-spacerun:yes\'> \u00A0</span>';
+					expect( normalizeSpacing( input ) ).to.equal( expected );
+				} );
 
-				expect( normalizeSpacing( input ) ).to.equal( expected );
-			} );
+				it( 'should remove newlines from spacerun spans #2', () => {
+					const input = '<span style=\'mso-spacerun:yes\'> \r\n</span>';
+					const expected = '<span style=\'mso-spacerun:yes\'>\u00A0</span>';
 
-			it( 'should remove newlines from spacerun spans #2', () => {
-				const input = '<span style=\'mso-spacerun:yes\'> \r\n</span>';
-				const expected = '<span style=\'mso-spacerun:yes\'>\u00A0</span>';
+					expect( normalizeSpacing( input ) ).to.equal( expected );
+				} );
 
-				expect( normalizeSpacing( input ) ).to.equal( expected );
-			} );
+				it( 'should remove newlines from spacerun spans #3', () => {
+					const input = '<span style=\'mso-spacerun:yes\'>  \r\n\n  </span>';
+					const expected = '<span style=\'mso-spacerun:yes\'>   \u00A0</span>';
 
-			it( 'should remove newlines from spacerun spans #3', () => {
-				const input = '<span style=\'mso-spacerun:yes\'>  \r\n\n  </span>';
-				const expected = '<span style=\'mso-spacerun:yes\'>   \u00A0</span>';
+					expect( normalizeSpacing( input ) ).to.equal( expected );
+				} );
 
-				expect( normalizeSpacing( input ) ).to.equal( expected );
-			} );
+				it( 'should remove newlines from spacerun spans #4', () => {
+					const input = '<span style=\'mso-spacerun:yes\'>\n\n\n  </span>';
+					const expected = '<span style=\'mso-spacerun:yes\'> \u00A0</span>';
 
-			it( 'should remove newlines from spacerun spans #4', () => {
-				const input = '<span style=\'mso-spacerun:yes\'>\n\n\n  </span>';
-				const expected = '<span style=\'mso-spacerun:yes\'> \u00A0</span>';
+					expect( normalizeSpacing( input ) ).to.equal( expected );
+				} );
 
-				expect( normalizeSpacing( input ) ).to.equal( expected );
-			} );
+				it( 'should remove newlines from spacerun spans #5', () => {
+					const input = '<span style=\'mso-spacerun:yes\'>\n\n</span>';
+					const expected = '';
 
-			it( 'should remove newlines from spacerun spans #5', () => {
-				const input = '<span style=\'mso-spacerun:yes\'>\n\n</span>';
-				const expected = '';
+					expect( normalizeSpacing( input ) ).to.equal( expected );
+				} );
 
-				expect( normalizeSpacing( input ) ).to.equal( expected );
-			} );
+				it( 'should remove multiline sequences of whitespaces', () => {
+					const input = '<p>Foo</p> \n\n   \n<p>Bar</p>   \r\n\r\n  <p>Baz</p>';
+					const expected = '<p>Foo</p><p>Bar</p><p>Baz</p>';
 
-			it( 'should remove multiline sequences of whitespaces', () => {
-				const input = '<p>Foo</p> \n\n   \n<p>Bar</p>   \r\n\r\n  <p>Baz</p>';
-				const expected = '<p>Foo</p><p>Bar</p><p>Baz</p>';
+					expect( normalizeSpacing( input ) ).to.equal( expected );
+				} );
 
-				expect( normalizeSpacing( input ) ).to.equal( expected );
-			} );
+				it( 'should normalize Safari "space spans"', () => {
+					const input = '<p>Foo <span class="Apple-converted-space">   </span> Baz <span>  </span></p>';
+					const expected = '<p>Foo \u00A0 \u00A0 Baz \u00A0\u00A0</p>';
 
-			it( 'should normalize Safari "space spans"', () => {
-				const input = '<p>Foo <span class="Apple-converted-space">   </span> Baz <span>  </span></p>';
-				const expected = '<p>Foo \u00A0 \u00A0 Baz \u00A0\u00A0</p>';
+					expect( normalizeSpacing( input ) ).to.equal( expected );
+				} );
 
-				expect( normalizeSpacing( input ) ).to.equal( expected );
-			} );
+				it( 'should normalize nested Safari "space spans"', () => {
+					const input =
+						'<p> Foo <span class="Apple-converted-space"> <span class="Apple-converted-space">    </span></span> Baz</p>';
 
-			it( 'should normalize nested Safari "space spans"', () => {
-				const input = '<p> Foo <span class="Apple-converted-space"> <span class="Apple-converted-space">    </span></span> Baz</p>';
-				const expected = '<p> Foo \u00A0 \u00A0 \u00A0 Baz</p>';
+					const expected = '<p> Foo \u00A0 \u00A0 \u00A0 Baz</p>';
 
-				expect( normalizeSpacing( input ) ).to.equal( expected );
+					expect( normalizeSpacing( input ) ).to.equal( expected );
+				} );
 			} );
-		} );
 
-		describe( 'normalizeSpacerunSpans()', () => {
-			it( 'should normalize spaces inside special "span.spacerun" elements', () => {
-				const input = '<p> <span style=\'mso-spacerun:yes\'>   </span>Foo</p>' +
-					'<p> Baz <span style=\'mso-spacerun:yes\'>      </span></p>';
+			describe( 'normalizeSpacerunSpans()', () => {
+				it( 'should normalize spaces inside special "span.spacerun" elements', () => {
+					const input = '<p> <span style=\'mso-spacerun:yes\'>   </span>Foo</p>' +
+						'<p> Baz <span style=\'mso-spacerun:yes\'>      </span></p>';
 
-				const expected = '<p> <span style="mso-spacerun:yes">&nbsp; &nbsp;</span>Foo</p>' +
-					'<p> Baz <span style="mso-spacerun:yes">&nbsp; &nbsp; &nbsp; </span></p>';
+					const expected = '<p> <span style="mso-spacerun:yes">&nbsp; &nbsp;</span>Foo</p>' +
+						'<p> Baz <span style="mso-spacerun:yes">&nbsp; &nbsp; &nbsp; </span></p>';
 
-				const domParser = new DOMParser();
-				const htmlDocument = domParser.parseFromString( input, 'text/html' );
+					const domParser = new DOMParser();
+					const htmlDocument = domParser.parseFromString( input, 'text/html' );
 
-				expect( htmlDocument.body.innerHTML.replace( /'/g, '"' ).replace( /: /g, ':' ) ).to.not.equal( expected );
+					expect( htmlDocument.body.innerHTML.replace( /'/g, '"' ).replace( /: /g, ':' ) ).to.not.equal( expected );
 
-				normalizeSpacerunSpans( htmlDocument );
+					normalizeSpacerunSpans( htmlDocument );
 
-				expect( htmlDocument.body.innerHTML.replace( /'/g, '"' ).replace( /: /g, ':' ) ).to.equal( expected );
+					expect( htmlDocument.body.innerHTML.replace( /'/g, '"' ).replace( /: /g, ':' ) ).to.equal( expected );
+				} );
 			} );
 		} );
 	} );