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

Commit

Permalink
Merge dd3f77a into 1a7c508
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2ciek committed Jul 10, 2019
2 parents 1a7c508 + dd3f77a commit b5df189
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 47 deletions.
9 changes: 5 additions & 4 deletions src/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
* @module ui/template
*/

/* global document */
/* global document, console */

import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import CKEditorError, { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import mix from '@ckeditor/ckeditor5-utils/src/mix';
import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
import View from './view';
import ViewCollection from './viewcollection';
import isNode from '@ckeditor/ckeditor5-utils/src/dom/isnode';
import log from '@ckeditor/ckeditor5-utils/src/log';
import { isObject, cloneDeepWith } from 'lodash-es';

const xhtmlNs = 'http://www.w3.org/1999/xhtml';
Expand Down Expand Up @@ -381,7 +380,9 @@ export default class Template {
*
* @error template-extend-render
*/
log.warn( 'template-extend-render: Attempting to extend a template which has already been rendered.' );
console.warn( attachLinkToDocumentation(
'template-extend-render: Attempting to extend a template which has already been rendered.'
) );
}

extendTemplate( template, normalize( clone( def ) ) );
Expand Down
9 changes: 5 additions & 4 deletions src/toolbar/toolbarview.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
* @module ui/toolbar/toolbarview
*/

/* globals console */

import View from '../view';
import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import FocusCycler from '../focuscycler';
import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
import ToolbarSeparatorView from './toolbarseparatorview';
import preventDefault from '../bindings/preventdefault.js';
import log from '@ckeditor/ckeditor5-utils/src/log';

import '../../theme/components/toolbar/toolbar.css';
import { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';

/**
* The toolbar view class.
Expand Down Expand Up @@ -180,10 +182,9 @@ export default class ToolbarView extends View {
* @error toolbarview-item-unavailable
* @param {String} name The name of the component.
*/
log.warn(
console.warn( attachLinkToDocumentation(
'toolbarview-item-unavailable: The requested toolbar item is unavailable.',
{ name }
);
), { name } );
}
} );
}
Expand Down
60 changes: 29 additions & 31 deletions tests/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* globals HTMLElement, Event, document */
/* globals HTMLElement, Event, document, console */

import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
import { default as Template, TemplateToBinding, TemplateIfBinding } from '../src/template';
import View from '../src/view';
import ViewCollection from '../src/viewcollection';
Expand All @@ -14,18 +13,17 @@ import Model from '../src/model';
import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
import DomEmitterMixin from '@ckeditor/ckeditor5-utils/src/dom/emittermixin';
import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
import log from '@ckeditor/ckeditor5-utils/src/log';

import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';

let el, text;
const injectedElements = [];

describe( 'Template', () => {
testUtils.createSinonSandbox();

// Clean-up document.body from the rendered elements.
afterEach( () => {
sinon.restore();

for ( const el of injectedElements ) {
el.remove();
}
Expand Down Expand Up @@ -1026,9 +1024,9 @@ describe( 'Template', () => {
'<div><a class="a1 a2">a</a><b class="b1 b2">b</b></div>'
);

const spy1 = testUtils.sinon.spy();
const spy2 = testUtils.sinon.spy();
const spy3 = testUtils.sinon.spy();
const spy1 = sinon.spy();
const spy2 = sinon.spy();
const spy3 = sinon.spy();

observable.on( 'ku', spy1 );
observable.on( 'kd', spy2 );
Expand Down Expand Up @@ -1593,7 +1591,7 @@ describe( 'Template', () => {
} );

it( 'accepts plain binding', () => {
const spy = testUtils.sinon.spy();
const spy = sinon.spy();

setElement( {
tag: 'p',
Expand All @@ -1612,8 +1610,8 @@ describe( 'Template', () => {
} );

it( 'accepts an array of event bindings', () => {
const spy1 = testUtils.sinon.spy();
const spy2 = testUtils.sinon.spy();
const spy1 = sinon.spy();
const spy2 = sinon.spy();

setElement( {
tag: 'p',
Expand All @@ -1640,9 +1638,9 @@ describe( 'Template', () => {
} );

it( 'accepts DOM selectors', () => {
const spy1 = testUtils.sinon.spy();
const spy2 = testUtils.sinon.spy();
const spy3 = testUtils.sinon.spy();
const spy1 = sinon.spy();
const spy2 = sinon.spy();
const spy3 = sinon.spy();

setElement( {
tag: 'p',
Expand Down Expand Up @@ -1721,8 +1719,8 @@ describe( 'Template', () => {
} );

it( 'accepts function callbacks', () => {
const spy1 = testUtils.sinon.spy();
const spy2 = testUtils.sinon.spy();
const spy1 = sinon.spy();
const spy2 = sinon.spy();

setElement( {
tag: 'p',
Expand Down Expand Up @@ -1753,7 +1751,7 @@ describe( 'Template', () => {
} );

it( 'supports event delegation', () => {
const spy = testUtils.sinon.spy();
const spy = sinon.spy();

setElement( {
tag: 'p',
Expand All @@ -1777,7 +1775,7 @@ describe( 'Template', () => {
} );

it( 'works for future elements', () => {
const spy = testUtils.sinon.spy();
const spy = sinon.spy();

setElement( {
tag: 'p',
Expand Down Expand Up @@ -1811,7 +1809,7 @@ describe( 'Template', () => {

describe( 'to', () => {
it( 'returns an instance of TemplateToBinding', () => {
const spy = testUtils.sinon.spy();
const spy = sinon.spy();
const binding = bind.to( 'foo', spy );

expect( binding ).to.be.instanceof( TemplateToBinding );
Expand Down Expand Up @@ -2034,7 +2032,7 @@ describe( 'Template', () => {

describe( 'if', () => {
it( 'returns an object which describes the binding', () => {
const spy = testUtils.sinon.spy();
const spy = sinon.spy();
const binding = bind.if( 'foo', 'whenTrue', spy );

expect( binding ).to.be.instanceof( TemplateIfBinding );
Expand Down Expand Up @@ -2334,7 +2332,7 @@ describe( 'Template', () => {
} );

it( 'logs a warning if an element has already been rendered', () => {
const spy = testUtils.sinon.stub( log, 'warn' );
const consoleWarnStub = sinon.stub( console, 'warn' );

const tpl = new Template( {
tag: 'p'
Expand All @@ -2354,8 +2352,8 @@ describe( 'Template', () => {
}
} );

sinon.assert.calledOnce( spy );
sinon.assert.calledWithExactly( spy, sinon.match( /^template-extend-render/ ) );
sinon.assert.calledOnce( consoleWarnStub );
sinon.assert.calledWithExactly( consoleWarnStub, sinon.match( /^template-extend-render/ ) );
} );

describe( 'attributes', () => {
Expand Down Expand Up @@ -2918,11 +2916,11 @@ describe( 'Template', () => {

describe( 'listeners', () => {
it( 'extends existing', () => {
const spy1 = testUtils.sinon.spy();
const spy2 = testUtils.sinon.spy();
const spy3 = testUtils.sinon.spy();
const spy4 = testUtils.sinon.spy();
const spy5 = testUtils.sinon.spy();
const spy1 = sinon.spy();
const spy2 = sinon.spy();
const spy3 = sinon.spy();
const spy4 = sinon.spy();
const spy5 = sinon.spy();

observable.on( 'A', spy1 );
observable.on( 'C', spy2 );
Expand Down Expand Up @@ -2973,9 +2971,9 @@ describe( 'Template', () => {
} );

it( 'creates new', () => {
const spy1 = testUtils.sinon.spy();
const spy2 = testUtils.sinon.spy();
const spy3 = testUtils.sinon.spy();
const spy1 = sinon.spy();
const spy2 = sinon.spy();
const spy3 = sinon.spy();

observable.on( 'A', spy1 );
observable.on( 'B', spy2 );
Expand Down
13 changes: 5 additions & 8 deletions tests/toolbar/toolbarview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* global document, Event */
/* global document, Event, console */

import ToolbarView from '../../src/toolbar/toolbarview';
import ToolbarSeparatorView from '../../src/toolbar/toolbarseparatorview';
Expand All @@ -13,22 +13,19 @@ import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import FocusCycler from '../../src/focuscycler';
import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
import ViewCollection from '../../src/viewcollection';
import log from '@ckeditor/ckeditor5-utils/src/log';
import View from '../../src/view';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';

describe( 'ToolbarView', () => {
let locale, view;

testUtils.createSinonSandbox();

beforeEach( () => {
locale = {};
view = new ToolbarView( locale );
view.render();
} );

afterEach( () => {
sinon.restore();
view.destroy();
} );

Expand Down Expand Up @@ -306,16 +303,16 @@ describe( 'ToolbarView', () => {

it( 'warns if there is no such component in the factory', () => {
const items = view.items;
testUtils.sinon.stub( log, 'warn' );
const consoleWarnStub = sinon.stub( console, 'warn' );

view.fillFromConfig( [ 'foo', 'bar', 'baz' ], factory );

expect( items ).to.have.length( 2 );
expect( items.get( 0 ).name ).to.equal( 'foo' );
expect( items.get( 1 ).name ).to.equal( 'bar' );

sinon.assert.calledOnce( log.warn );
sinon.assert.calledWithExactly( log.warn,
sinon.assert.calledOnce( consoleWarnStub );
sinon.assert.calledWithExactly( consoleWarnStub,
sinon.match( /^toolbarview-item-unavailable/ ),
{ name: 'baz' }
);
Expand Down

0 comments on commit b5df189

Please sign in to comment.