utils.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 } from '../../src/fontfamily/utils';
  6. describe( 'FontFamily utils', () => {
  7. describe( 'normalizeOptions()', () => {
  8. it( 'should discard unsupported values', () => {
  9. expect( normalizeOptions( [ () => {}, 0, true ] ) ).to.deep.equal( [] );
  10. } );
  11. it( 'should pass through object definition', () => {
  12. expect( normalizeOptions( [
  13. 'default',
  14. {
  15. title: 'Comic Sans',
  16. model: 'comic',
  17. view: {
  18. name: 'span',
  19. styles: {
  20. 'font-family': 'Comic Sans'
  21. }
  22. }
  23. }
  24. ] ) ).to.deep.equal( [
  25. {
  26. model: undefined,
  27. title: 'Default'
  28. },
  29. {
  30. title: 'Comic Sans',
  31. model: 'comic',
  32. view: {
  33. name: 'span',
  34. styles: {
  35. 'font-family': 'Comic Sans'
  36. }
  37. }
  38. }
  39. ] );
  40. } );
  41. describe( 'shorthand presets', () => {
  42. it( 'should return full preset from string presets', () => {
  43. expect( normalizeOptions( ( [
  44. 'Arial',
  45. '"Comic Sans MS", sans-serif',
  46. 'Lucida Console, \'Courier New\', Courier, monospace'
  47. ] ) ) ).to.deep.equal( [
  48. {
  49. title: 'Arial',
  50. model: 'Arial',
  51. view: {
  52. name: 'span',
  53. styles: {
  54. 'font-family': 'Arial'
  55. },
  56. priority: 7
  57. }
  58. },
  59. {
  60. title: 'Comic Sans MS',
  61. model: 'Comic Sans MS',
  62. view: {
  63. name: 'span',
  64. styles: {
  65. 'font-family': '\'Comic Sans MS\', sans-serif'
  66. },
  67. priority: 7
  68. }
  69. },
  70. {
  71. title: 'Lucida Console',
  72. model: 'Lucida Console',
  73. view: {
  74. name: 'span',
  75. styles: {
  76. 'font-family': '\'Lucida Console\', \'Courier New\', Courier, monospace'
  77. },
  78. priority: 7
  79. }
  80. }
  81. ] );
  82. } );
  83. } );
  84. } );
  85. } );