utils.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 { normalizeOptions, FONT_SIZE_PRESET_UNITS } from '../../src/fontsize/utils';
  6. describe( 'FontSizeEditing Utils', () => {
  7. describe( 'normalizeOptions()', () => {
  8. it( 'should discard unsupported values', () => {
  9. expect( normalizeOptions( [ () => {}, 'default', 'unknown' ] ) ).to.deep.equal( [ { title: 'Default', model: undefined } ] );
  10. } );
  11. it( 'should pass through object definition', () => {
  12. expect( normalizeOptions( [ {
  13. title: 'My Size',
  14. model: 'my-size',
  15. view: { name: 'span', styles: 'font-size: 12em;' }
  16. } ] ) ).to.deep.equal( [
  17. {
  18. title: 'My Size',
  19. model: 'my-size',
  20. view: { name: 'span', styles: 'font-size: 12em;' }
  21. }
  22. ] );
  23. } );
  24. describe( 'named presets', () => {
  25. it( 'should return defined presets', () => {
  26. expect( normalizeOptions( [ 'tiny', 'small', 'default', 'big', 'huge' ] ) ).to.deep.equal( [
  27. { title: 'Tiny', model: 'tiny', view: { name: 'span', classes: 'text-tiny', priority: 7 } },
  28. { title: 'Small', model: 'small', view: { name: 'span', classes: 'text-small', priority: 7 } },
  29. { title: 'Default', model: undefined },
  30. { title: 'Big', model: 'big', view: { name: 'span', classes: 'text-big', priority: 7 } },
  31. { title: 'Huge', model: 'huge', view: { name: 'span', classes: 'text-huge', priority: 7 } }
  32. ] );
  33. } );
  34. it( 'should return defined presets with units in model values', () => {
  35. const options = normalizeOptions( [ 'tiny', 'small', 'default', 'big', 'huge' ], { disableValueMatching: true } );
  36. expect( options ).to.deep.equal( [
  37. { title: 'Tiny', model: '0.7em', view: { name: 'span', classes: 'text-tiny', priority: 7 } },
  38. { title: 'Small', model: '0.85em', view: { name: 'span', classes: 'text-small', priority: 7 } },
  39. { title: 'Default', model: undefined },
  40. { title: 'Big', model: '1.4em', view: { name: 'span', classes: 'text-big', priority: 7 } },
  41. { title: 'Huge', model: '1.8em', view: { name: 'span', classes: 'text-huge', priority: 7 } }
  42. ] );
  43. } );
  44. } );
  45. describe( 'numerical presets', () => {
  46. it( 'should return generated presets', () => {
  47. expect( normalizeOptions( [ '10', 12, 'default', '14.1', 18.3 ] ) ).to.deep.equal( [
  48. { title: '10', model: 10, view: { name: 'span', styles: { 'font-size': '10px' }, priority: 7 } },
  49. { title: '12', model: 12, view: { name: 'span', styles: { 'font-size': '12px' }, priority: 7 } },
  50. { title: 'Default', model: undefined },
  51. { title: '14.1', model: 14.1, view: { name: 'span', styles: { 'font-size': '14.1px' }, priority: 7 } },
  52. { title: '18.3', model: 18.3, view: { name: 'span', styles: { 'font-size': '18.3px' }, priority: 7 } }
  53. ] );
  54. } );
  55. } );
  56. } );
  57. describe( 'FONT_SIZE_PRESET_UNITS', () => {
  58. it( 'provides default values', () => {
  59. expect( Object.keys( FONT_SIZE_PRESET_UNITS ).length ).to.equal( 4 );
  60. } );
  61. } );
  62. } );