| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- /**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
- import {
- FONT_COLOR,
- FONT_BACKGROUND_COLOR,
- normalizeColorOptions,
- addColorTableToDropdown,
- renderDowncastElement
- } from './../src/utils';
- import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
- import ColorTableView from './../src/ui/colortableview';
- import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
- describe( 'utils', () => {
- testUtils.createSinonSandbox();
- it( 'plugin names has proper values', () => {
- expect( FONT_COLOR ).to.equal( 'fontColor' );
- expect( FONT_BACKGROUND_COLOR ).to.equal( 'fontBackgroundColor' );
- } );
- describe( 'normalizeColorOptions()', () => {
- it( 'should return normalized config object from string', () => {
- const normalizedOption = normalizeColorOptions( [ 'black' ] );
- expect( normalizedOption ).to.deep.equal( [
- {
- model: 'black',
- label: 'black',
- hasBorder: false,
- view: {
- name: 'span',
- styles: {
- color: 'black'
- }
- }
- }
- ] );
- } );
- it( 'should return normalized config object from object( color )', () => {
- const normalizedOption = normalizeColorOptions( [ { color: 'black' } ] );
- expect( normalizedOption ).to.deep.equal( [
- {
- model: 'black',
- label: 'black',
- hasBorder: false,
- view: {
- name: 'span',
- styles: {
- color: 'black'
- }
- }
- }
- ] );
- } );
- it( 'should return normalized config object from object( color, label )', () => {
- const normalizedOption = normalizeColorOptions( [
- {
- color: 'black',
- label: 'Black'
- }
- ] );
- expect( normalizedOption ).to.deep.equal( [
- {
- model: 'black',
- label: 'Black',
- hasBorder: false,
- view: {
- name: 'span',
- styles: {
- color: 'black'
- }
- }
- }
- ] );
- } );
- it( 'should return normalized config object from object( color, label, hasBorder )', () => {
- const normalizedOption = normalizeColorOptions( [
- {
- color: 'black',
- label: 'Black',
- hasBorder: true
- }
- ] );
- expect( normalizedOption ).to.deep.equal( [
- {
- model: 'black',
- label: 'Black',
- hasBorder: true,
- view: {
- name: 'span',
- styles: {
- color: 'black'
- }
- }
- }
- ] );
- } );
- it( 'should return normalized config object from object( color, hasBorder )', () => {
- const normalizedOption = normalizeColorOptions( [
- {
- color: 'black',
- hasBorder: true
- }
- ] );
- expect( normalizedOption ).to.deep.equal( [
- {
- model: 'black',
- label: 'black',
- hasBorder: true,
- view: {
- name: 'span',
- styles: {
- color: 'black'
- }
- }
- }
- ] );
- } );
- } );
- it( 'addColorTableToDropdown()', () => {
- const dropdown = createDropdown();
- dropdown.render();
- addColorTableToDropdown( {
- dropdownView: dropdown,
- colors: [
- {
- label: 'Black',
- color: '#000',
- options: {
- hasBorder: false
- }
- },
- {
- label: 'White',
- color: '#FFFFFF',
- options: {
- hasBorder: true
- }
- }
- ],
- columns: 2,
- removeButtonTooltip: 'Remove Color'
- } );
- expect( dropdown.colorTableView ).to.be.instanceOf( ColorTableView );
- expect( dropdown.panelView.children.length ).to.equal( 1 );
- } );
- it( 'renderDowncastElement()', () => {
- const testRender = renderDowncastElement( 'color' );
- const fake = testUtils.sinon.fake();
- testRender( 'blue', { createAttributeElement: fake } );
- sinon.assert.calledWithExactly( fake, 'span', { style: 'color:blue' }, { priority: 7 } );
- } );
- } );
|