background.js 2.4 KB

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