8
0

padding.js 6.5 KB

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