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

Commit

Permalink
Fixed errors/warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2ciek committed Jul 12, 2019
1 parent e75fcb0 commit 0fa0f51
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
13 changes: 6 additions & 7 deletions src/conversion/downcasthelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @module engine/conversion/downcasthelpers
*/

/* globals console */
/* globals */

import ModelRange from '../model/range';
import ModelSelection from '../model/selection';
Expand All @@ -20,7 +20,7 @@ import DocumentSelection from '../model/documentselection';
import ConversionHelpers from './conversionhelpers';

import { cloneDeep } from 'lodash-es';
import { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';

/**
* Downcast conversion helper functions.
Expand Down Expand Up @@ -826,12 +826,11 @@ function changeAttribute( attributeCreator ) {
*
* @error conversion-attribute-to-attribute-on-text
*/
console.warn( attachLinkToDocumentation(
throw new CKEditorError(
'conversion-attribute-to-attribute-on-text: ' +
'Trying to convert text node\'s attribute with attribute-to-attribute converter.'
) );

return;
'Trying to convert text node\'s attribute with attribute-to-attribute converter.',
[ data, conversionApi ]
);
}

// First remove the old attribute if there was one.
Expand Down
10 changes: 8 additions & 2 deletions src/model/utils/insertcontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Element from '../element';
import Range from '../range';
import DocumentSelection from '../documentselection';
import Selection from '../selection';
import { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import CKEditorError, { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';

/**
* Inserts content into the editor (specified selection) as one would expect the paste
Expand Down Expand Up @@ -438,7 +438,13 @@ class Insertion {
// Algorithm's correctness check. We should never end up here but it's good to know that we did.
// At this point the insertion position should be after the node we'll merge. If it isn't,
// it should need to be secured as in the left merge case.
// @if CK_DEBUG // console.error( 'The insertion position should equal the merge position' );
/**
* An internal error occured during merging insertion content with siblings.
* The insertion position should equal to the merge position.
*
* @error insertcontent-invalid-insertion-position
*/
throw new CKEditorError( 'insertcontent-invalid-insertion-position', this );
}

// Move the position to the previous node, so it isn't moved to the graveyard on merge.
Expand Down
27 changes: 9 additions & 18 deletions tests/conversion/downcasthelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { stringify as stringifyView } from '../../src/dev-utils/view';
import View from '../../src/view/view';
import createViewRoot from '../view/_utils/createroot';
import { setData as setModelData } from '../../src/dev-utils/model';
import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';

describe( 'DowncastHelpers', () => {
let model, modelRoot, viewRoot, downcastHelpers, controller;
Expand Down Expand Up @@ -638,29 +639,19 @@ describe( 'DowncastHelpers', () => {

// #1587
it( 'config.view and config.model as strings in generic conversion (elements + text)', () => {
const consoleWarnStub = testUtils.sinon.stub( console, 'warn' );

downcastHelpers.elementToElement( { model: 'paragraph', view: 'p' } );

downcastHelpers.attributeToAttribute( { model: 'test', view: 'test' } );

model.change( writer => {
writer.insertElement( 'paragraph', modelRoot, 0 );
writer.insertElement( 'paragraph', { test: '1' }, modelRoot, 1 );

writer.insertText( 'Foo', { test: '2' }, modelRoot.getChild( 0 ), 0 );
writer.insertText( 'Bar', { test: '3' }, modelRoot.getChild( 1 ), 0 );
} );

expectResult( '<p>Foo</p><p test="1">Bar</p>' );
expect( consoleWarnStub.callCount ).to.equal( 2 );
expect( consoleWarnStub.alwaysCalledWithMatch( 'conversion-attribute-to-attribute-on-text' ) ).to.true;

model.change( writer => {
writer.removeAttribute( 'test', modelRoot.getChild( 1 ) );
} );
expectToThrowCKEditorError( () => {
model.change( writer => {
writer.insertElement( 'paragraph', modelRoot, 0 );
writer.insertElement( 'paragraph', { test: '1' }, modelRoot, 1 );

expectResult( '<p>Foo</p><p>Bar</p>' );
writer.insertText( 'Foo', { test: '2' }, modelRoot.getChild( 0 ), 0 );
writer.insertText( 'Bar', { test: '3' }, modelRoot.getChild( 1 ), 0 );
} );
}, /^conversion-attribute-to-attribute-on-text/ );
} );

it( 'should convert attribute insert/change/remove on a model node', () => {
Expand Down

0 comments on commit 0fa0f51

Please sign in to comment.