|
|
@@ -16,6 +16,7 @@ import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
|
|
|
import DomEmitterMixin from '@ckeditor/ckeditor5-utils/src/dom/emittermixin';
|
|
|
import Collection from '@ckeditor/ckeditor5-utils/src/collection';
|
|
|
import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
|
|
|
+import log from '@ckeditor/ckeditor5-utils/src/log';
|
|
|
|
|
|
testUtils.createSinonSandbox();
|
|
|
|
|
|
@@ -23,6 +24,10 @@ let el, text;
|
|
|
|
|
|
describe( 'Template', () => {
|
|
|
describe( 'constructor()', () => {
|
|
|
+ it( 'sets #_isRendered property', () => {
|
|
|
+ expect( new Template( { tag: 'p' } )._isRendered ).to.be.false;
|
|
|
+ } );
|
|
|
+
|
|
|
it( 'accepts and normalizes the definition', () => {
|
|
|
const bind = Template.bind( new Model( {} ), Object.create( DomEmitterMixin ) );
|
|
|
const tpl = new Template( {
|
|
|
@@ -133,6 +138,16 @@ describe( 'Template', () => {
|
|
|
} ).to.throw( CKEditorError, /ui-template-wrong-syntax/ );
|
|
|
} );
|
|
|
|
|
|
+ it( 'sets #_isRendered true', () => {
|
|
|
+ const tpl = new Template( { tag: 'p' } );
|
|
|
+
|
|
|
+ expect( tpl._isRendered ).to.be.false;
|
|
|
+
|
|
|
+ tpl.render();
|
|
|
+
|
|
|
+ expect( tpl._isRendered ).to.be.true;
|
|
|
+ } );
|
|
|
+
|
|
|
describe( 'DOM Node', () => {
|
|
|
it( 'creates HTMLElement', () => {
|
|
|
const el = new Template( {
|
|
|
@@ -2188,6 +2203,31 @@ describe( 'Template', () => {
|
|
|
expect( tpl.attributes.b[ 0 ] ).to.equal( 'bar' );
|
|
|
} );
|
|
|
|
|
|
+ it( 'logs a warning if an element has already been rendered', () => {
|
|
|
+ const spy = testUtils.sinon.spy( log, 'warn' );
|
|
|
+
|
|
|
+ const tpl = new Template( {
|
|
|
+ tag: 'p'
|
|
|
+ } );
|
|
|
+
|
|
|
+ Template.extend( tpl, {
|
|
|
+ attributes: {
|
|
|
+ class: 'foo'
|
|
|
+ }
|
|
|
+ } );
|
|
|
+
|
|
|
+ tpl.render();
|
|
|
+
|
|
|
+ Template.extend( tpl, {
|
|
|
+ attributes: {
|
|
|
+ class: 'bar'
|
|
|
+ }
|
|
|
+ } );
|
|
|
+
|
|
|
+ sinon.assert.calledOnce( spy );
|
|
|
+ sinon.assert.calledWithExactly( spy, sinon.match( /^template-extend-render/ ) );
|
|
|
+ } );
|
|
|
+
|
|
|
describe( 'attributes', () => {
|
|
|
it( 'extends existing - simple', () => {
|
|
|
extensionTest(
|