marginstyles.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import Styles from '../../../src/view/styles';
  6. describe( 'Margin styles normalizer', () => {
  7. let styles;
  8. beforeEach( () => {
  9. styles = new Styles();
  10. } );
  11. it( 'should set all margins (1 value defined)', () => {
  12. styles.setStyle( 'margin:1px;' );
  13. expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
  14. top: '1px',
  15. right: '1px',
  16. bottom: '1px',
  17. left: '1px'
  18. } );
  19. } );
  20. it( 'should set all margins (2 values defined)', () => {
  21. styles.setStyle( 'margin:1px .34cm;' );
  22. expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
  23. top: '1px',
  24. right: '.34cm',
  25. bottom: '1px',
  26. left: '.34cm'
  27. } );
  28. } );
  29. it( 'should set all margins (3 values defined)', () => {
  30. styles.setStyle( 'margin:1px .34cm 90.1rem;' );
  31. expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
  32. top: '1px',
  33. right: '.34cm',
  34. bottom: '90.1rem',
  35. left: '.34cm'
  36. } );
  37. } );
  38. it( 'should set all margins (4 values defined)', () => {
  39. styles.setStyle( 'margin:1px .34cm 90.1rem thick;' );
  40. expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
  41. top: '1px',
  42. right: '.34cm',
  43. bottom: '90.1rem',
  44. left: 'thick'
  45. } );
  46. } );
  47. it( 'should output inline style (1 value defined)', () => {
  48. styles.setStyle( 'margin:1px;' );
  49. expect( styles.getInlineStyle() ).to.equal( 'margin:1px;' );
  50. expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px' );
  51. expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
  52. expect( styles.getInlineProperty( 'margin-right' ) ).to.equal( '1px' );
  53. expect( styles.getInlineProperty( 'margin-bottom' ) ).to.equal( '1px' );
  54. expect( styles.getInlineProperty( 'margin-left' ) ).to.equal( '1px' );
  55. } );
  56. it( 'should output inline style (2 values defined)', () => {
  57. styles.setStyle( 'margin:1px .34cm;' );
  58. expect( styles.getInlineStyle() ).to.equal( 'margin:1px .34cm;' );
  59. expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px .34cm' );
  60. expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
  61. expect( styles.getInlineProperty( 'margin-right' ) ).to.equal( '.34cm' );
  62. expect( styles.getInlineProperty( 'margin-bottom' ) ).to.equal( '1px' );
  63. expect( styles.getInlineProperty( 'margin-left' ) ).to.equal( '.34cm' );
  64. } );
  65. it( 'should output inline style (3 values defined)', () => {
  66. styles.setStyle( 'margin:1px .34cm 90.1rem;' );
  67. expect( styles.getInlineStyle() ).to.equal( 'margin:1px .34cm 90.1rem;' );
  68. expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px .34cm 90.1rem' );
  69. expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
  70. expect( styles.getInlineProperty( 'margin-right' ) ).to.equal( '.34cm' );
  71. expect( styles.getInlineProperty( 'margin-bottom' ) ).to.equal( '90.1rem' );
  72. expect( styles.getInlineProperty( 'margin-left' ) ).to.equal( '.34cm' );
  73. } );
  74. it( 'should output inline style (3 values defined, only last different)', () => {
  75. styles.setStyle( 'margin:1px 1px 90.1rem;' );
  76. expect( styles.getInlineStyle() ).to.equal( 'margin:1px 1px 90.1rem;' );
  77. expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px 1px 90.1rem' );
  78. expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
  79. expect( styles.getInlineProperty( 'margin-right' ) ).to.equal( '1px' );
  80. expect( styles.getInlineProperty( 'margin-bottom' ) ).to.equal( '90.1rem' );
  81. expect( styles.getInlineProperty( 'margin-left' ) ).to.equal( '1px' );
  82. } );
  83. it( 'should output inline style (4 values defined)', () => {
  84. styles.setStyle( 'margin:1px .34cm 90.1rem thick;' );
  85. expect( styles.getInlineStyle() ).to.equal( 'margin:1px .34cm 90.1rem thick;' );
  86. expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px .34cm 90.1rem thick' );
  87. expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
  88. expect( styles.getInlineProperty( 'margin-right' ) ).to.equal( '.34cm' );
  89. expect( styles.getInlineProperty( 'margin-bottom' ) ).to.equal( '90.1rem' );
  90. expect( styles.getInlineProperty( 'margin-left' ) ).to.equal( 'thick' );
  91. } );
  92. it( 'should output inline style (4 values defined, only last different)', () => {
  93. styles.setStyle( 'margin:1px 1px 1px thick;' );
  94. expect( styles.getInlineStyle() ).to.equal( 'margin:1px 1px 1px thick;' );
  95. expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px 1px 1px thick' );
  96. expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
  97. expect( styles.getInlineProperty( 'margin-right' ) ).to.equal( '1px' );
  98. expect( styles.getInlineProperty( 'margin-bottom' ) ).to.equal( '1px' );
  99. expect( styles.getInlineProperty( 'margin-left' ) ).to.equal( 'thick' );
  100. } );
  101. describe( 'margin-*', () => {
  102. it( 'should set proper margin', () => {
  103. styles.setStyle( 'margin-top:1px;' );
  104. expect( styles.getNormalized( 'margin' ) ).to.deep.equal( { top: '1px' } );
  105. expect( styles.getNormalized( 'margin-top' ) ).to.equal( '1px' );
  106. } );
  107. it( 'should merge margin with margin shorthand', () => {
  108. styles.setStyle( 'margin: 2em;margin-top:1px;' );
  109. expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
  110. top: '1px',
  111. right: '2em',
  112. bottom: '2em',
  113. left: '2em'
  114. } );
  115. expect( styles.getNormalized( 'margin-top' ) ).to.equal( '1px' );
  116. expect( styles.getNormalized( 'margin-right' ) ).to.equal( '2em' );
  117. expect( styles.getNormalized( 'margin-bottom' ) ).to.equal( '2em' );
  118. expect( styles.getNormalized( 'margin-left' ) ).to.equal( '2em' );
  119. } );
  120. it( 'should output margin-top', () => {
  121. styles.setStyle( 'margin-top:1px;' );
  122. expect( styles.getInlineStyle() ).to.equal( 'margin-top:1px;' );
  123. expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
  124. } );
  125. it( 'should output margin-right', () => {
  126. styles.setStyle( 'margin-right:1px;' );
  127. expect( styles.getInlineStyle() ).to.equal( 'margin-right:1px;' );
  128. expect( styles.getInlineProperty( 'margin-right' ) ).to.equal( '1px' );
  129. } );
  130. it( 'should output margin-bottom', () => {
  131. styles.setStyle( 'margin-bottom:1px;' );
  132. expect( styles.getInlineStyle() ).to.equal( 'margin-bottom:1px;' );
  133. expect( styles.getInlineProperty( 'margin-bottom' ) ).to.equal( '1px' );
  134. } );
  135. it( 'should output margin-left', () => {
  136. styles.setStyle( 'margin-left:1px;' );
  137. expect( styles.getInlineStyle() ).to.equal( 'margin-left:1px;' );
  138. expect( styles.getInlineProperty( 'margin-left' ) ).to.equal( '1px' );
  139. } );
  140. } );
  141. } );