background.js 2.4 KB

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