This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Paste from Office support for Safari #16
Merged
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
2a3c2ed
Tests: Safari input files added.
f1ames c2e7b96
Tests: fixtures loader added and used in basic styles integration tests.
f1ames 6c2ea03
Tests: removed leftovers
f1ames 569b7ca
Tests: Util for browser detection added.
f1ames a27aa01
Adjust 'isWordInput' method to Safari.
f1ames 8f8032a
Tests: Refactoring basic styles tests and utils.
f1ames 59306ff
Tests: Link tests refactor and Safari fixtures added.
f1ames 4bdd9bb
Tests: Spacing tests for Safari.
f1ames 499bf01
Tests: List Safari tests. Tests utils refactoring.
f1ames 9070253
Normalize Safari specific spaces.
f1ames be70851
Tests: Adjust tests expected files to Safari space normalization.
f1ames 027312c
Handle Safari specific spacing.
f1ames d6381cc
Tests: Refactoring - run all fixtures in each browser.
f1ames 036083e
Merge branch 't/8' into t/12
f1ames 9aa46f9
Tests: Add 'Clipboard' plugin to normalization tests.
f1ames c54fc33
Tests: Corrected unit test after wrong merge resolution.
f1ames 8fe3bf4
Merge branch 't/8' into t/12
Reinmar 3f5459d
Tests: Initial tests readme.
f1ames a0a7c24
Tests: Readme adjustments. [skip ci]
f1ames 6f41c23
Tests: Added section on creating tests to README. [skip ci]
f1ames cf51bb0
Tests: Readme rewording. [skip ci]
f1ames 550153e
Merge branch 't/8' into t/12
f1ames c5ff14c
Merge branch 'master' into t/12
Reinmar 78426f3
Reviewed the tests readme.
Reinmar 5833e28
Readme title.
Reinmar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
# Normalization and integration testing in `Paste from Office` | ||
|
||
To test if content pasted from any external application is transformed correctly by the editor the test itself needs to | ||
use data which is put into the native clipboard by the application. For test purpose, such data is stored in the single file | ||
called `fixture` file. | ||
|
||
The `fixture` file is usually a HTML file containing HTML content which was fetched from the native browser `dataTransfer` | ||
object (`dataTransfer.getData( 'html/text' )`) when content was pasted to the browser. This ensures that `fixture` | ||
file provides exactly same data as a real use scenario. | ||
|
||
## Fixture files | ||
|
||
_For example files see `_data/basic-style/bold-within-text/`_. | ||
|
||
The `fixture` files are grouped per feature (which usually corresponds to editor plugins, for example `basic-styles`, `list`, etc). | ||
All fixtures are stored in `_data/feature-name/` directory (for example `_data/basic-style/`). Each feature (which | ||
will be called **group**) has a separate folder per fixture. Each fixture is used to create one normalization and one integration test. | ||
|
||
Each fixture folder contains: | ||
|
||
- original input file - `bold-with-text.docx` | ||
- input fixture - `input.word2016.html` | ||
- normalized output fixture - `normalized.word2016.html` | ||
- model output fixture - `model.word2016.html` | ||
|
||
In some cases, different browsers produces different input data. For such situations, additional fixtures are stored. | ||
For example if input data is different for Safari, additional `input.safari.word2016.html` file will be present in fixture directory. | ||
|
||
## Tests group index | ||
|
||
_For example file see `_data/basic-style/index.js`_. | ||
|
||
Each group of fixtures contains index file (`index.js` in group folder e.g. `_data/basic-styles/index.js`). | ||
Its purpose is to simply import all fixture files from the group and expose them for further use. Index file has the following structure: | ||
|
||
|
||
``` | ||
// Import default/generic fixtures. | ||
// Input fixtures. | ||
import boldWithinText from './bold-within-text/input.word2016.html'; | ||
|
||
// Expected normalized fixtures. | ||
import boldWithinTextNormalized from './bold-within-text/normalized.word2016.html'; | ||
|
||
// Expected model fixtures. | ||
import boldWithinTextModel from './bold-within-text/model.word2016.html'; | ||
|
||
// Export imported generic fixtures for future use. | ||
export const fixtures = { | ||
input: { | ||
boldWithinText: boldWithinText | ||
}, | ||
normalized: { | ||
boldWithinText: boldWithinTextNormalized | ||
}, | ||
model: { | ||
boldWithinText: boldWithinTextModel | ||
} | ||
} | ||
``` | ||
|
||
Such structure exports generic fixtures (the ones which are the same for more than one browser and will be used if no browser specific fixtures are present). | ||
|
||
Index files must also export browser specific fixtures. In the simplest case if there are none, it exports empty object: | ||
|
||
|
||
``` | ||
export browserFixtures = {}; | ||
``` | ||
|
||
If there are any browser specific fixtures, they are exported in a similar manner to generic ones (apart from being grouped by a browser): | ||
|
||
|
||
``` | ||
// Export imported browser-specific fixtures for future use. | ||
export const browserFixtures = { | ||
safari: { | ||
input: { | ||
boldWithinText: boldWithinTextSafari | ||
}, | ||
normalized: { | ||
boldWithinText: boldWithinTextNormalizedSafari | ||
}, | ||
model: { | ||
boldWithinText: boldWithinTextModelSafari | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### What if only input or one of the expected output fixtures are different for specific browser? Could fixtures be mixed? | ||
|
||
There are cases when only some fixtures differ for a given browser. In such cases browser fixtures export reuses generic fixtures: | ||
|
||
``` | ||
// Export imported browser-specific fixtures for future use. | ||
export const browserFixtures = { | ||
safari: { | ||
input: { | ||
boldWithinText: boldWithinText // generic | ||
}, | ||
normalized: { | ||
boldWithinText: boldWithinTextNormalizedSafari // Safari specific | ||
}, | ||
model: { | ||
boldWithinText: boldWithinTextModel // generic | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Fixtures aggregation | ||
|
||
_See `_utils/fixtures.js`_. | ||
|
||
All group indexes files are aggregated in the `fixtures` util (`_utils/fixtures.js`) and exposed for tests in a single | ||
`fixtures` and `browserFixtures` objects: | ||
|
||
|
||
``` | ||
// Import fixtures. | ||
import { fixtures as basicStyles, browserFixtures as basicStylesBrowser } from '../_data/basic-styles/index.js'; | ||
|
||
// Generic fixtures. | ||
export const fixtures = { | ||
'basic-styles': basicStyles | ||
}; | ||
|
||
// Browser specific fixtures. | ||
export const browserFixtures = { | ||
'basic-styles': basicStylesBrowser | ||
}; | ||
``` | ||
|
||
## Tests generation | ||
|
||
_See `data/normalization.js` and `data/integration.js`_. | ||
|
||
Tests based on fixture files are generated by the special util function `generateTests()` (see `_utils/utils.js`). This function | ||
is specifically designed to generate `normalization` (see `data/normalization.js`) or `integration` (see `data/integration.js`) | ||
tests using provided fixtures group, for example: | ||
|
||
|
||
``` | ||
generateTests( { | ||
input: 'basic-styles', // Group name. | ||
type: 'integration', // Tests type (integration or normalization). | ||
browsers: [ 'chrome', 'firefox', 'safari', 'edge' ], // For which browsers generate tests. | ||
editorConfig: { // Editor config which will be used during editor creation which is used in tests. | ||
plugins: [ Clipboard, Paragraph, Heading, Bold, Italic, Underline, Strikethrough, PasteFromOffice ] | ||
}, | ||
skip: { // Names of fixtures which tests should be skipped (object `key` is the name of the browser for which to skip tests). | ||
safari: [ 'italicStartingText', 'multipleStylesSingleLine', 'multipleStylesMultiline' ] // Skip due to spacing issue (#13). | ||
} | ||
} ); | ||
``` | ||
|
||
## Adding new tests | ||
|
||
### To an existing group | ||
|
||
1. Create new fixtures directory in a group to which you plan to add tests (e.g. `_data/link/new-use-case/`). | ||
2. Add all necessary fixture files to the above directory: | ||
* original input file - `new-use-case.docx` | ||
* input fixture - `input.word2016.html` (to acquire clipboard data you may use `integration.html` manual test which prints `text/html` on paste) | ||
* normalized output fixture - `normalized.word2016.html` | ||
* model output fixture - `model.word2016.html` | ||
* any browser specific fixtures | ||
3. Add new fixtures to group `index.js` file. | ||
|
||
That's all, added fixtures will be now used to generate normalization and integration test. | ||
|
||
### To a new group | ||
|
||
1. Create new group directory, for example `_data/new-group/`. | ||
2. Create new fixtures directories (one per input fixture file) in `_data/new-group/`, each containing: | ||
* original input file - `new-use-case.docx` | ||
* input fixture - `input.word2016.html` (to acquire clipboard data you may use `integration.html` manual test which prints `text/html` on paste) | ||
* normalized output fixture - `normalized.word2016.html` | ||
* model output fixture - `model.word2016.html` | ||
* any browser specific fixtures | ||
3. Create group `index.js` file (`_data/new-group/index.js`) importing all necessary fixtures. | ||
4. Add new group to fixtures util `_utils/fixtures.js`: | ||
|
||
|
||
``` | ||
// Import fixtures. | ||
import { fixtures as newGroup, browserFixtures as newGroupBrowser } from '../_data/new-group/index.js'; | ||
|
||
// Generic fixtures. | ||
export const fixtures = { | ||
'new-group': newGroup | ||
}; | ||
|
||
// Browser specific fixtures. | ||
export const browserFixtures = { | ||
'new-group': newGroupBrowser | ||
}; | ||
``` | ||
|
||
5. Add `generateTests()` function call in `data/normalization.js` to generate normalization and in `data/integration.js` | ||
to generate integration tests: | ||
|
||
``` | ||
// normalization.js | ||
generateTests( { | ||
input: 'new-group', | ||
type: 'normalization', | ||
browsers: [ 'chrome', 'firefox', 'safari', 'edge' ] | ||
editorConfig: { ... } | ||
} ); | ||
|
||
// integration.js | ||
generateTests( { | ||
input: 'new-group', | ||
type: 'integration', | ||
browsers: [ 'chrome', 'firefox', 'safari', 'edge' ] | ||
editorConfig: { ... } | ||
} ); | ||
|
||
``` |
4 changes: 4 additions & 0 deletions
4
tests/_data/basic-styles/bold-within-text/input.safari.word2016.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>Some text<span class="Apple-converted-space"> </span><b>with bold</b>.<o:p></o:p></span></p></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<paragraph>Some text <$text bold="true">with bold</$text>.</paragraph> |
1 change: 1 addition & 0 deletions
1
tests/_data/basic-styles/bold-within-text/normalized.safari.word2016.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<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>Some text <b>with bold</b>.<o:p></o:p></span></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
// Default. | ||
import boldWithinText from './bold-within-text/input.word2016.html'; | ||
import italicStartingText from './italic-starting-text/input.word2016.html'; | ||
import underlinedText from './underlined-text/input.word2016.html'; | ||
import strikethroughEndingText from './strikethrough-ending-text/input.word2016.html'; | ||
import multipleStylesSingleLine from './multiple-styles-single-line/input.word2016.html'; | ||
import multipleStylesMultiline from './multiple-styles-multiline/input.word2016.html'; | ||
|
||
import boldWithinTextNormalized from './bold-within-text/normalized.word2016.html'; | ||
import italicStartingTextNormalized from './italic-starting-text/normalized.word2016.html'; | ||
import underlinedTextNormalized from './underlined-text/normalized.word2016.html'; | ||
import strikethroughEndingTextNormalized from './strikethrough-ending-text/normalized.word2016.html'; | ||
import multipleStylesSingleLineNormalized from './multiple-styles-single-line/normalized.word2016.html'; | ||
import multipleStylesMultilineNormalized from './multiple-styles-multiline/normalized.word2016.html'; | ||
|
||
import boldWithinTextModel from './bold-within-text/model.word2016.html'; | ||
import italicStartingTextModel from './italic-starting-text/model.word2016.html'; | ||
import underlinedTextModel from './underlined-text/model.word2016.html'; | ||
import strikethroughEndingTextModel from './strikethrough-ending-text/model.word2016.html'; | ||
import multipleStylesSingleLineModel from './multiple-styles-single-line/model.word2016.html'; | ||
import multipleStylesMultilineModel from './multiple-styles-multiline/model.word2016.html'; | ||
|
||
export const fixtures = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand what's in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added |
||
input: { | ||
boldWithinText, | ||
italicStartingText, | ||
underlinedText, | ||
strikethroughEndingText, | ||
multipleStylesSingleLine, | ||
multipleStylesMultiline | ||
}, | ||
normalized: { | ||
boldWithinText: boldWithinTextNormalized, | ||
italicStartingText: italicStartingTextNormalized, | ||
underlinedText: underlinedTextNormalized, | ||
strikethroughEndingText: strikethroughEndingTextNormalized, | ||
multipleStylesSingleLine: multipleStylesSingleLineNormalized, | ||
multipleStylesMultiline: multipleStylesMultilineNormalized | ||
}, | ||
model: { | ||
boldWithinText: boldWithinTextModel, | ||
italicStartingText: italicStartingTextModel, | ||
underlinedText: underlinedTextModel, | ||
strikethroughEndingText: strikethroughEndingTextModel, | ||
multipleStylesSingleLine: multipleStylesSingleLineModel, | ||
multipleStylesMultiline: multipleStylesMultilineModel | ||
} | ||
}; | ||
|
||
// Safari. | ||
import boldWithinTextSafari from './bold-within-text/input.safari.word2016.html'; | ||
import italicStartingTextSafari from './italic-starting-text/input.safari.word2016.html'; | ||
import underlinedTextSafari from './underlined-text/input.safari.word2016.html'; | ||
import strikethroughEndingTextSafari from './strikethrough-ending-text/input.safari.word2016.html'; | ||
import multipleStylesSingleLineSafari from './multiple-styles-single-line/input.safari.word2016.html'; | ||
import multipleStylesMultilineSafari from './multiple-styles-multiline/input.safari.word2016.html'; | ||
|
||
import boldWithinTextNormalizedSafari from './bold-within-text/normalized.safari.word2016.html'; | ||
import italicStartingTextNormalizedSafari from './italic-starting-text/normalized.safari.word2016.html'; | ||
import underlinedTextNormalizedSafari from './underlined-text/normalized.safari.word2016.html'; | ||
import strikethroughEndingTextNormalizedSafari from './strikethrough-ending-text/normalized.safari.word2016.html'; | ||
import multipleStylesSingleLineNormalizedSafari from './multiple-styles-single-line/normalized.safari.word2016.html'; | ||
import multipleStylesMultilineNormalizedSafari from './multiple-styles-multiline/normalized.safari.word2016.html'; | ||
|
||
export const browserFixtures = { | ||
safari: { | ||
input: { | ||
boldWithinText: boldWithinTextSafari, | ||
italicStartingText: italicStartingTextSafari, | ||
underlinedText: underlinedTextSafari, | ||
strikethroughEndingText: strikethroughEndingTextSafari, | ||
multipleStylesSingleLine: multipleStylesSingleLineSafari, | ||
multipleStylesMultiline: multipleStylesMultilineSafari | ||
}, | ||
normalized: { | ||
boldWithinText: boldWithinTextNormalizedSafari, | ||
italicStartingText: italicStartingTextNormalizedSafari, | ||
underlinedText: underlinedTextNormalizedSafari, | ||
strikethroughEndingText: strikethroughEndingTextNormalizedSafari, | ||
multipleStylesSingleLine: multipleStylesSingleLineNormalizedSafari, | ||
multipleStylesMultiline: multipleStylesMultilineNormalizedSafari | ||
}, | ||
model: { | ||
boldWithinText: boldWithinTextModel, | ||
italicStartingText: italicStartingTextModel, | ||
underlinedText: underlinedTextModel, | ||
strikethroughEndingText: strikethroughEndingTextModel, | ||
multipleStylesSingleLine: multipleStylesSingleLineModel, | ||
multipleStylesMultiline: multipleStylesMultilineModel | ||
} | ||
} | ||
}; |
4 changes: 4 additions & 0 deletions
4
tests/_data/basic-styles/italic-starting-text/input.safari.word2016.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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;"><i><span>Italic</span></i><span>text.<o:p></o:p></span></p></html> |
1 change: 1 addition & 0 deletions
1
tests/_data/basic-styles/italic-starting-text/model.word2016.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<paragraph><$text italic="true">Italic</$text> text.</paragraph> |
1 change: 1 addition & 0 deletions
1
tests/_data/basic-styles/italic-starting-text/normalized.safari.word2016.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<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;"><i><span>Italic</span></i><span>text.<o:p></o:p></span></p> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.