/**
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
import viewToPlainText from '../../src/utils/viewtoplaintext';
import { parse as parseView } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
describe( 'viewToPlainText()', () => {
function testViewToPlainText( viewString, expectedText ) {
const view = parseView( viewString );
const text = viewToPlainText( view );
expect( text ).to.equal( expectedText );
}
it( 'should output text contents of given view', () => {
testViewToPlainText(
'FooBarXyz',
'FooBarXyz'
);
} );
it( 'should put empty line between container elements', () => {
testViewToPlainText(
'Header' +
'Foo' +
'Bar' +
'Abc' +
'Xyz',
'Header\n\nFoo\n\nBar\n\nAbc\n\nXyz'
);
} );
it( 'should turn a soft break into a single empty line', () => {
testViewToPlainText(
'FooBar',
'Foo\nBar'
);
} );
it( 'should turn multiple soft breaks into empty lines', () => {
testViewToPlainText(
'FooBar',
'Foo\n\nBar'
);
} );
it( 'should output alt attribute of image elements', () => {
testViewToPlainText(
'Foo' +
'
',
'Foo\n\nAlt'
);
} );
it( 'should not put empty line after li (if not needed)', () => {
testViewToPlainText(
'Foo' +
'' +
'A' +
'B' +
'C' +
'' +
'Bar',
'Foo\n\nA\nB\nC\n\nBar'
);
} );
it( 'should not put empty line before/after figcaption (if not needed)', () => {
testViewToPlainText(
'Foo' +
'' +
'
' +
'Caption' +
'' +
'Bar',
'Foo\n\nAlt\nCaption\n\nBar'
);
} );
} );