linkform.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 LinkForm from '/ckeditor5/link/ui/linkform.js';
  7. import LinkFormView from '/ckeditor5/link/ui/linkformview.js';
  8. import Model from '/ckeditor5/ui/model.js';
  9. import Button from '/ckeditor5/ui/button/button.js';
  10. import LabeledInput from '/ckeditor5/ui/labeledinput/labeledinput.js';
  11. describe( 'LinkForm', () => {
  12. let linkForm, view, model;
  13. beforeEach( () => {
  14. view = new LinkFormView( {
  15. t: () => {}
  16. } );
  17. model = new Model( {
  18. url: 'foo'
  19. } );
  20. linkForm = new LinkForm( model, view );
  21. } );
  22. describe( 'constructor', () => {
  23. it( 'creates view#submit -> model#submit binding', () => {
  24. const spy = sinon.spy();
  25. model.on( 'submit', spy );
  26. view.fire( 'submit' );
  27. expect( spy.calledOnce ).to.be.true;
  28. } );
  29. } );
  30. describe( 'child components', () => {
  31. describe( 'urlInput', () => {
  32. it( 'is created', () => {
  33. expect( linkForm.urlInput ).to.be.instanceOf( LabeledInput );
  34. } );
  35. it( 'belongs to anonymous collection', () => {
  36. expect( linkForm.collections.get( '$anonymous' ).find( ( item ) => {
  37. return item === linkForm.urlInput;
  38. } ) ).to.be.not.undefined;
  39. } );
  40. it( 'binds urlInput.model#value to linkForm.model#url', () => {
  41. expect( linkForm.urlInput.model.value ).to.equal( 'foo' );
  42. model.url = 'bar';
  43. expect( linkForm.urlInput.model.value ).to.equal( 'bar' );
  44. } );
  45. } );
  46. describe( 'saveButton', () => {
  47. it( 'is created', () => {
  48. expect( linkForm.saveButton ).to.be.instanceOf( Button );
  49. } );
  50. it( 'belongs to anonymous collection', () => {
  51. expect( linkForm.collections.get( '$anonymous' ).find( ( item ) => {
  52. return item === linkForm.saveButton;
  53. } ) ).to.be.not.undefined;
  54. } );
  55. } );
  56. describe( 'cancelButton', () => {
  57. it( 'is created', () => {
  58. expect( linkForm.cancelButton ).to.be.instanceOf( Button );
  59. } );
  60. it( 'belongs to anonymous collection', () => {
  61. expect( linkForm.collections.get( '$anonymous' ).find( ( item ) => {
  62. return item === linkForm.cancelButton;
  63. } ) ).to.be.not.undefined;
  64. } );
  65. it( 'passes cancelButton.model#execute as linkForm.model#cancel', ( done ) => {
  66. model.on( 'cancel', () => {
  67. done();
  68. } );
  69. linkForm.cancelButton.model.fire( 'execute' );
  70. } );
  71. } );
  72. describe( 'unlinkButton', () => {
  73. it( 'is created', () => {
  74. expect( linkForm.unlinkButton ).to.be.instanceOf( Button );
  75. } );
  76. it( 'belongs to anonymous collection', () => {
  77. expect( linkForm.collections.get( '$anonymous' ).find( ( item ) => {
  78. return item === linkForm.unlinkButton;
  79. } ) ).to.be.not.undefined;
  80. } );
  81. it( 'passes unlinkButton.model#execute as linkForm.model#unlink', ( done ) => {
  82. model.on( 'unlink', () => {
  83. done();
  84. } );
  85. linkForm.unlinkButton.model.fire( 'execute' );
  86. } );
  87. } );
  88. } );
  89. } );