linkformview.js 2.5 KB

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