tooltipview.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import TooltipView from '../../src/tooltip/tooltipview';
  6. describe( 'TooltipView', () => {
  7. let view, text;
  8. beforeEach( () => {
  9. view = new TooltipView();
  10. view.render();
  11. text = view.element.firstChild;
  12. } );
  13. describe( 'constructor()', () => {
  14. it( 'should create element from template', () => {
  15. expect( view.element.tagName ).to.equal( 'SPAN' );
  16. expect( view.element.classList.contains( 'ck' ) ).to.be.true;
  17. expect( view.element.classList.contains( 'ck-tooltip' ) ).to.be.true;
  18. expect( view.element.childNodes ).to.have.length( 1 );
  19. expect( text.tagName ).to.equal( 'SPAN' );
  20. expect( text.classList.contains( 'ck' ) ).to.be.true;
  21. expect( text.classList.contains( 'ck-tooltip__text' ) ).to.be.true;
  22. } );
  23. it( 'should set default #position', () => {
  24. expect( view.position ).to.equal( 's' );
  25. } );
  26. } );
  27. describe( 'DOM bindings', () => {
  28. beforeEach( () => {
  29. view.text = 'foo';
  30. } );
  31. describe( 'text content', () => {
  32. it( 'should react on view#text', () => {
  33. expect( text.textContent ).to.equal( 'foo' );
  34. view.text = 'baz';
  35. expect( text.textContent ).to.equal( 'baz' );
  36. } );
  37. } );
  38. describe( 'class', () => {
  39. it( 'should react on view#text', () => {
  40. expect( view.element.classList.contains( 'ck-hidden' ) ).to.be.false;
  41. view.text = '';
  42. expect( view.element.classList.contains( 'ck-hidden' ) ).to.be.true;
  43. } );
  44. it( 'should react on view#position', () => {
  45. expect( view.element.classList.contains( 'ck-tooltip_n' ) ).to.be.false;
  46. expect( view.element.classList.contains( 'ck-tooltip_s' ) ).to.be.true;
  47. view.position = 'n';
  48. expect( view.element.classList.contains( 'ck-tooltip_n' ) ).to.be.true;
  49. expect( view.element.classList.contains( 'ck-tooltip_s' ) ).to.be.false;
  50. } );
  51. } );
  52. } );
  53. } );