'use strict';

import {
    getAggregatedColors,
    getInitialMaxColorAmount,
    getOriginalColorsMap,
    hasBackgroundColor,
    getColorKeysForAggregatedColor,
    isPlaceholderObject,
} from '../Selectors';

describe('Reducers/DesignData/Selectors', () => {
    test('hasBackgroundColor returns false', () => {
        const colors = [{ value: '#000000' }];
        expect(hasBackgroundColor(colors)).toEqual(false);
    });
    test('hasBackgroundColor returns true for bright color', () => {
        const colors = [{ value: '#ffffff' }];
        expect(hasBackgroundColor(colors)).toEqual(true);
    });
    test('getAggregatedColors returns the correct object', () => {
        const colors = {
            '#838484': { identifier: '{"color":"silver","palette":"default"}', value: '#84888b' },
            '#998484': { identifier: '{"color":"silver","palette":"default"}', value: '#84888b' },
            '#cbebf8': { identifier: '{"color":"white","palette":"default"}', value: '#ffffff' },
        };
        const expectedResult = {
            '#838484': { identifier: '{"color":"silver","palette":"default"}', value: '#84888b' },
            '#cbebf8': { identifier: '{"color":"white","palette":"default"}', value: '#ffffff' },
        };
        expect(getAggregatedColors(colors)).toEqual(expectedResult);
    });
    test('getInitialMaxColorAmount returns the correct initial max color amount ', () => {
        const colors = {
            imageGallery: {
                selectedImage: {
                    operations: {
                        vectorizeColorsMap: {
                            '#ff0000': {
                                identifier: '{"color":"red","palette":"default"}',
                                value: 'rgb(255, 0, 0)',
                            },
                            '#000000': {
                                identifier: '{"color":"black","palette":"default"}',
                                value: '#000000',
                            },
                        },
                        vectorizeMaxColorAmount: 2,
                    },
                },
            },
        };
        expect(getInitialMaxColorAmount(colors)).toEqual(2);
    });
    test('getOriginalColorsMap returns true for bright color', () => {
        const vectorizeColorsMap = {
            '#ff0000': {
                identifier: '{"color":"red","palette":"default"}',
                value: '#ff0000',
            },
            '#000000': {
                identifier: '{"color":"black","palette":"default"}',
                value: '#000000',
            },
            '#838484': {
                identifier: '{"color":"black","palette":"default"}',
                value: '#000000',
            },
        };

        const colors = {
            imageGallery: {
                selectedImage: {
                    operations: {
                        vectorizeColorsMap: {
                            '#ff0000': {
                                identifier: '{"color":"red","palette":"default"}',
                                value: '#ff0000',
                            },
                            '#000000': {
                                identifier: '{"color":"black","palette":"default"}',
                                value: '#000000',
                            },
                        },
                        vectorizeMaxColorAmount: 2,
                        vectorizeOriginalColorsMap: vectorizeColorsMap,
                    },
                },
            },
        };
        expect(getOriginalColorsMap(colors)).toEqual(vectorizeColorsMap);
    });
    test('getColorKeysForAggregatedColor returns the correct array with the color keys', () => {
        const vectorizeColorsMap = {
            '#ff0000': {
                identifier: '{"color":"red","palette":"default"}',
                value: '#ff0000',
            },
            '#000000': {
                identifier: '{"color":"black","palette":"default"}',
                value: '#000000',
            },
            '#501B00': {
                identifier: '{"color":"black","palette":"default"}',
                value: '#000000',
            },
        };
        const originalColor = '#000000';
        const originalColor1 = '#ff0000';
        expect(getColorKeysForAggregatedColor(vectorizeColorsMap, originalColor)).toEqual([
            '#000000',
            '#501B00',
        ]);
        expect(getColorKeysForAggregatedColor(vectorizeColorsMap, originalColor1)).toEqual(['#ff0000']);
    });

    test('isPlaceholderObject returns the correct result', () => {
        expect(isPlaceholderObject({ type: 'Text', content: '<span>fake text</span>' })).toEqual(false);
        expect(
            isPlaceholderObject({ type: 'Text', content: '<span data-placeholder="true">fake text</span>' })
        ).toEqual(true);
        expect(isPlaceholderObject({ type: 'Image', imageData: { isPlaceHolderImage: false } })).toEqual(
            false
        );
        expect(isPlaceholderObject({ type: 'Image', imageData: { isPlaceHolderImage: true } })).toEqual(true);
    });
});
