utils.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 {
  6. FONT_COLOR,
  7. FONT_BACKGROUND_COLOR,
  8. addColorTableToDropdown,
  9. renderDowncastElement
  10. } from './../src/utils';
  11. import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
  12. import ColorTableView from './../src/ui/colortableview';
  13. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  14. describe( 'utils', () => {
  15. testUtils.createSinonSandbox();
  16. it( 'plugin names has proper values', () => {
  17. expect( FONT_COLOR ).to.equal( 'fontColor' );
  18. expect( FONT_BACKGROUND_COLOR ).to.equal( 'fontBackgroundColor' );
  19. } );
  20. describe( 'addColorTableToDropdown()', () => {
  21. it( 'should create dropdown with color table', () => {
  22. const dropdown = createDropdown();
  23. dropdown.render();
  24. addColorTableToDropdown( {
  25. dropdownView: dropdown,
  26. colors: [
  27. {
  28. label: 'Black',
  29. color: '#000',
  30. options: {
  31. hasBorder: false
  32. }
  33. },
  34. {
  35. label: 'White',
  36. color: '#FFFFFF',
  37. options: {
  38. hasBorder: true
  39. }
  40. }
  41. ],
  42. columns: 2,
  43. removeButtonTooltip: 'Remove Color'
  44. } );
  45. expect( dropdown.colorTableView ).to.be.instanceOf( ColorTableView );
  46. expect( dropdown.panelView.children.length ).to.equal( 1 );
  47. expect( dropdown.colorTableView.element ).to.equal( dropdown.panelView.children.first.element );
  48. } );
  49. } );
  50. describe( 'renderDowncastElement()', () => {
  51. it( 'should create function executes viewWriter with proper arguments', () => {
  52. const downcastViewConverterFn = renderDowncastElement( 'color' );
  53. const fake = testUtils.sinon.fake();
  54. const fakeViewWriter = { createAttributeElement: fake };
  55. downcastViewConverterFn( 'blue', fakeViewWriter );
  56. sinon.assert.calledWithExactly( fake, 'span', { style: 'color:blue' }, { priority: 7 } );
  57. } );
  58. } );
  59. } );