8
0

linkballoonpanel.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. 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 LinkForm from '/ckeditor5/link/ui/linkform.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 be created', () => {
  31. expect( linkBalloonPanel.form ).to.instanceof( LinkForm );
  32. } );
  33. it( 'should be appended to "content" collection', () => {
  34. expect( linkBalloonPanel.collections.get( 'content' ).get( 0 ) ).to.deep.equal( linkBalloonPanel.form );
  35. } );
  36. it( 'should fire model#executeLink event on form.model#execute event', () => {
  37. const executeSpy = sinon.spy();
  38. model.on( 'executeLink', executeSpy );
  39. linkBalloonPanel.form.model.fire( 'execute' );
  40. expect( executeSpy.calledOnce ).to.true;
  41. } );
  42. } );
  43. describe( 'urlInput', () => {
  44. it( 'should be created', () => {
  45. expect( linkBalloonPanel.urlInput ).to.instanceof( LabeledInput );
  46. } );
  47. it( 'should be appended to the 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 be created', () => {
  58. expect( linkBalloonPanel.saveButton ).to.instanceof( Button );
  59. } );
  60. it( 'should be appended to the form "actions" collection', () => {
  61. expect( linkBalloonPanel.form.collections.get( 'actions' ).get( 0 ) ).to.deep.equal( linkBalloonPanel.saveButton );
  62. } );
  63. it( 'should fire model#executeLink event on DOM click event', ( done ) => {
  64. const executeSpy = sinon.spy();
  65. model.on( 'executeLink', executeSpy );
  66. linkBalloonPanel.init().then( () => {
  67. linkBalloonPanel.saveButton.view.element.click();
  68. expect( executeSpy.calledOnce ).to.true;
  69. done();
  70. } );
  71. } );
  72. it( 'should be a type `submit`', () => {
  73. expect( linkBalloonPanel.saveButton.model.type ).to.equal( 'submit' );
  74. } );
  75. } );
  76. describe( 'cancelButton', () => {
  77. it( 'should be created', () => {
  78. expect( linkBalloonPanel.cancelButton ).to.instanceof( Button );
  79. } );
  80. it( 'should be appended to the form "actions" collection', () => {
  81. expect( linkBalloonPanel.form.collections.get( 'actions' ).get( 1 ) ).to.deep.equal( linkBalloonPanel.cancelButton );
  82. } );
  83. it( 'should fire model#executeCancel event on cancelButton.model#execute event', () => {
  84. const executeSpy = sinon.spy();
  85. model.on( 'executeCancel', executeSpy );
  86. linkBalloonPanel.cancelButton.model.fire( 'execute' );
  87. expect( executeSpy.calledOnce ).to.true;
  88. } );
  89. } );
  90. describe( 'unlinkButton', () => {
  91. it( 'should be created', () => {
  92. expect( linkBalloonPanel.unlinkButton ).to.instanceof( Button );
  93. } );
  94. it( 'should be appended to the form "actions" collection', () => {
  95. expect( linkBalloonPanel.form.collections.get( 'actions' ).get( 2 ) ).to.deep.equal( linkBalloonPanel.unlinkButton );
  96. } );
  97. it( 'should fire model#executeUnlink event on unlinkButton.model#execute event', () => {
  98. const executeUnlinkSpy = sinon.spy();
  99. model.on( 'executeUnlink', executeUnlinkSpy );
  100. linkBalloonPanel.unlinkButton.model.fire( 'execute' );
  101. expect( executeUnlinkSpy.calledOnce ).to.true;
  102. } );
  103. } );
  104. } );
  105. } );
  106. } );