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

Tests: Spacing tests for Safari.

Krzysztof Krztoń 7 лет назад
Родитель
Сommit
9ba8043a0c

+ 50 - 0
packages/ckeditor5-paste-from-office/tests/_data/spacing/index.js

@@ -0,0 +1,50 @@
+/**
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+// Default.
+import simple from './simple/input.word2016.html';
+import singleLine from './single-line/input.word2016.html';
+import multiLine from './multi-line/input.word2016.html';
+
+import simpleNormalized from './simple/normalized.word2016.html';
+import singleLineNormalized from './single-line/normalized.word2016.html';
+import multiLineNormalized from './multi-line/normalized.word2016.html';
+
+export const fixtures = {
+	input: {
+		simple,
+		singleLine,
+		multiLine
+	},
+	normalized: {
+		simple: simpleNormalized,
+		singleLine: singleLineNormalized,
+		multiLine: multiLineNormalized
+	}
+};
+
+// Safari.
+import simpleSafari from './simple/input.safari.word2016.html';
+import singleLineSafari from './single-line/input.safari.word2016.html';
+import multiLineSafari from './multi-line/input.safari.word2016.html';
+
+import simpleNormalizedSafari from './simple/normalized.safari.word2016.html';
+import singleLineNormalizedSafari from './single-line/normalized.safari.word2016.html';
+import multiLineNormalizedSafari from './multi-line/normalized.safari.word2016.html';
+
+export const browserFixtures = {
+	safari: {
+		input: {
+			simple: simpleSafari,
+			singleLine: singleLineSafari,
+			multiLine: multiLineSafari
+		},
+		normalized: {
+			simple: simpleNormalizedSafari,
+			singleLine: singleLineNormalizedSafari,
+			multiLine: multiLineNormalizedSafari
+		}
+	}
+};

+ 4 - 0
packages/ckeditor5-paste-from-office/tests/_data/spacing/multi-line/input.safari.word2016.html

@@ -0,0 +1,4 @@
+<html xmlns:o="urn:schemas-microsoft-com:office:office"
+	  xmlns:w="urn:schemas-microsoft-com:office:word"
+	  xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
+	  xmlns="http://www.w3.org/TR/REC-html40"><p class="MsoNormal" style="margin: 0cm 0cm 8pt; line-height: 15.693333625793457px; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; text-indent: 5.25pt;"><span>2Foo<span class="Apple-converted-space"> </span><span>  </span>3Bar4<span class="Apple-converted-space"> </span><span>   </span><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 8pt; line-height: 15.693333625793457px; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; text-indent: 5.25pt;"><span>03<span>  <span class="Apple-converted-space"> </span></span><o:p></o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 8pt; line-height: 15.693333625793457px; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; text-indent: 5.25pt;"><span><span> <span class="Apple-converted-space"> </span></span>21<span class="Apple-converted-space"> </span><o:p></o:p></span></p></html>

+ 11 - 0
packages/ckeditor5-paste-from-office/tests/_data/spacing/multi-line/normalized.safari.word2016.html

@@ -0,0 +1,11 @@
+<p class="MsoNormal" style="margin: 0cm 0cm 8pt; line-height: 15.693333625793457px; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; text-indent: 5.25pt;">
+	<span>2Foo<span class="Apple-converted-space"> </span><span>  </span>3Bar4<span class="Apple-converted-space"> </span><span>   </span><o:p></o:p></span>
+</p>
+
+<p class="MsoNormal" style="margin: 0cm 0cm 8pt; line-height: 15.693333625793457px; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; text-indent: 5.25pt;">
+	<span>03<span>  <span class="Apple-converted-space"> </span></span><o:p></o:p></span>
+</p>
+
+<p class="MsoNormal" style="margin: 0cm 0cm 8pt; line-height: 15.693333625793457px; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; text-indent: 5.25pt;">
+	<span><span> <span class="Apple-converted-space"> </span></span>21<span class="Apple-converted-space"> </span><o:p></o:p></span>
+</p>

+ 4 - 0
packages/ckeditor5-paste-from-office/tests/_data/spacing/simple/input.safari.word2016.html

@@ -0,0 +1,4 @@
+<html xmlns:o="urn:schemas-microsoft-com:office:office"
+	  xmlns:w="urn:schemas-microsoft-com:office:word"
+	  xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
+	  xmlns="http://www.w3.org/TR/REC-html40"><p class="MsoNormal" style="margin: 0cm 0cm 8pt; line-height: 15.693333625793457px; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Foo Bar<span class="Apple-converted-space"> </span><o:p></o:p></span></p></html>

+ 3 - 0
packages/ckeditor5-paste-from-office/tests/_data/spacing/simple/normalized.safari.word2016.html

@@ -0,0 +1,3 @@
+<p class="MsoNormal" style="margin: 0cm 0cm 8pt; line-height: 15.693333625793457px; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;">
+	<span>Foo Bar<span class="Apple-converted-space"> </span><o:p></o:p></span>
+</p>

+ 4 - 0
packages/ckeditor5-paste-from-office/tests/_data/spacing/single-line/input.safari.word2016.html

@@ -0,0 +1,4 @@
+<html xmlns:o="urn:schemas-microsoft-com:office:office"
+	  xmlns:w="urn:schemas-microsoft-com:office:word"
+	  xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
+	  xmlns="http://www.w3.org/TR/REC-html40"><p class="MsoNormal" style="margin: 0cm 0cm 8pt; line-height: 15.693333625793457px; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;"><span><span> <span class="Apple-converted-space"> </span></span>2Foo<span class="Apple-converted-space"> </span><span>  </span>3Bar4<span class="Apple-converted-space"> </span><span>   </span><o:p></o:p></span></p></html>

+ 5 - 0
packages/ckeditor5-paste-from-office/tests/_data/spacing/single-line/normalized.safari.word2016.html

@@ -0,0 +1,5 @@
+<p class="MsoNormal" style="margin: 0cm 0cm 8pt; line-height: 15.693333625793457px; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;">
+	<span>
+		<span> <span class="Apple-converted-space"> </span></span>2Foo<span class="Apple-converted-space"> </span><span>  </span>3Bar4<span class="Apple-converted-space"> </span><span>   </span><o:p></o:p>
+	</span>
+</p>

+ 5 - 2
packages/ckeditor5-paste-from-office/tests/_utils/fixtures.js

@@ -7,15 +7,18 @@ import { getBrowserName } from './utils';
 
 import { fixtures as basicStyles, browserFixtures as basicStylesBrowser } from '../_data/basic-styles/index.js';
 import { fixtures as link, browserFixtures as linkBrowser } from '../_data/link/index.js';
+import { fixtures as spacing, browserFixtures as spacingBrowser } from '../_data/spacing/index.js';
 
 const fixtures = {
 	'basic-styles': basicStyles,
-	link
+	link,
+	spacing
 };
 
 const browserFixtures = {
 	'basic-styles': basicStylesBrowser,
-	link: linkBrowser
+	link: linkBrowser,
+	spacing: spacingBrowser
 };
 
 export function getFixtures( group ) {

+ 12 - 36
packages/ckeditor5-paste-from-office/tests/data/integration/spacing.js

@@ -13,17 +13,16 @@ import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
 import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
 import PasteFromOffice from '../../../src/pastefromoffice';
 
-import { setData, stringify } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { pasteHtml } from '../../_utils/utils';
-
-import simple from '../../_data/spacing/simple/input.word2016.html';
-import singleLine from '../../_data/spacing/single-line/input.word2016.html';
-import multiLine from '../../_data/spacing/multi-line/input.word2016.html';
+import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import { getFixtures } from '../../_utils/fixtures';
+import { expectModel } from '../../_utils/utils';
 
 describe( 'Spacing – integration', () => {
-	let element, editor, insertedModel;
+	let element, editor, input;
 
 	before( () => {
+		input = getFixtures( 'spacing' ).input;
+
 		element = document.createElement( 'div' );
 
 		document.body.appendChild( element );
@@ -32,16 +31,6 @@ describe( 'Spacing – integration', () => {
 			.create( element, { plugins: [ Clipboard, Paragraph, Bold, Italic, Underline, PasteFromOffice ] } )
 			.then( editorInstance => {
 				editor = editorInstance;
-
-				const model = editor.model;
-				const insertContent = model.insertContent;
-
-				sinon.stub( editor.model, 'insertContent' ).callsFake( ( content, selection ) => {
-					// Save model string representation now as it may change after `insertContent()` function call
-					// so accessing it later may not work as it may have empty/changed structure.
-					insertedModel = stringify( content );
-					insertContent.call( model, content, selection );
-				} );
 			} );
 	} );
 
@@ -49,13 +38,7 @@ describe( 'Spacing – integration', () => {
 		setData( editor.model, '<paragraph>[]</paragraph>' );
 	} );
 
-	afterEach( () => {
-		insertedModel = null;
-	} );
-
 	after( () => {
-		sinon.restore();
-
 		editor.destroy();
 
 		element.remove();
@@ -69,9 +52,9 @@ describe( 'Spacing – integration', () => {
 	//
 	//		<p>Foo Bar </p>
 	it( 'pastes line with single space', () => {
-		const expectedModel = '<paragraph>Foo Bar </paragraph>';
+		const expected = '<paragraph>Foo Bar </paragraph>';
 
-		expectContent( simple, expectedModel );
+		expectModel( editor, input.simple, expected );
 	} );
 
 	// Pastes (after cleaning up garbage markup):
@@ -86,9 +69,9 @@ describe( 'Spacing – integration', () => {
 	//
 	// 		<p>  2Foo   3Bar4    </p>
 	it( 'pastes single line with multiple spaces', () => {
-		const expectedModel = '<paragraph>  2Foo   3Bar4    </paragraph>';
+		const expected = '<paragraph>  2Foo   3Bar4    </paragraph>';
 
-		expectContent( singleLine, expectedModel );
+		expectModel( editor, input.singleLine, expected );
 	} );
 
 	// Pastes (after cleaning up garbage markup):
@@ -103,17 +86,10 @@ describe( 'Spacing – integration', () => {
 	//		<p>03   </p>
 	//		<p>  21 </p>
 	it( 'pastes multiple lines with multiple spaces', () => {
-		const expectedModel = '<paragraph>2Foo   3Bar4    </paragraph>' +
+		const expected = '<paragraph>2Foo   3Bar4    </paragraph>' +
 			'<paragraph>03   </paragraph>' +
 			'<paragraph>  21 </paragraph>';
 
-		expectContent( multiLine, expectedModel );
+		expectModel( editor, input.multiLine, expected );
 	} );
-
-	function expectContent( input, expectedModel ) {
-		pasteHtml( editor, input );
-
-		expect( insertedModel.replace( /\u00A0/g, '#' ).replace( /&nbsp;/g, '#' ) )
-			.to.equal( expectedModel.replace( /\u00A0/g, '#' ).replace( /&nbsp;/g, '#' ) );
-	}
 } );

+ 9 - 12
packages/ckeditor5-paste-from-office/tests/data/normalization/spacing.js

@@ -8,17 +8,14 @@ import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
 import PasteFromOffice from '../../../src/pastefromoffice';
 
 import { expectNormalized } from '../../_utils/utils';
-
-import simple from '../../_data/spacing/simple/input.word2016.html';
-import singleLine from '../../_data/spacing/single-line/input.word2016.html';
-import multiLine from '../../_data/spacing/multi-line/input.word2016.html';
-
-import simpleNormalized from '../../_data/spacing/simple/normalized.word2016.html';
-import singleLineNormalized from '../../_data/spacing/single-line/normalized.word2016.html';
-import multiLineNormalized from '../../_data/spacing/multi-line/normalized.word2016.html';
+import { getFixtures } from '../../_utils/fixtures';
 
 describe( 'Spacing – normalization', () => {
-	let editor, pasteFromOfficePlugin;
+	let editor, input, normalized, pasteFromOfficePlugin;
+
+	before( () => {
+		( { input, normalized } = getFixtures( 'spacing' ) );
+	} );
 
 	beforeEach( () => {
 		return VirtualTestEditor
@@ -33,14 +30,14 @@ describe( 'Spacing – normalization', () => {
 	} );
 
 	it( 'normalizes simple single spacing', () => {
-		expectNormalized( pasteFromOfficePlugin._normalizeWordInput( simple, editor ), simpleNormalized );
+		expectNormalized( pasteFromOfficePlugin._normalizeWordInput( input.simple, editor ), normalized.simple );
 	} );
 
 	it( 'normalizes multiple spacing in a single line', () => {
-		expectNormalized( pasteFromOfficePlugin._normalizeWordInput( singleLine, editor ), singleLineNormalized );
+		expectNormalized( pasteFromOfficePlugin._normalizeWordInput( input.singleLine, editor ), normalized.singleLine );
 	} );
 
 	it( 'normalizes multiple spacing in multiple lines', () => {
-		expectNormalized( pasteFromOfficePlugin._normalizeWordInput( multiLine, editor ), multiLineNormalized );
+		expectNormalized( pasteFromOfficePlugin._normalizeWordInput( input.multiLine, editor ), normalized.multiLine );
 	} );
 } );