8
0

linkformview.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import View from 'ckeditor5-ui/src/view';
  6. import LinkFormView from 'ckeditor5-link/src/ui/linkformview';
  7. describe( 'LinkFormView', () => {
  8. let view;
  9. beforeEach( () => {
  10. view = new LinkFormView( { t: () => {} } );
  11. view.init();
  12. } );
  13. describe( 'constructor()', () => {
  14. it( 'should create element from template', () => {
  15. expect( view.element.classList.contains( 'ck-link-form' ) ).to.true;
  16. } );
  17. it( 'should create child views', () => {
  18. expect( view.urlInputView ).to.be.instanceOf( View );
  19. expect( view.saveButtonView ).to.be.instanceOf( View );
  20. expect( view.cancelButtonView ).to.be.instanceOf( View );
  21. expect( view.unlinkButtonView ).to.be.instanceOf( View );
  22. expect( view._unboundChildren.get( 0 ) ).to.equal( view.urlInputView );
  23. expect( view._unboundChildren.get( 1 ) ).to.equal( view.saveButtonView );
  24. expect( view._unboundChildren.get( 2 ) ).to.equal( view.cancelButtonView );
  25. expect( view._unboundChildren.get( 3 ) ).to.equal( view.unlinkButtonView );
  26. } );
  27. it( 'should fire `cancel` event on cancelButtonView#execute', () => {
  28. const spy = sinon.spy();
  29. view.on( 'cancel', spy );
  30. view.cancelButtonView.fire( 'execute' );
  31. expect( spy.calledOnce ).to.true;
  32. } );
  33. it( 'should fire `unlink` event on unlinkButtonView#execute', () => {
  34. const spy = sinon.spy();
  35. view.on( 'unlink', spy );
  36. view.unlinkButtonView.fire( 'execute' );
  37. expect( spy.calledOnce ).to.true;
  38. } );
  39. describe( 'template', () => {
  40. it( 'has url input view', () => {
  41. expect( view.template.children.get( 0 ) ).to.equal( view.urlInputView );
  42. } );
  43. it( 'has form actions container', () => {
  44. expect( view.template.children.get( 1 ).attributes.class ).to.have.members( [ 'ck-link-form__actions' ] );
  45. } );
  46. it( 'has form action views', () => {
  47. const actions = view.template.children.get( 1 ).children;
  48. expect( actions.get( 0 ) ).to.equal( view.saveButtonView );
  49. expect( actions.get( 1 ) ).to.equal( view.cancelButtonView );
  50. expect( actions.get( 2 ) ).to.equal( view.unlinkButtonView );
  51. } );
  52. } );
  53. } );
  54. describe( 'DOM bindings', () => {
  55. describe( 'submit event', () => {
  56. it( 'should trigger submit event', () => {
  57. const spy = sinon.spy();
  58. view.on( 'submit', spy );
  59. view.element.dispatchEvent( new Event( 'submit' ) );
  60. expect( spy.calledOnce ).to.true;
  61. } );
  62. } );
  63. } );
  64. } );