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

Commit

Permalink
Added tests checking 1267 issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonkups committed Mar 2, 2018
1 parent 2462d27 commit 9014fdd
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions tests/tickets/1267.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

/* globals document */

import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
import Position from '../../src/model/position';
import Range from '../../src/model/range';
import { setData as setModelData, getData as getModelData } from '../../src/dev-utils/model';

describe( 'Bug ckeditor5-engine#1267', () => {
let element, editor, model;

beforeEach( () => {
element = document.createElement( 'div' );
document.body.appendChild( element );

return ClassicTestEditor
.create( element, { plugins: [ Paragraph, Bold ] } )
.then( newEditor => {
editor = newEditor;
model = editor.model;
} );
} );

afterEach( () => {
element.remove();

return editor.destroy();
} );

it( 'selection should not retain attributes after external change removal', () => {
setModelData( model,
'<paragraph>foo bar baz</paragraph>' +
'<paragraph>foo <$text bold="true">bar{}</$text> baz</paragraph>'
);

// Remove second paragraph where selection is placed.
model.enqueueChange( 'transparent', writer => {
writer.remove( Range.createFromPositionAndShift( new Position( model.document.getRoot(), [ 1 ] ), 1 ) );
} );

expect( getModelData( model ) ).to.equal( '<paragraph>foo bar baz[]</paragraph>' );
} );

it( 'selection should retain attributes set manually', () => {
setModelData( model,
'<paragraph>foo bar baz</paragraph>' +
'<paragraph>foo bar baz</paragraph>' +
'<paragraph>[]</paragraph>'
);

// Execute bold command when selection is inside empty paragraph.
editor.execute( 'bold' );
expect( getModelData( model ) ).to.equal(
'<paragraph>foo bar baz</paragraph>' +
'<paragraph>foo bar baz</paragraph>' +
'<paragraph selection:bold="true"><$text bold="true">[]</$text></paragraph>'
);

// Remove second paragraph.
model.enqueueChange( 'transparent', writer => {
writer.remove( Range.createFromPositionAndShift( new Position( model.document.getRoot(), [ 1 ] ), 1 ) );
} );

// Selection attributes set by command should stay as they were.
expect( getModelData( model ) ).to.equal(
'<paragraph>foo bar baz</paragraph>' +
'<paragraph selection:bold="true"><$text bold="true">[]</$text></paragraph>' );
} );
} );

0 comments on commit 9014fdd

Please sign in to comment.