|
@@ -11,6 +11,7 @@ import IconView from '../../src/icon/iconview';
|
|
|
import TooltipView from '../../src/tooltip/tooltipview';
|
|
import TooltipView from '../../src/tooltip/tooltipview';
|
|
|
import View from '../../src/view';
|
|
import View from '../../src/view';
|
|
|
import ViewCollection from '../../src/viewcollection';
|
|
import ViewCollection from '../../src/viewcollection';
|
|
|
|
|
+import env from '@ckeditor/ckeditor5-utils/src/env';
|
|
|
|
|
|
|
|
describe( 'ButtonView', () => {
|
|
describe( 'ButtonView', () => {
|
|
|
let locale, view;
|
|
let locale, view;
|
|
@@ -24,6 +25,10 @@ describe( 'ButtonView', () => {
|
|
|
view.render();
|
|
view.render();
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ afterEach( () => {
|
|
|
|
|
+ view.destroy();
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
describe( 'constructor()', () => {
|
|
describe( 'constructor()', () => {
|
|
|
it( 'creates view#children collection', () => {
|
|
it( 'creates view#children collection', () => {
|
|
|
expect( view.children ).to.be.instanceOf( ViewCollection );
|
|
expect( view.children ).to.be.instanceOf( ViewCollection );
|
|
@@ -39,6 +44,10 @@ describe( 'ButtonView', () => {
|
|
|
expect( view.labelView.element.classList.contains( 'ck-button__label' ) ).to.be.true;
|
|
expect( view.labelView.element.classList.contains( 'ck-button__label' ) ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'creates #keystrokeView', () => {
|
|
|
|
|
+ expect( view.keystrokeView ).to.be.instanceOf( View );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'creates #iconView', () => {
|
|
it( 'creates #iconView', () => {
|
|
|
expect( view.iconView ).to.be.instanceOf( IconView );
|
|
expect( view.iconView ).to.be.instanceOf( IconView );
|
|
|
} );
|
|
} );
|
|
@@ -86,6 +95,14 @@ describe( 'ButtonView', () => {
|
|
|
expect( view.element.classList.contains( 'ck-button_with-text' ) ).to.false;
|
|
expect( view.element.classList.contains( 'ck-button_with-text' ) ).to.false;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'reacts on view#withKeystroke', () => {
|
|
|
|
|
+ view.withKeystroke = true;
|
|
|
|
|
+ expect( view.element.classList.contains( 'ck-button_with-keystroke' ) ).to.true;
|
|
|
|
|
+
|
|
|
|
|
+ view.withKeystroke = false;
|
|
|
|
|
+ expect( view.element.classList.contains( 'ck-button_with-keystroke' ) ).to.false;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'reacts on view#type', () => {
|
|
it( 'reacts on view#type', () => {
|
|
|
// Default value.
|
|
// Default value.
|
|
|
expect( view.element.getAttribute( 'type' ) ).to.equal( 'button' );
|
|
expect( view.element.getAttribute( 'type' ) ).to.equal( 'button' );
|
|
@@ -288,7 +305,7 @@ describe( 'ButtonView', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- describe( 'icon', () => {
|
|
|
|
|
|
|
+ describe( '#iconView', () => {
|
|
|
it( 'is omited in #children when view#icon is not defined', () => {
|
|
it( 'is omited in #children when view#icon is not defined', () => {
|
|
|
view = new ButtonView( locale );
|
|
view = new ButtonView( locale );
|
|
|
view.render();
|
|
view.render();
|
|
@@ -325,6 +342,57 @@ describe( 'ButtonView', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ describe( '#keystrokeView', () => {
|
|
|
|
|
+ it( 'is omited in #children when view#icon is not defined', () => {
|
|
|
|
|
+ view = new ButtonView( locale );
|
|
|
|
|
+ view.render();
|
|
|
|
|
+
|
|
|
|
|
+ expect( view.element.childNodes ).to.have.length( 2 );
|
|
|
|
|
+ expect( view.keystrokeView.element ).to.be.null;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'is added to the #children when view#withKeystroke is true', () => {
|
|
|
|
|
+ testUtils.sinon.stub( env, 'isMac' ).value( false );
|
|
|
|
|
+
|
|
|
|
|
+ view = new ButtonView( locale );
|
|
|
|
|
+ view.keystroke = 'Ctrl+A';
|
|
|
|
|
+ view.withKeystroke = true;
|
|
|
|
|
+ view.render();
|
|
|
|
|
+
|
|
|
|
|
+ expect( view.element.childNodes ).to.have.length( 3 );
|
|
|
|
|
+ expect( view.element.childNodes[ 2 ] ).to.equal( view.keystrokeView.element );
|
|
|
|
|
+
|
|
|
|
|
+ expect( view.keystrokeView.element.classList.contains( 'ck' ) ).to.be.true;
|
|
|
|
|
+ expect( view.keystrokeView.element.classList.contains( 'ck-button__keystroke' ) ).to.be.true;
|
|
|
|
|
+
|
|
|
|
|
+ expect( view.keystrokeView ).to.instanceOf( View );
|
|
|
|
|
+ expect( view.keystrokeView.element.textContent ).to.equal( 'Ctrl+A' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'usese fancy kesytroke preview on Mac', () => {
|
|
|
|
|
+ testUtils.sinon.stub( env, 'isMac' ).value( true );
|
|
|
|
|
+
|
|
|
|
|
+ view = new ButtonView( locale );
|
|
|
|
|
+ view.keystroke = 'Ctrl+A';
|
|
|
|
|
+ view.withKeystroke = true;
|
|
|
|
|
+ view.render();
|
|
|
|
|
+
|
|
|
|
|
+ expect( view.keystrokeView.element.textContent ).to.equal( '⌘A' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'is destroyed with the view', () => {
|
|
|
|
|
+ view = new ButtonView( locale );
|
|
|
|
|
+ view.keystroke = 'Ctrl+A';
|
|
|
|
|
+ view.withKeystroke = true;
|
|
|
|
|
+ view.render();
|
|
|
|
|
+
|
|
|
|
|
+ const spy = sinon.spy( view.keystrokeView, 'destroy' );
|
|
|
|
|
+
|
|
|
|
|
+ view.destroy();
|
|
|
|
|
+ sinon.assert.calledOnce( spy );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
describe( 'focus()', () => {
|
|
describe( 'focus()', () => {
|
|
|
it( 'focuses the button in DOM', () => {
|
|
it( 'focuses the button in DOM', () => {
|
|
|
const spy = sinon.spy( view.element, 'focus' );
|
|
const spy = sinon.spy( view.element, 'focus' );
|