utils.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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, addColorTableToDropdown } 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. {
  21. color: 'black',
  22. label: 'Black'
  23. },
  24. {
  25. color: 'black',
  26. label: 'Black',
  27. hasBorder: true
  28. },
  29. {
  30. color: 'black',
  31. hasBorder: true
  32. }
  33. ] );
  34. expect( normalizedArray ).to.deep.equal( [
  35. {
  36. model: 'black',
  37. label: 'black',
  38. hasBorder: false,
  39. view: {
  40. name: 'span',
  41. styles: {
  42. color: 'black'
  43. },
  44. priority: 5
  45. }
  46. },
  47. {
  48. model: 'black',
  49. label: 'black',
  50. hasBorder: false,
  51. view: {
  52. name: 'span',
  53. styles: {
  54. color: 'black'
  55. },
  56. priority: 5
  57. }
  58. },
  59. {
  60. model: 'black',
  61. label: 'Black',
  62. hasBorder: false,
  63. view: {
  64. name: 'span',
  65. styles: {
  66. color: 'black'
  67. },
  68. priority: 5
  69. }
  70. },
  71. {
  72. model: 'black',
  73. label: 'Black',
  74. hasBorder: true,
  75. view: {
  76. name: 'span',
  77. styles: {
  78. color: 'black'
  79. },
  80. priority: 5
  81. }
  82. },
  83. {
  84. model: 'black',
  85. label: 'black',
  86. hasBorder: true,
  87. view: {
  88. name: 'span',
  89. styles: {
  90. color: 'black'
  91. },
  92. priority: 5
  93. }
  94. },
  95. ] );
  96. } );
  97. it( 'adding colors table to dropdown works', () => {
  98. const dropdown = createDropdown();
  99. dropdown.render();
  100. addColorTableToDropdown( {
  101. dropdownView: dropdown,
  102. colors: [
  103. {
  104. label: 'Black',
  105. color: '#000',
  106. options: {
  107. hasBorder: false
  108. }
  109. },
  110. {
  111. label: 'White',
  112. color: '#FFFFFF',
  113. options: {
  114. hasBorder: true
  115. }
  116. }
  117. ],
  118. columns: 2,
  119. removeButtonTooltip: 'Remove Color'
  120. } );
  121. expect( dropdown.colorTableView ).to.be.instanceOf( ColorTableView );
  122. expect( dropdown.panelView.children.length ).to.equal( 1 );
  123. } );
  124. } );
  125. } );