linkballoonpanel.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: ui, link */
  6. import LinkBalloonPanel from '/ckeditor5/link/ui/linkballoonpanel.js';
  7. import LinkBalloonPanelView from '/ckeditor5/link/ui/linkballoonpanelview.js';
  8. import BalloonPanel from '/ckeditor5/ui/balloonpanel/balloonpanel.js';
  9. import Model from '/ckeditor5/ui/model.js';
  10. import Form from '/ckeditor5/ui/form/form.js';
  11. import LabeledInput from '/ckeditor5/ui/labeledinput/labeledinput.js';
  12. import Button from '/ckeditor5/ui/button/button.js';
  13. import LocaleMock from '/tests/utils/_utils/locale-mock.js';
  14. describe( 'LinkBalloonPanel', () => {
  15. let model, linkBalloonPanel, view;
  16. beforeEach( () => {
  17. model = new Model( {
  18. maxWidth: 200,
  19. url: 'http://ckeditor.com'
  20. } );
  21. view = new LinkBalloonPanelView( new LocaleMock() );
  22. linkBalloonPanel = new LinkBalloonPanel( model, view );
  23. } );
  24. describe( 'constructor', () => {
  25. it( 'should extend BalloonPanel class', () => {
  26. expect( linkBalloonPanel ).to.be.instanceOf( BalloonPanel );
  27. } );
  28. describe( 'child components', () => {
  29. describe( 'form', () => {
  30. it( 'should create Form instance', () => {
  31. expect( linkBalloonPanel.form ).to.instanceof( Form );
  32. } );
  33. it( 'should append to "content" collection', () => {
  34. expect( linkBalloonPanel.collections.get( 'content' ).get( 0 ) ).to.deep.equal( linkBalloonPanel.form );
  35. } );
  36. it( 'should delegate form.model#execute to the model', () => {
  37. const executeSpy = sinon.spy();
  38. model.on( 'execute', executeSpy );
  39. linkBalloonPanel.form.model.fire( 'execute' );
  40. expect( executeSpy.calledOnce ).to.true;
  41. } );
  42. } );
  43. describe( 'urlInput', () => {
  44. it( 'should create LabeledInput instance', () => {
  45. expect( linkBalloonPanel.urlInput ).to.instanceof( LabeledInput );
  46. } );
  47. it( 'should append to Form "content" collection', () => {
  48. expect( linkBalloonPanel.form.collections.get( 'content' ).get( 0 ) ).to.deep.equal( linkBalloonPanel.urlInput );
  49. } );
  50. it( 'should bind model#url to urlInput.model#value', () => {
  51. expect( linkBalloonPanel.urlInput.model.value ).to.equal( model.url ).to.equal( 'http://ckeditor.com' );
  52. model.url = 'http://cksource.com';
  53. expect( linkBalloonPanel.urlInput.model.value ).to.equal( 'http://cksource.com' );
  54. } );
  55. } );
  56. describe( 'saveButton', () => {
  57. it( 'should create Button instance', () => {
  58. expect( linkBalloonPanel.saveButton ).to.instanceof( Button );
  59. } );
  60. it( 'should trigger model#execute event after clicking', ( done ) => {
  61. const executeSpy = sinon.spy();
  62. model.on( 'execute', executeSpy );
  63. linkBalloonPanel.init().then( () => {
  64. linkBalloonPanel.saveButton.view.element.click();
  65. expect( executeSpy.calledOnce ).to.true;
  66. done();
  67. } );
  68. } );
  69. it( 'should be a submit', () => {
  70. expect( linkBalloonPanel.saveButton.model.type ).to.equal( 'submit' );
  71. } );
  72. } );
  73. describe( 'cancelButton', () => {
  74. it( 'should create Button instance', () => {
  75. expect( linkBalloonPanel.cancelButton ).to.instanceof( Button );
  76. } );
  77. it( 'should hide LinkBalloonPanel on cancelButton.model#execute event', () => {
  78. const hideSpy = sinon.spy( linkBalloonPanel.view, 'hide' );
  79. linkBalloonPanel.cancelButton.model.fire( 'execute' );
  80. expect( hideSpy.calledOnce ).to.true;
  81. } );
  82. } );
  83. } );
  84. } );
  85. } );