/** * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ import LinkActionsView from '../../src/ui/linkactionsview'; import View from '@ckeditor/ckeditor5-ui/src/view'; import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard'; import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler'; import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker'; import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler'; import ViewCollection from '@ckeditor/ckeditor5-ui/src/viewcollection'; import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; testUtils.createSinonSandbox(); describe( 'LinkActionsView', () => { let view; beforeEach( () => { view = new LinkActionsView( { t: val => val } ); view.render(); } ); describe( 'constructor()', () => { it( 'should create element from template', () => { expect( view.element.classList.contains( 'ck' ) ).to.true; expect( view.element.classList.contains( 'ck-link-actions' ) ).to.true; expect( view.element.getAttribute( 'tabindex' ) ).to.equal( '-1' ); } ); it( 'should create child views', () => { expect( view.previewButtonView ).to.be.instanceOf( View ); expect( view.unlinkButtonView ).to.be.instanceOf( View ); expect( view.editButtonView ).to.be.instanceOf( View ); expect( view._unboundChildren.get( 0 ) ).to.equal( view.previewButtonView ); expect( view._unboundChildren.get( 1 ) ).to.equal( view.editButtonView ); expect( view._unboundChildren.get( 2 ) ).to.equal( view.unlinkButtonView ); } ); it( 'should create #focusTracker instance', () => { expect( view.focusTracker ).to.be.instanceOf( FocusTracker ); } ); it( 'should create #keystrokes instance', () => { expect( view.keystrokes ).to.be.instanceOf( KeystrokeHandler ); } ); it( 'should create #_focusCycler instance', () => { expect( view._focusCycler ).to.be.instanceOf( FocusCycler ); } ); it( 'should create #_focusables view collection', () => { expect( view._focusables ).to.be.instanceOf( ViewCollection ); } ); it( 'should fire `edit` event on editButtonView#execute', () => { const spy = sinon.spy(); view.on( 'edit', spy ); view.editButtonView.fire( 'execute' ); expect( spy.calledOnce ).to.true; } ); it( 'should fire `unlink` event on unlinkButtonView#execute', () => { const spy = sinon.spy(); view.on( 'unlink', spy ); view.unlinkButtonView.fire( 'execute' ); expect( spy.calledOnce ).to.true; } ); describe( 'preview button view', () => { it( 'is an anchor', () => { expect( view.previewButtonView.element.tagName.toLowerCase() ).to.equal( 'a' ); } ); it( 'has a CSS class', () => { expect( view.previewButtonView.element.classList.contains( 'ck-link-actions__preview' ) ).to.be.true; } ); it( 'has a target attribute', () => { expect( view.previewButtonView.element.getAttribute( 'target' ) ).to.equal( '_blank' ); } ); describe( '