8
0

background.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 { addBackgroundRules } from '../../../src/view/styles/background';
  7. describe( 'Background styles normalization', () => {
  8. let styles;
  9. before( () => {
  10. const stylesProcessor = new StylesProcessor();
  11. StylesMap._setProcessor( stylesProcessor );
  12. addBackgroundRules( stylesProcessor );
  13. } );
  14. beforeEach( () => {
  15. styles = new StylesMap();
  16. } );
  17. it( 'should normalize background', () => {
  18. styles.setTo( 'background:url("example.jpg") center #f00 repeat-y fixed border-box;' );
  19. expect( styles.getNormalized( 'background' ) ).to.deep.equal( {
  20. attachment: 'fixed',
  21. image: 'url("example.jpg")',
  22. position: [ 'center' ],
  23. repeat: [ 'repeat-y' ],
  24. color: '#f00'
  25. } );
  26. } );
  27. it( 'should normalize background (color with spaces)', () => {
  28. styles.setTo( 'background:url("example.jpg") center rgb(253, 253, 119) repeat-y fixed border-box;' );
  29. expect( styles.getNormalized( 'background' ) ).to.deep.equal( {
  30. attachment: 'fixed',
  31. image: 'url("example.jpg")',
  32. position: [ 'center' ],
  33. repeat: [ 'repeat-y' ],
  34. color: 'rgb(253, 253, 119)'
  35. } );
  36. } );
  37. it( 'should normalize background (color only with spaces)', () => {
  38. styles.setTo( 'background: rgb(253, 253, 119);' );
  39. expect( styles.getNormalized( 'background' ) ).to.deep.equal( {
  40. color: 'rgb(253, 253, 119)'
  41. } );
  42. } );
  43. // Layers are not supported.
  44. it.skip( 'should normalize background with layers', () => {
  45. styles.setTo( 'background:url("test.jpg") repeat-y,#f00;' );
  46. expect( styles.getNormalized( 'background' ) ).to.deep.equal( { color: '#f00' } );
  47. } );
  48. it( 'should normalize background-color', () => {
  49. styles.setTo( 'background-color:#f00;' );
  50. expect( styles.getNormalized( 'background' ) ).to.deep.equal( { color: '#f00' } );
  51. } );
  52. it( 'should normalize background-color with rgb() value', () => {
  53. styles.setTo( 'background-color:rgba(253, 253, 119, 1);' );
  54. expect( styles.getNormalized( 'background' ) ).to.deep.equal( { color: 'rgba(253, 253, 119, 1)' } );
  55. } );
  56. it( 'should output inline background-color style', () => {
  57. styles.setTo( 'background:#f00;' );
  58. expect( styles.toString() ).to.equal( 'background-color:#f00;' );
  59. expect( styles.getAsString( 'background-color' ) ).to.equal( '#f00' );
  60. } );
  61. } );