Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Tests: Added tests created while debugging ckeditor/ckeditor5-clipboa…
Browse files Browse the repository at this point in the history
…rd#2.
  • Loading branch information
Reinmar committed Jul 3, 2017
1 parent 88fcdcb commit fb514e3
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
32 changes: 30 additions & 2 deletions tests/dataprocessor/htmldataprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { stringify, parse } from '../../src/dev-utils/view';
describe( 'HtmlDataProcessor', () => {
const dataProcessor = new HtmlDataProcessor();

describe( 'toView', () => {
describe( 'toView()', () => {
it( 'should return empty DocumentFragment when empty string is passed', () => {
const fragment = dataProcessor.toView( '' );
expect( fragment ).to.be.an.instanceOf( ViewDocumentFragment );
Expand Down Expand Up @@ -58,9 +58,37 @@ describe( 'HtmlDataProcessor', () => {
}, 10 );
} );
}

// Uncomment this test after fixing #404.
// describe( 'https://github.com/ckeditor/ckeditor5-clipboard/issues/2#issuecomment-310417731 + #404', () => {
// it( 'does not lose whitespaces in Chrome\'s paste-like content', () => {
// const fragment = dataProcessor.toView(
// '<meta charset=\'utf-8\'>' +
// '<span>This is the<span>\u00a0</span></span>' +
// '<a href="url">third developer preview</a>' +
// '<span><span>\u00a0</span>of<span>\u00a0</span></span>' +
// '<strong>CKEditor\u00a05</strong>' +
// '<span>.</span>'
// );

// expect( stringify( fragment ) ).to.equal(
// '<span>This is the<span>\u00a0</span></span>' +
// '<a href="url">third developer preview</a>' +
// '<span><span>\u00a0</span>of<span>\u00a0</span></span>' +
// '<strong>CKEditor\u00a05</strong>' +
// '<span>.</span>'
// );

// // Just to be sure... stringify() uses conversion and the browser extensively,
// // so it's not entirely safe.
// expect( fragment.getChild( 0 ).getChild( 1 ).getChild( 0 ).data ).to.equal( '\u00a0' );
// expect( fragment.getChild( 2 ).getChild( 0 ).getChild( 0 ).data ).to.equal( '\u00a0' );
// expect( fragment.getChild( 2 ).getChild( 2 ).getChild( 0 ).data ).to.equal( '\u00a0' );
// } );
// } );
} );

describe( 'toData', () => {
describe( 'toData()', () => {
it( 'should return empty string when empty DocumentFragment is passed', () => {
const fragment = new ViewDocumentFragment();

Expand Down
62 changes: 62 additions & 0 deletions tests/view/domconverter/dom-to-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,68 @@ describe( 'DomConverter', () => {
expect( viewDiv.getChild( 0 ).getChild( 0 ).data ).to.equal( ' foo\n foo ' );
} );

// https://github.com/ckeditor/ckeditor5-clipboard/issues/2#issuecomment-310417731
it( 'not in span between two words (space)', () => {
const domDiv = createElement( document, 'div', {}, [
document.createTextNode( 'word' ),
createElement( document, 'span', {}, [
document.createTextNode( ' ' )
] ),
document.createTextNode( 'word' )
] );

const viewDiv = converter.domToView( domDiv );

expect( viewDiv.getChild( 1 ).name ).to.equal( 'span' );
expect( viewDiv.getChild( 1 ).childCount ).to.equal( 1 );
expect( viewDiv.getChild( 1 ).getChild( 0 ).data ).to.equal( ' ' );
} );

// https://github.com/ckeditor/ckeditor5-clipboard/issues/2#issuecomment-310417731
it( 'not in span between two words (nbsp)', () => {
const domDiv = createElement( document, 'div', {}, [
document.createTextNode( 'word' ),
createElement( document, 'span', {}, [
document.createTextNode( '\u00a0' )
] ),
document.createTextNode( 'word' )
] );

const viewDiv = converter.domToView( domDiv );

expect( viewDiv.getChild( 1 ).name ).to.equal( 'span' );
expect( viewDiv.getChild( 1 ).childCount ).to.equal( 1 );
expect( viewDiv.getChild( 1 ).getChild( 0 ).data ).to.equal( '\u00a0' );
} );

// https://github.com/ckeditor/ckeditor5-clipboard/issues/2#issuecomment-310417731
it( 'not in a Chrome\'s paste-like content', () => {
// Like:
// <span style="color: rgb(0, 0, 0); font-family: Times;">This is the<span>\u00a0</span></span>
// <a href="url" style="font-family: Times; font-size: medium;">third developer preview</a>
const domDiv = createElement( document, 'div', {}, [
createElement( document, 'span', {}, [
document.createTextNode( 'word' ),
createElement( document, 'span', {}, [
document.createTextNode( '\u00a0' )
] )
] ),
createElement( document, 'a', {}, [
document.createTextNode( 'word' )
] )
] );

const viewDiv = converter.domToView( domDiv );

expect( viewDiv.getChild( 0 ).name ).to.equal( 'span' );
expect( viewDiv.getChild( 0 ).childCount ).to.equal( 2 );

expect( viewDiv.getChild( 0 ).getChild( 1 ).name ).to.equal( 'span' );
expect( viewDiv.getChild( 0 ).getChild( 1 ).childCount ).to.equal( 1 );

expect( viewDiv.getChild( 0 ).getChild( 1 ).getChild( 0 ).data ).to.equal( '\u00a0' );
} );

//
// See also whitespace-handling-integration.js.
//
Expand Down

0 comments on commit fb514e3

Please sign in to comment.