8
0

styles.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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 StyleProxy from '../../src/view/styles';
  6. describe( 'Styles', () => {
  7. let styles;
  8. beforeEach( () => {
  9. styles = new StyleProxy();
  10. } );
  11. describe( 'size getter', () => {
  12. it( 'should return 0 if no styles are set', () => {
  13. expect( styles.size ).to.equal( 0 );
  14. } );
  15. it( 'should return number of set styles', () => {
  16. styles.setStyle( 'color:blue' );
  17. expect( styles.size ).to.equal( 1 );
  18. styles.setStyle( 'margin:1px;' );
  19. expect( styles.size ).to.equal( 1 );
  20. styles.setStyle( 'margin-top:1px;margin-bottom:1px;' );
  21. expect( styles.size ).to.equal( 2 );
  22. } );
  23. } );
  24. describe( 'setStyle()', () => {
  25. it( 'should reset styles to a new value', () => {
  26. styles.setStyle( 'color:red;margin-top:1px;' );
  27. expect( styles.getNormalized() ).to.deep.equal( { color: 'red', margin: { top: '1px' } } );
  28. styles.setStyle( 'margin-bottom:2em;' );
  29. expect( styles.getNormalized() ).to.deep.equal( { margin: { bottom: '2em' } } );
  30. } );
  31. } );
  32. describe( 'getInlineStyle()', () => {
  33. it( 'should return undefined for empty styles', () => {
  34. expect( styles.getInlineStyle() ).to.be.undefined;
  35. } );
  36. it( 'should return sorted styles string if styles are set', () => {
  37. styles.setStyle( 'margin-top:1px;color:blue;' );
  38. expect( styles.getInlineStyle() ).to.equal( 'color:blue;margin-top:1px;' );
  39. } );
  40. } );
  41. describe( 'getInlineProperty', () => {
  42. it( 'should return empty string for missing shorthand', () => {
  43. styles.setStyle( 'margin-top:1px' );
  44. expect( styles.getInlineProperty( 'margin' ) ).to.be.undefined;
  45. } );
  46. } );
  47. describe( 'hasProperty()', () => {
  48. it( 'should return false if property is not set', () => {
  49. expect( styles.hasProperty( 'foo' ) ).to.be.false;
  50. } );
  51. it( 'should return false if normalized property is not set', () => {
  52. styles.setStyle( 'margin-top:1px' );
  53. // TODO
  54. // expect( styles.hasProperty( 'margin' ) ).to.be.false;
  55. expect( styles.hasProperty( 'margin' ) ).to.be.true;
  56. } );
  57. it( 'should return true if property is set', () => {
  58. styles.setStyle( 'color:deeppink' );
  59. expect( styles.hasProperty( 'color' ) ).to.be.true;
  60. } );
  61. it( 'should return true if normalized shorthanded property is set', () => {
  62. styles.setStyle( 'margin:1px 2px 3px 4px' );
  63. expect( styles.hasProperty( 'margin-top' ) ).to.be.true;
  64. } );
  65. } );
  66. describe( 'insertProperty()', () => {
  67. it( 'should insert new property (empty styles)', () => {
  68. styles.insertProperty( 'color', 'blue' );
  69. expect( styles.getInlineProperty( 'color' ) ).to.equal( 'blue' );
  70. } );
  71. it( 'should insert new property (other properties are set)', () => {
  72. styles.setStyle( 'margin: 1px;' );
  73. styles.insertProperty( 'color', 'blue' );
  74. expect( styles.getInlineProperty( 'color' ) ).to.equal( 'blue' );
  75. } );
  76. it( 'should overwrite property', () => {
  77. styles.setStyle( 'color: red;' );
  78. styles.insertProperty( 'color', 'blue' );
  79. expect( styles.getInlineProperty( 'color' ) ).to.equal( 'blue' );
  80. } );
  81. it( 'should work with objects', () => {
  82. styles.setStyle( 'color: red;' );
  83. styles.insertProperty( { color: 'blue', margin: '1px' } );
  84. expect( styles.getInlineProperty( 'color' ) ).to.equal( 'blue' );
  85. expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
  86. } );
  87. } );
  88. describe( 'removeProperty()', () => {
  89. it( 'should do nothing if property is not set', () => {
  90. styles.removeProperty( 'color' );
  91. expect( styles.getInlineProperty( 'color' ) ).to.be.undefined;
  92. } );
  93. it( 'should insert new property (other properties are set)', () => {
  94. styles.setStyle( 'color:blue' );
  95. styles.removeProperty( 'color' );
  96. expect( styles.getInlineProperty( 'color' ) ).to.be.undefined;
  97. } );
  98. it( 'should remove normalized property', () => {
  99. styles.setStyle( 'margin:1px' );
  100. styles.removeProperty( 'margin-top' );
  101. expect( styles.getInlineProperty( 'margin-top' ) ).to.be.undefined;
  102. } );
  103. } );
  104. describe( 'getStyleNames()', () => {
  105. it( 'should output empty array for empty styles', () => {
  106. expect( styles.getStyleNames() ).to.deep.equal( [] );
  107. } );
  108. it( 'should output custom style names', () => {
  109. styles.setStyle( 'foo: 2;bar: baz;foo-bar-baz:none;' );
  110. expect( styles.getStyleNames() ).to.deep.equal( [ 'bar', 'foo', 'foo-bar-baz' ] );
  111. } );
  112. it( 'should output full names for known style names', () => {
  113. styles.setStyle( 'margin: 1px;margin-left: 2em;' );
  114. expect( styles.getStyleNames() ).to.deep.equal( [ 'margin' ] );
  115. } );
  116. } );
  117. describe( 'styles rules', () => {
  118. describe( 'border', () => {
  119. it( 'should parse border shorthand', () => {
  120. styles.setStyle( 'border:1px solid blue;' );
  121. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  122. color: { top: 'blue', right: 'blue', bottom: 'blue', left: 'blue' },
  123. style: { top: 'solid', right: 'solid', bottom: 'solid', left: 'solid' },
  124. width: { top: '1px', right: '1px', bottom: '1px', left: '1px' }
  125. } );
  126. } );
  127. it( 'should parse border shorthand with other shorthands', () => {
  128. styles.setStyle( 'border:1px solid blue;border-left:#665511 dashed 2.7em;border-top:7px dotted #ccc;' );
  129. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  130. color: { top: '#ccc', right: 'blue', bottom: 'blue', left: '#665511' },
  131. style: { top: 'dotted', right: 'solid', bottom: 'solid', left: 'dashed' },
  132. width: { top: '7px', right: '1px', bottom: '1px', left: '2.7em' }
  133. } );
  134. } );
  135. it( 'should output inline shorthand rules #1', () => {
  136. styles.setStyle( 'border:1px solid blue;' );
  137. expect( styles.getInlineStyle() ).to.equal( 'border-color:blue;border-style:solid;border-width:1px;' );
  138. expect( styles.getInlineProperty( 'border-color' ) ).to.equal( 'blue' );
  139. expect( styles.getInlineProperty( 'border-style' ) ).to.equal( 'solid' );
  140. expect( styles.getInlineProperty( 'border-width' ) ).to.equal( '1px' );
  141. } );
  142. it( 'should output inline shorthand rules #2', () => {
  143. styles.setStyle( 'border:1px solid blue;border-left:#665511 dashed 2.7em;border-top:7px dotted #ccc;' );
  144. expect( styles.getInlineStyle() ).to.equal(
  145. 'border-color:#ccc blue blue #665511;border-style:dotted solid solid dashed;border-width:7px 1px 1px 2.7em;'
  146. );
  147. // todo expect( styles.getInlineProperty( 'border' ) ).to.be.undefined;
  148. expect( styles.getInlineProperty( 'border-color' ) ).to.equal( '#ccc blue blue #665511' );
  149. expect( styles.getInlineProperty( 'border-style' ) ).to.equal( 'dotted solid solid dashed' );
  150. expect( styles.getInlineProperty( 'border-width' ) ).to.equal( '7px 1px 1px 2.7em' );
  151. } );
  152. it( 'should merge rules on insert other shorthand', () => {
  153. styles.setStyle( 'border:1px solid blue;' );
  154. styles.insertProperty( 'border-left', '#665511 dashed 2.7em' );
  155. styles.insertProperty( 'border-top', '7px dotted #ccc' );
  156. expect( styles.getInlineStyle() ).to.equal(
  157. 'border-color:#ccc blue blue #665511;border-style:dotted solid solid dashed;border-width:7px 1px 1px 2.7em;'
  158. );
  159. // expect( styles.getInlineProperty( 'border' ) ).to.be.undefined;
  160. expect( styles.getInlineProperty( 'border-color' ) ).to.equal( '#ccc blue blue #665511' );
  161. expect( styles.getInlineProperty( 'border-style' ) ).to.equal( 'dotted solid solid dashed' );
  162. expect( styles.getInlineProperty( 'border-width' ) ).to.equal( '7px 1px 1px 2.7em' );
  163. } );
  164. it( 'should output', () => {
  165. styles.setStyle( 'border:1px solid blue;' );
  166. styles.removeProperty( 'border-color' );
  167. expect( styles.getInlineStyle() ).to.equal(
  168. 'border-style:solid;border-width:1px;'
  169. );
  170. // expect( styles.getInlineProperty( 'border' ) ).to.be.undefined;
  171. expect( styles.getInlineProperty( 'border-color' ) ).to.be.undefined;
  172. expect( styles.getInlineProperty( 'border-style' ) ).to.equal( 'solid' );
  173. expect( styles.getInlineProperty( 'border-width' ) ).to.equal( '1px' );
  174. } );
  175. describe( 'border-color', () => {
  176. it( 'should set all border colors (1 value defined)', () => {
  177. styles.setStyle( 'border-color:cyan;' );
  178. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  179. color: {
  180. top: 'cyan',
  181. right: 'cyan',
  182. bottom: 'cyan',
  183. left: 'cyan'
  184. }
  185. } );
  186. } );
  187. it( 'should set all border colors (2 values defined)', () => {
  188. styles.setStyle( 'border-color:cyan magenta;' );
  189. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  190. color: {
  191. top: 'cyan',
  192. right: 'magenta',
  193. bottom: 'cyan',
  194. left: 'magenta'
  195. }
  196. } );
  197. } );
  198. it( 'should set all border colors (3 values defined)', () => {
  199. styles.setStyle( 'border-color:cyan magenta pink;' );
  200. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  201. color: {
  202. top: 'cyan',
  203. right: 'magenta',
  204. bottom: 'pink',
  205. left: 'magenta'
  206. }
  207. } );
  208. } );
  209. it( 'should set all border colors (4 values defined)', () => {
  210. styles.setStyle( 'border-color:cyan magenta pink beige;' );
  211. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  212. color: {
  213. top: 'cyan',
  214. right: 'magenta',
  215. bottom: 'pink',
  216. left: 'beige'
  217. }
  218. } );
  219. } );
  220. it( 'should merge with border shorthand', () => {
  221. styles.setStyle( 'border:1px solid blue;border-color:cyan black;' );
  222. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  223. color: { top: 'cyan', right: 'black', bottom: 'cyan', left: 'black' },
  224. style: { top: 'solid', right: 'solid', bottom: 'solid', left: 'solid' },
  225. width: { top: '1px', right: '1px', bottom: '1px', left: '1px' }
  226. } );
  227. } );
  228. } );
  229. describe( 'border-style', () => {
  230. it( 'should set all border styles (1 value defined)', () => {
  231. styles.setStyle( 'border-style:solid;' );
  232. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  233. style: {
  234. top: 'solid',
  235. right: 'solid',
  236. bottom: 'solid',
  237. left: 'solid'
  238. }
  239. } );
  240. } );
  241. it( 'should set all border styles (2 values defined)', () => {
  242. styles.setStyle( 'border-style:solid dotted;' );
  243. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  244. style: {
  245. top: 'solid',
  246. right: 'dotted',
  247. bottom: 'solid',
  248. left: 'dotted'
  249. }
  250. } );
  251. } );
  252. it( 'should set all border styles (3 values defined)', () => {
  253. styles.setStyle( 'border-style:solid dotted dashed;' );
  254. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  255. style: {
  256. top: 'solid',
  257. right: 'dotted',
  258. bottom: 'dashed',
  259. left: 'dotted'
  260. }
  261. } );
  262. } );
  263. it( 'should set all border styles (4 values defined)', () => {
  264. styles.setStyle( 'border-style:solid dotted dashed ridge;' );
  265. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  266. style: {
  267. top: 'solid',
  268. right: 'dotted',
  269. bottom: 'dashed',
  270. left: 'ridge'
  271. }
  272. } );
  273. } );
  274. } );
  275. describe( 'border-width', () => {
  276. it( 'should set all border widths (1 value defined)', () => {
  277. styles.setStyle( 'border-width:1px;' );
  278. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  279. width: {
  280. top: '1px',
  281. right: '1px',
  282. bottom: '1px',
  283. left: '1px'
  284. }
  285. } );
  286. } );
  287. it( 'should set all border widths (2 values defined)', () => {
  288. styles.setStyle( 'border-width:1px .34cm;' );
  289. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  290. width: {
  291. top: '1px',
  292. right: '.34cm',
  293. bottom: '1px',
  294. left: '.34cm'
  295. }
  296. } );
  297. } );
  298. it( 'should set all border widths (3 values defined)', () => {
  299. styles.setStyle( 'border-width:1px .34cm 90.1rem;' );
  300. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  301. width: {
  302. top: '1px',
  303. right: '.34cm',
  304. bottom: '90.1rem',
  305. left: '.34cm'
  306. }
  307. } );
  308. } );
  309. it( 'should set all border widths (4 values defined)', () => {
  310. styles.setStyle( 'border-width:1px .34cm 90.1rem thick;' );
  311. expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
  312. width: {
  313. top: '1px',
  314. right: '.34cm',
  315. bottom: '90.1rem',
  316. left: 'thick'
  317. }
  318. } );
  319. } );
  320. } );
  321. } );
  322. describe( 'margin', () => {
  323. it( 'should set all margins (1 value defined)', () => {
  324. styles.setStyle( 'margin:1px;' );
  325. expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
  326. top: '1px',
  327. right: '1px',
  328. bottom: '1px',
  329. left: '1px'
  330. } );
  331. } );
  332. it( 'should set all margins (2 values defined)', () => {
  333. styles.setStyle( 'margin:1px .34cm;' );
  334. expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
  335. top: '1px',
  336. right: '.34cm',
  337. bottom: '1px',
  338. left: '.34cm'
  339. } );
  340. } );
  341. it( 'should set all margins (3 values defined)', () => {
  342. styles.setStyle( 'margin:1px .34cm 90.1rem;' );
  343. expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
  344. top: '1px',
  345. right: '.34cm',
  346. bottom: '90.1rem',
  347. left: '.34cm'
  348. } );
  349. } );
  350. it( 'should set all margins (4 values defined)', () => {
  351. styles.setStyle( 'margin:1px .34cm 90.1rem thick;' );
  352. expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
  353. top: '1px',
  354. right: '.34cm',
  355. bottom: '90.1rem',
  356. left: 'thick'
  357. } );
  358. } );
  359. it( 'should output inline style (1 value defined)', () => {
  360. styles.setStyle( 'margin:1px;' );
  361. expect( styles.getInlineStyle() ).to.equal( 'margin:1px;' );
  362. expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px' );
  363. expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
  364. expect( styles.getInlineProperty( 'margin-right' ) ).to.equal( '1px' );
  365. expect( styles.getInlineProperty( 'margin-bottom' ) ).to.equal( '1px' );
  366. expect( styles.getInlineProperty( 'margin-left' ) ).to.equal( '1px' );
  367. } );
  368. it( 'should output inline style (2 values defined)', () => {
  369. styles.setStyle( 'margin:1px .34cm;' );
  370. expect( styles.getInlineStyle() ).to.equal( 'margin:1px .34cm;' );
  371. expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px .34cm' );
  372. expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
  373. expect( styles.getInlineProperty( 'margin-right' ) ).to.equal( '.34cm' );
  374. expect( styles.getInlineProperty( 'margin-bottom' ) ).to.equal( '1px' );
  375. expect( styles.getInlineProperty( 'margin-left' ) ).to.equal( '.34cm' );
  376. } );
  377. it( 'should output inline style (3 values defined)', () => {
  378. styles.setStyle( 'margin:1px .34cm 90.1rem;' );
  379. expect( styles.getInlineStyle() ).to.equal( 'margin:1px .34cm 90.1rem;' );
  380. expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px .34cm 90.1rem' );
  381. expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
  382. expect( styles.getInlineProperty( 'margin-right' ) ).to.equal( '.34cm' );
  383. expect( styles.getInlineProperty( 'margin-bottom' ) ).to.equal( '90.1rem' );
  384. expect( styles.getInlineProperty( 'margin-left' ) ).to.equal( '.34cm' );
  385. } );
  386. it( 'should output inline style (3 values defined, only last different)', () => {
  387. styles.setStyle( 'margin:1px 1px 90.1rem;' );
  388. expect( styles.getInlineStyle() ).to.equal( 'margin:1px 1px 90.1rem;' );
  389. expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px 1px 90.1rem' );
  390. expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
  391. expect( styles.getInlineProperty( 'margin-right' ) ).to.equal( '1px' );
  392. expect( styles.getInlineProperty( 'margin-bottom' ) ).to.equal( '90.1rem' );
  393. expect( styles.getInlineProperty( 'margin-left' ) ).to.equal( '1px' );
  394. } );
  395. it( 'should output inline style (4 values defined)', () => {
  396. styles.setStyle( 'margin:1px .34cm 90.1rem thick;' );
  397. expect( styles.getInlineStyle() ).to.equal( 'margin:1px .34cm 90.1rem thick;' );
  398. expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px .34cm 90.1rem thick' );
  399. expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
  400. expect( styles.getInlineProperty( 'margin-right' ) ).to.equal( '.34cm' );
  401. expect( styles.getInlineProperty( 'margin-bottom' ) ).to.equal( '90.1rem' );
  402. expect( styles.getInlineProperty( 'margin-left' ) ).to.equal( 'thick' );
  403. } );
  404. it( 'should output inline style (4 values defined, only last different)', () => {
  405. styles.setStyle( 'margin:1px 1px 1px thick;' );
  406. expect( styles.getInlineStyle() ).to.equal( 'margin:1px 1px 1px thick;' );
  407. expect( styles.getInlineProperty( 'margin' ) ).to.equal( '1px 1px 1px thick' );
  408. expect( styles.getInlineProperty( 'margin-top' ) ).to.equal( '1px' );
  409. expect( styles.getInlineProperty( 'margin-right' ) ).to.equal( '1px' );
  410. expect( styles.getInlineProperty( 'margin-bottom' ) ).to.equal( '1px' );
  411. expect( styles.getInlineProperty( 'margin-left' ) ).to.equal( 'thick' );
  412. } );
  413. describe( 'margin-*', () => {
  414. it( 'should set proper margin', () => {
  415. styles.setStyle( 'margin-top:1px;' );
  416. expect( styles.getNormalized( 'margin' ) ).to.deep.equal( { top: '1px' } );
  417. expect( styles.getNormalized( 'margin-top' ) ).to.equal( '1px' );
  418. } );
  419. it( 'should set proper margin with margin shorthand', () => {
  420. styles.setStyle( 'margin: 2em;margin-top:1px;' );
  421. expect( styles.getNormalized( 'margin' ) ).to.deep.equal( {
  422. top: '1px',
  423. right: '2em',
  424. bottom: '2em',
  425. left: '2em'
  426. } );
  427. expect( styles.getNormalized( 'margin-top' ) ).to.equal( '1px' );
  428. expect( styles.getNormalized( 'margin-right' ) ).to.equal( '2em' );
  429. expect( styles.getNormalized( 'margin-bottom' ) ).to.equal( '2em' );
  430. expect( styles.getNormalized( 'margin-left' ) ).to.equal( '2em' );
  431. } );
  432. } );
  433. } );
  434. describe( 'padding', () => {
  435. it( 'should set all paddings (1 value defined)', () => {
  436. styles.setStyle( 'padding:1px;' );
  437. expect( styles.getNormalized( 'padding' ) ).to.deep.equal( {
  438. top: '1px',
  439. right: '1px',
  440. bottom: '1px',
  441. left: '1px'
  442. } );
  443. } );
  444. it( 'should set all paddings (2 values defined)', () => {
  445. styles.setStyle( 'padding:1px .34cm;' );
  446. expect( styles.getNormalized( 'padding' ) ).to.deep.equal( {
  447. top: '1px',
  448. right: '.34cm',
  449. bottom: '1px',
  450. left: '.34cm'
  451. } );
  452. } );
  453. it( 'should set all paddings (3 values defined)', () => {
  454. styles.setStyle( 'padding:1px .34cm 90.1rem;' );
  455. expect( styles.getNormalized( 'padding' ) ).to.deep.equal( {
  456. top: '1px',
  457. right: '.34cm',
  458. bottom: '90.1rem',
  459. left: '.34cm'
  460. } );
  461. } );
  462. it( 'should set all paddings (4 values defined)', () => {
  463. styles.setStyle( 'padding:1px .34cm 90.1rem thick;' );
  464. expect( styles.getNormalized( 'padding' ) ).to.deep.equal( {
  465. top: '1px',
  466. right: '.34cm',
  467. bottom: '90.1rem',
  468. left: 'thick'
  469. } );
  470. } );
  471. describe( 'padding-*', () => {
  472. it( 'should set proper padding', () => {
  473. styles.setStyle( 'padding-top:1px;' );
  474. expect( styles.getNormalized( 'padding' ) ).to.deep.equal( {
  475. top: '1px'
  476. } );
  477. } );
  478. it( 'should set proper padding with padding shorthand', () => {
  479. styles.setStyle( 'padding: 2em;padding-top:1px;' );
  480. expect( styles.getNormalized( 'padding' ) ).to.deep.equal( {
  481. top: '1px',
  482. right: '2em',
  483. bottom: '2em',
  484. left: '2em'
  485. } );
  486. } );
  487. } );
  488. } );
  489. describe( 'unknown rules', () => {
  490. it( 'should left rules untouched', () => {
  491. styles.setStyle( 'foo-bar:baz 1px abc;baz: 2px 3em;' );
  492. expect( styles.getInlineStyle() ).to.equal( 'baz:2px 3em;foo-bar:baz 1px abc;' );
  493. expect( styles.getInlineProperty( 'foo-bar' ) ).to.equal( 'baz 1px abc' );
  494. expect( styles.getInlineProperty( 'baz' ) ).to.equal( '2px 3em' );
  495. } );
  496. } );
  497. } );
  498. } );