8
0

utils.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import { FONT_COLOR, FONT_BACKGROUND_COLOR, normalizeOptions, addColorsToDropdown } from './../src/utils';
  6. import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
  7. import ColorTableView from './../src/ui/colortableview';
  8. describe( 'utils', () => {
  9. describe( 'color and background color related', () => {
  10. it( 'plugin names has proper values', () => {
  11. expect( FONT_COLOR ).to.equal( 'fontColor' );
  12. expect( FONT_BACKGROUND_COLOR ).to.equal( 'fontBackgroundColor' );
  13. } );
  14. it( 'normalizeOptions can produce the same output object', () => {
  15. const normalizedArray = normalizeOptions( [
  16. 'black',
  17. {
  18. color: 'black'
  19. }, {
  20. color: 'black',
  21. label: 'Black'
  22. }, {
  23. color: 'black',
  24. label: 'Black',
  25. hasBorder: true
  26. }, {
  27. color: 'black',
  28. hasBorder: true
  29. }
  30. ] );
  31. expect( normalizedArray ).to.deep.equal( [
  32. {
  33. model: 'black',
  34. label: 'black',
  35. hasBorder: false,
  36. view: {
  37. name: 'span',
  38. styles: {
  39. color: 'black'
  40. },
  41. priority: 5
  42. }
  43. }, {
  44. model: 'black',
  45. label: 'black',
  46. hasBorder: false,
  47. view: {
  48. name: 'span',
  49. styles: {
  50. color: 'black'
  51. },
  52. priority: 5
  53. }
  54. }, {
  55. model: 'black',
  56. label: 'Black',
  57. hasBorder: false,
  58. view: {
  59. name: 'span',
  60. styles: {
  61. color: 'black'
  62. },
  63. priority: 5
  64. }
  65. },
  66. {
  67. model: 'black',
  68. label: 'Black',
  69. hasBorder: true,
  70. view: {
  71. name: 'span',
  72. styles: {
  73. color: 'black'
  74. },
  75. priority: 5
  76. }
  77. },
  78. {
  79. model: 'black',
  80. label: 'black',
  81. hasBorder: true,
  82. view: {
  83. name: 'span',
  84. styles: {
  85. color: 'black'
  86. },
  87. priority: 5
  88. }
  89. },
  90. ] );
  91. } );
  92. it( 'adding colors table to dropdown works', () => {
  93. const dropdown = createDropdown();
  94. dropdown.render();
  95. addColorsToDropdown( {
  96. dropdownView: dropdown,
  97. colors: [
  98. {
  99. label: 'Black',
  100. color: '#000',
  101. options: {
  102. hasBorder: false
  103. }
  104. }, {
  105. label: 'White',
  106. color: '#FFFFFF',
  107. options: {
  108. hasBorder: true
  109. }
  110. }
  111. ],
  112. colorColumns: 2,
  113. removeButtonTooltip: 'Remove Color'
  114. } );
  115. expect( dropdown.colorTableView ).to.be.instanceOf( ColorTableView );
  116. expect( dropdown.panelView.children.length ).to.equal( 1 );
  117. } );
  118. } );
  119. } );