'use strict';

import { designAreaAppliesMask, getMaskDataForDesignArea } from '../MaskSelectors';

describe('Reducers/DesignArea/MaskSelectors', () => {
    describe('designAreaAppliesMask', () => {
        describe('tests with selected design area', () => {
            it('returns true if it has mask', () => {
                expect(
                    designAreaAppliesMask({
                        configurator: {
                            configuration: {},
                        },
                        designArea: {
                            selectedDesignArea: {
                                mask: {
                                    maskType: 'circle',
                                },
                            },
                        },
                    })
                ).toBe(true);
            });
            it('returns false if it has no mask', () => {
                expect(
                    designAreaAppliesMask({
                        configurator: {
                            configuration: {},
                        },
                        designArea: {
                            selectedDesignArea: {
                                mask: null,
                            },
                        },
                    })
                ).toBe(false);
            });
            it('returns false if it has non supported mask type', () => {
                expect(
                    designAreaAppliesMask({
                        configurator: {
                            configuration: {},
                        },
                        designArea: {
                            selectedDesignArea: {
                                mask: {
                                    maskType: 'the-real-mask',
                                },
                            },
                        },
                    })
                ).toBe(false);
            });
            it('returns true if it has mask for the selected design production method', () => {
                expect(
                    designAreaAppliesMask({
                        configurator: {
                            configuration: {
                                designdata: {
                                    designArea1: {
                                        designProductionMethodIdentifier: 'customPrinting',
                                    },
                                },
                            },
                        },
                        designArea: {
                            selectedDesignArea: {
                                identifier: 'designArea1',
                                mask: null,
                                designProductionMethods: [
                                    {
                                        identifier: 'customPrinting',
                                        mask: {
                                            maskType: 'circle',
                                        },
                                    },
                                ],
                            },
                        },
                    })
                ).toBe(true);
            });
        });

        describe('tests with design area as argument', () => {
            it('returns true if it has mask', () => {
                expect(
                    designAreaAppliesMask(
                        {
                            configurator: {
                                configuration: {},
                            },
                        },
                        {
                            mask: {
                                maskType: 'circle',
                            },
                        }
                    )
                ).toBe(true);
            });
            it('returns true if it has mask for the selected design production method', () => {
                expect(
                    designAreaAppliesMask(
                        {
                            configurator: {
                                configuration: {
                                    designdata: {
                                        designArea1: {
                                            designProductionMethodIdentifier: 'customPrinting',
                                        },
                                    },
                                },
                            },
                        },
                        {
                            identifier: 'designArea1',
                            mask: null,
                            designProductionMethods: [
                                {
                                    identifier: 'customPrinting',
                                    mask: {
                                        maskType: 'circle',
                                    },
                                },
                            ],
                        }
                    )
                ).toBe(true);
            });
            it('returns true if the selected design production method does not have mask, but the design area does', () => {
                expect(
                    designAreaAppliesMask(
                        {
                            configurator: {
                                configuration: {
                                    designdata: {
                                        designArea1: {
                                            designProductionMethodIdentifier: 'customPrinting',
                                        },
                                    },
                                },
                            },
                        },
                        {
                            identifier: 'designArea1',
                            mask: {
                                maskType: 'circle',
                            },
                            designProductionMethods: [
                                {
                                    identifier: 'customPrinting',
                                    mask: null,
                                },
                            ],
                        }
                    )
                ).toBe(true);
            });
        });
    });

    describe('getMaskDataForDesignArea', () => {
        describe('test with selected design area', () => {
            it('returns the correct data if it has circle mask', () => {
                expect(
                    getMaskDataForDesignArea({
                        configurator: {
                            client: {
                                theme: {
                                    highlightColor: '#abc',
                                },
                            },
                            configuration: {
                                item: {
                                    identifier: 'item1',
                                },
                            },
                        },
                        designArea: {
                            selectedDesignArea: {
                                identifier: 'dseignArea1',
                                mask: {
                                    maskType: 'circle',
                                    maskData: {
                                        x: 0.2,
                                        y: 0.3,
                                        rotation: 0.4,
                                        scaling: 0.5,
                                    },
                                },
                            },
                        },
                    })
                ).toMatchObject({
                    outlineColor: '#abc',
                    type: 'circle',
                    src: 'test-file-stub',
                    x: 0.2,
                    y: 0.3,
                    rotation: 0.4,
                    scaling: 0.5,
                });
            });
            it('returns the correct data if it has freeForm mask', () => {
                expect(
                    getMaskDataForDesignArea({
                        configurator: {
                            client: {
                                theme: {
                                    highlightColor: '#abc',
                                },
                            },
                            configuration: {
                                item: {
                                    identifier: 'item1',
                                },
                            },
                        },
                        designArea: {
                            selectedDesignArea: {
                                identifier: 'dseignArea1',
                                mask: {
                                    maskType: 'freeForm',
                                    maskData: {
                                        x: 0.2,
                                        y: 0.3,
                                        rotation: 0.4,
                                        scaling: 0.5,
                                    },
                                },
                            },
                        },
                    })
                ).toMatchObject({
                    outlineColor: '#abc',
                    type: 'freeForm',
                    src: '/designer/masks/item1/dseignArea1.svg',
                    x: 0.2,
                    y: 0.3,
                    rotation: 0.4,
                    scaling: 0.5,
                });
            });
        });
        describe('test with design area as argument', () => {
            it('returns the correct data if it has freeForm mask', () => {
                expect(
                    getMaskDataForDesignArea(
                        {
                            configurator: {
                                client: {
                                    theme: {
                                        highlightColor: '#abc',
                                    },
                                },
                                configuration: {
                                    item: {
                                        identifier: 'item1',
                                    },
                                    configuration: {
                                        designdata: {
                                            designArea1: {
                                                designProductionMethodIdentifier: 'customPrinting',
                                            },
                                        },
                                    },
                                },
                            },
                        },
                        {
                            identifier: 'dseignArea1',
                            mask: null,
                            designProductionMethods: [
                                {
                                    identifier: 'customPrinting',
                                    mask: {
                                        maskType: 'freeForm',
                                        maskData: {
                                            x: 0.2,
                                            y: 0.3,
                                            rotation: 0.4,
                                            scaling: 0.5,
                                        },
                                    },
                                },
                            ],
                        }
                    )
                ).toMatchObject({
                    outlineColor: '#abc',
                    type: 'freeForm',
                    src: '/designer/masks/item1/dseignArea1_customPrinting.svg',
                    x: 0.2,
                    y: 0.3,
                    rotation: 0.4,
                    scaling: 0.5,
                });
            });
        });
    });
});
