utils.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import {
  6. FONT_COLOR,
  7. FONT_BACKGROUND_COLOR,
  8. normalizeColorOptions,
  9. addColorTableToDropdown,
  10. renderDowncastElement
  11. } from './../src/utils';
  12. import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
  13. import ColorTableView from './../src/ui/colortableview';
  14. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  15. describe( 'utils', () => {
  16. testUtils.createSinonSandbox();
  17. it( 'plugin names has proper values', () => {
  18. expect( FONT_COLOR ).to.equal( 'fontColor' );
  19. expect( FONT_BACKGROUND_COLOR ).to.equal( 'fontBackgroundColor' );
  20. } );
  21. describe( 'normalizeColorOptions()', () => {
  22. it( 'should return normalized config object from string', () => {
  23. const normalizedOption = normalizeColorOptions( [ 'black' ] );
  24. expect( normalizedOption ).to.deep.equal( [
  25. {
  26. model: 'black',
  27. label: 'black',
  28. hasBorder: false,
  29. view: {
  30. name: 'span',
  31. styles: {
  32. color: 'black'
  33. }
  34. }
  35. }
  36. ] );
  37. } );
  38. it( 'should return normalized config object from object( color )', () => {
  39. const normalizedOption = normalizeColorOptions( [ { color: 'black' } ] );
  40. expect( normalizedOption ).to.deep.equal( [
  41. {
  42. model: 'black',
  43. label: 'black',
  44. hasBorder: false,
  45. view: {
  46. name: 'span',
  47. styles: {
  48. color: 'black'
  49. }
  50. }
  51. }
  52. ] );
  53. } );
  54. it( 'should return normalized config object from object( color, label )', () => {
  55. const normalizedOption = normalizeColorOptions( [
  56. {
  57. color: 'black',
  58. label: 'Black'
  59. }
  60. ] );
  61. expect( normalizedOption ).to.deep.equal( [
  62. {
  63. model: 'black',
  64. label: 'Black',
  65. hasBorder: false,
  66. view: {
  67. name: 'span',
  68. styles: {
  69. color: 'black'
  70. }
  71. }
  72. }
  73. ] );
  74. } );
  75. it( 'should return normalized config object from object( color, label, hasBorder )', () => {
  76. const normalizedOption = normalizeColorOptions( [
  77. {
  78. color: 'black',
  79. label: 'Black',
  80. hasBorder: true
  81. }
  82. ] );
  83. expect( normalizedOption ).to.deep.equal( [
  84. {
  85. model: 'black',
  86. label: 'Black',
  87. hasBorder: true,
  88. view: {
  89. name: 'span',
  90. styles: {
  91. color: 'black'
  92. }
  93. }
  94. }
  95. ] );
  96. } );
  97. it( 'should return normalized config object from object( color, hasBorder )', () => {
  98. const normalizedOption = normalizeColorOptions( [
  99. {
  100. color: 'black',
  101. hasBorder: true
  102. }
  103. ] );
  104. expect( normalizedOption ).to.deep.equal( [
  105. {
  106. model: 'black',
  107. label: 'black',
  108. hasBorder: true,
  109. view: {
  110. name: 'span',
  111. styles: {
  112. color: 'black'
  113. }
  114. }
  115. }
  116. ] );
  117. } );
  118. } );
  119. it( 'addColorTableToDropdown()', () => {
  120. const dropdown = createDropdown();
  121. dropdown.render();
  122. addColorTableToDropdown( {
  123. dropdownView: dropdown,
  124. colors: [
  125. {
  126. label: 'Black',
  127. color: '#000',
  128. options: {
  129. hasBorder: false
  130. }
  131. },
  132. {
  133. label: 'White',
  134. color: '#FFFFFF',
  135. options: {
  136. hasBorder: true
  137. }
  138. }
  139. ],
  140. columns: 2,
  141. removeButtonTooltip: 'Remove Color'
  142. } );
  143. expect( dropdown.colorTableView ).to.be.instanceOf( ColorTableView );
  144. expect( dropdown.panelView.children.length ).to.equal( 1 );
  145. } );
  146. it( 'renderDowncastElement()', () => {
  147. const testRender = renderDowncastElement( 'color' );
  148. const fake = testUtils.sinon.fake();
  149. testRender( 'blue', { createAttributeElement: fake } );
  150. sinon.assert.calledWithExactly( fake, 'span', { style: 'color:blue' }, { priority: 7 } );
  151. } );
  152. } );