Parcourir la source

Tests: Link tests refactor and Safari fixtures added.

Krzysztof Krztoń il y a 7 ans
Parent
commit
6a7a675565

+ 4 - 0
packages/ckeditor5-paste-from-office/tests/_data/link/combined/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><a href="https://ckeditor.com/" style="color: rgb(149, 79, 114); text-decoration: underline;">CKEditor</a><span class="MsoHyperlink" style="color: rgb(5, 99, 193); text-decoration: underline;"><a href="https://cksource.com/" style="color: rgb(149, 79, 114); text-decoration: underline;">CKSource</a></span>2<o:p></o:p></span></p></html>

+ 3 - 0
packages/ckeditor5-paste-from-office/tests/_data/link/combined/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><a href="https://ckeditor.com/" style="color: rgb(149, 79, 114); text-decoration: underline;">CKEditor</a><span class="MsoHyperlink" style="color: rgb(5, 99, 193); text-decoration: underline;"><a href="https://cksource.com/" style="color: rgb(149, 79, 114); text-decoration: underline;">CKSource</a></span>2<o:p></o:p></span>
+</p>

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

@@ -0,0 +1,50 @@
+/**
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+// Default.
+import withinText from './within-text/input.word2016.html';
+import combined from './combined/input.word2016.html';
+import twoLine from './two-line/input.word2016.html';
+
+import withinTextNormalized from './within-text/normalized.word2016.html';
+import combinedNormalized from './combined/normalized.word2016.html';
+import twoLineNormalized from './two-line/normalized.word2016.html';
+
+export const fixtures = {
+	input: {
+		withinText,
+		combined,
+		twoLine
+	},
+	normalized: {
+		withinText: withinTextNormalized,
+		combined: combinedNormalized,
+		twoLine: twoLineNormalized
+	}
+};
+
+// Safari.
+import withinTextSafari from './within-text/input.safari.word2016.html';
+import combinedSafari from './combined/input.safari.word2016.html';
+import twoLineSafari from './two-line/input.safari.word2016.html';
+
+import withinTextNormalizedSafari from './within-text/normalized.safari.word2016.html';
+import combinedNormalizedSafari from './combined/normalized.safari.word2016.html';
+import twoLineNormalizedSafari from './two-line/normalized.safari.word2016.html';
+
+export const browserFixtures = {
+	safari: {
+		input: {
+			withinText: withinTextSafari,
+			combined: combinedSafari,
+			twoLine: twoLineSafari
+		},
+		normalized: {
+			withinText: withinTextNormalizedSafari,
+			combined: combinedNormalizedSafari,
+			twoLine: twoLineNormalizedSafari
+		}
+	}
+};

+ 4 - 0
packages/ckeditor5-paste-from-office/tests/_data/link/two-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 class="MsoHyperlink" style="color: rgb(5, 99, 193); text-decoration: underline;"><span><a href="https://cksource.com/" style="color: rgb(149, 79, 114); text-decoration: underline;">Long link<span class="Apple-converted-space"> </span><br>WITH spaces</a></span></span><span><o:p></o:p></span></p></html>

+ 8 - 0
packages/ckeditor5-paste-from-office/tests/_data/link/two-line/normalized.safari.word2016.html

@@ -0,0 +1,8 @@
+<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 class="MsoHyperlink" style="color: rgb(5, 99, 193); text-decoration: underline;">
+		<span>
+			<a href="https://cksource.com/" style="color: rgb(149, 79, 114); text-decoration: underline;">Long link<span class="Apple-converted-space"> </span><br>WITH spaces</a>
+		</span>
+	</span>
+	<span><o:p></o:p></span>
+</p>

+ 4 - 0
packages/ckeditor5-paste-from-office/tests/_data/link/within-text/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>Regular<span class="Apple-converted-space"> </span><span class="MsoHyperlink" style="color: rgb(5, 99, 193); text-decoration: underline;"><a href="https://ckeditor.com/" style="color: rgb(149, 79, 114); text-decoration: underline;">link</a></span>1<o:p></o:p></span></p></html>

+ 3 - 0
packages/ckeditor5-paste-from-office/tests/_data/link/within-text/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>Regular<span class="Apple-converted-space"> </span><span class="MsoHyperlink" style="color: rgb(5, 99, 193); text-decoration: underline;"><a href="https://ckeditor.com/" style="color: rgb(149, 79, 114); text-decoration: underline;">link</a></span>1<o:p></o:p></span>
+</p>

+ 23 - 117
packages/ckeditor5-paste-from-office/tests/data/integration/link.js

@@ -14,16 +14,15 @@ import Link from '@ckeditor/ckeditor5-link/src/link';
 import ShiftEnter from '@ckeditor/ckeditor5-enter/src/shiftenter';
 
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { expectPaste } from '../../_utils/utils';
-
-import withinText from '../../_data/link/within-text/input.word2016.html';
-import combined from '../../_data/link/combined/input.word2016.html';
-import twoLine from '../../_data/link/two-line/input.word2016.html';
+import { getFixtures } from '../../_utils/fixtures';
+import { expectModel } from '../../_utils/utils';
 
 describe( 'Link – integration', () => {
-	let element, editor;
+	let element, editor, input;
 
 	before( () => {
+		input = getFixtures( 'link' ).input;
+
 		element = document.createElement( 'div' );
 
 		document.body.appendChild( element );
@@ -45,122 +44,29 @@ describe( 'Link – integration', () => {
 		element.remove();
 	} );
 
-	// Pastes: 'Regular <a href="https://ckeditor.com/">link</a>1'
-	// Input same for: Chrome, Firefox and Edge.
-	describe( 'within text', () => {
-		it( 'pastes in the empty editor', () => {
-			expectPaste( editor, withinText, '<paragraph>Regular ' +
-				'<$text linkHref="https://ckeditor.com/">link</$text>1[]</paragraph>' );
-		} );
-
-		it( 'pastes in the paragraph', () => {
-			setData( editor.model, '<paragraph>More [] text</paragraph>' );
-
-			expectPaste( editor, withinText, '<paragraph>More Regular ' +
-				'<$text linkHref="https://ckeditor.com/">link</$text>1[] text</paragraph>' );
-		} );
-
-		it( 'pastes in the different block context', () => {
-			setData( editor.model, '<heading1>More [] text</heading1>' );
+	// Pastes:
+	//		'Regular <a href="https://ckeditor.com/">link</a>1'
+	it( 'pastes link within text', () => {
+		const expected = '<paragraph>Regular <$text linkHref="https://ckeditor.com/">link</$text>1</paragraph>';
 
-			expectPaste( editor, withinText, '<heading1>More Regular ' +
-				'<$text linkHref="https://ckeditor.com/">link</$text>1[] text</heading1>' );
-		} );
-
-		it( 'pastes in the inline styling context', () => {
-			setData( editor.model, '<paragraph><$text bold="true">Bo[]ld</$text></paragraph>' );
-
-			expectPaste( editor, withinText, '<paragraph><$text bold="true">Bo</$text>' +
-				'Regular <$text linkHref="https://ckeditor.com/">link</$text>1[]<$text bold="true">ld</$text></paragraph>' );
-		} );
+		expectModel( editor, input.withinText, expected );
+	} );
 
-		it( 'pastes inside another link element', () => {
-			setData( editor.model, '<paragraph>1<$text linkHref="#test">tes[]t</$text>2</paragraph>' );
+	// Pastes:
+	//		'<a href="https://ckeditor.com/">CKEditor</a><a href="https://cksource.com/">CKSource</a> 2'
+	it( 'pastes combined links', () => {
+		const expected = '<paragraph><$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
+			'<$text linkHref="https://cksource.com/">CKSource</$text> 2</paragraph>';
 
-			expectPaste( editor, withinText, '<paragraph>1<$text linkHref="#test">tes</$text>' +
-				'Regular <$text linkHref="https://ckeditor.com/">link</$text>1[]<$text linkHref="#test">t</$text>2</paragraph>' );
-		} );
+		expectModel( editor, input.combined, expected );
 	} );
 
-	// Pastes: '<a href="https://ckeditor.com/">CKEditor</a><a href="https://cksource.com/">CKSource</a> 2'
-	// Input same for: Chrome, Firefox and Edge.
-	describe( 'combined', () => {
-		it( 'pastes in the empty editor', () => {
-			expectPaste( editor, combined, '<paragraph><$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
-				'<$text linkHref="https://cksource.com/">CKSource</$text> 2[]</paragraph>' );
-		} );
-
-		it( 'pastes in the paragraph', () => {
-			setData( editor.model, '<paragraph>More [] text</paragraph>' );
-
-			expectPaste( editor, combined, '<paragraph>More <$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
-				'<$text linkHref="https://cksource.com/">CKSource</$text> 2[] text</paragraph>' );
-		} );
-
-		it( 'pastes in the different block context', () => {
-			setData( editor.model, '<heading1>More [] text</heading1>' );
-
-			expectPaste( editor, combined, '<heading1>More <$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
-				'<$text linkHref="https://cksource.com/">CKSource</$text> 2[] text</heading1>' );
-		} );
-
-		it( 'pastes in the inline styling context', () => {
-			setData( editor.model, '<paragraph><$text bold="true">Bo[]ld</$text></paragraph>' );
-
-			expectPaste( editor, combined, '<paragraph><$text bold="true">Bo</$text>' +
-				'<$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
-				'<$text linkHref="https://cksource.com/">CKSource</$text> 2[]' +
-				'<$text bold="true">ld</$text></paragraph>' );
-		} );
-
-		it( 'pastes inside another link element', () => {
-			setData( editor.model, '<paragraph>1<$text linkHref="#test">tes[]t</$text>2</paragraph>' );
-
-			expectPaste( editor, combined, '<paragraph>1<$text linkHref="#test">tes</$text>' +
-				'<$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
-				'<$text linkHref="https://cksource.com/">CKSource</$text> 2[]' +
-				'<$text linkHref="#test">t</$text>2</paragraph>' );
-		} );
-	} );
+	// Pastes:
+	//		'<a href="https://cksource.com/">Long link <br> WITH spaces</a>'
+	it( 'pastes two line link', () => {
+		const expected = '<paragraph><$text linkHref="https://cksource.com/">Long link </$text><softBreak></softBreak>' +
+			'<$text linkHref="https://cksource.com/">WITH spaces</$text></paragraph>';
 
-	// Pastes: '<a href="https://cksource.com/">Long link <br> WITH spaces</a>'
-	// Input same for: Chrome, Firefox and Edge.
-	describe( 'two line', () => {
-		it( 'pastes in the empty editor', () => {
-			expectPaste( editor, twoLine, '<paragraph><$text linkHref="https://cksource.com/">Long link </$text><softBreak></softBreak>' +
-				'<$text linkHref="https://cksource.com/">WITH spaces[]</$text></paragraph>' );
-		} );
-
-		it( 'pastes in the paragraph', () => {
-			setData( editor.model, '<paragraph>More [] text</paragraph>' );
-
-			expectPaste( editor, twoLine, '<paragraph>More <$text linkHref="https://cksource.com/">Long link </$text>' +
-				'<softBreak></softBreak><$text linkHref="https://cksource.com/">WITH spaces[]</$text> text</paragraph>' );
-		} );
-
-		it( 'pastes in the different block context', () => {
-			setData( editor.model, '<heading1>More [] text</heading1>' );
-
-			expectPaste( editor, twoLine, '<heading1>More <$text linkHref="https://cksource.com/">Long link </$text>' +
-				'<softBreak></softBreak><$text linkHref="https://cksource.com/">WITH spaces[]</$text> text</heading1>' );
-		} );
-
-		it( 'pastes in the inline styling context', () => {
-			setData( editor.model, '<paragraph><$text bold="true">Bo[]ld</$text></paragraph>' );
-
-			expectPaste( editor, twoLine, '<paragraph><$text bold="true">Bo</$text>' +
-				'<$text linkHref="https://cksource.com/">Long link </$text>' +
-				'<softBreak></softBreak><$text linkHref="https://cksource.com/">WITH spaces[]</$text>' +
-				'<$text bold="true">ld</$text></paragraph>' );
-		} );
-
-		it( 'pastes inside another link element', () => {
-			setData( editor.model, '<paragraph>1<$text linkHref="#test">tes[]t</$text>2</paragraph>' );
-
-			expectPaste( editor, twoLine, '<paragraph>1<$text linkHref="#test">tes</$text>' +
-				'<$text linkHref="https://cksource.com/">Long link </$text>' +
-				'<softBreak></softBreak><$text linkHref="https://cksource.com/">WITH spaces[]</$text>' +
-				'<$text linkHref="#test">t</$text>2</paragraph>' );
-		} );
+		expectModel( editor, input.twoLine, expected );
 	} );
 } );

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

@@ -8,17 +8,14 @@ import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
 import PasteFromOffice from '../../../src/pastefromoffice';
 
 import { expectNormalized } from '../../_utils/utils';
-
-import withinText from '../../_data/link/within-text/input.word2016.html';
-import combined from '../../_data/link/combined/input.word2016.html';
-import twoLine from '../../_data/link/two-line/input.word2016.html';
-
-import withinTextNormalized from '../../_data/link/within-text/normalized.word2016.html';
-import combinedNormalized from '../../_data/link/combined/normalized.word2016.html';
-import twoLineNormalized from '../../_data/link/two-line/normalized.word2016.html';
+import { getFixtures } from '../../_utils/fixtures';
 
 describe( 'Link – normalization', () => {
-	let editor, pasteFromOfficePlugin;
+	let editor, input, normalized, pasteFromOfficePlugin;
+
+	before( () => {
+		( { input, normalized } = getFixtures( 'link' ) );
+	} );
 
 	beforeEach( () => {
 		return VirtualTestEditor
@@ -33,14 +30,14 @@ describe( 'Link – normalization', () => {
 	} );
 
 	it( 'normalizes link within text', () => {
-		expectNormalized( pasteFromOfficePlugin._normalizeWordInput( withinText, editor ), withinTextNormalized );
+		expectNormalized( pasteFromOfficePlugin._normalizeWordInput( input.withinText, editor ), normalized.withinText );
 	} );
 
 	it( 'normalizes combined links', () => {
-		expectNormalized( pasteFromOfficePlugin._normalizeWordInput( combined, editor ), combinedNormalized );
+		expectNormalized( pasteFromOfficePlugin._normalizeWordInput( input.combined, editor ), normalized.combined );
 	} );
 
 	it( 'normalizes two line links', () => {
-		expectNormalized( pasteFromOfficePlugin._normalizeWordInput( twoLine, editor ), twoLineNormalized );
+		expectNormalized( pasteFromOfficePlugin._normalizeWordInput( input.twoLine, editor ), normalized.twoLine );
 	} );
 } );