linkballoonpanel.js 4.6 KB

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