import {
    getAvailableConfigurationModes,
    getAvailableLicenses,
    getConfigurationModeOptions,
    getSelectedConfigurationMode,
    isConfigurationModeAvailable,
    isConfigurationModeSwitchAvailable,
    isDesignerMode,
} from '../Selectors';

describe('Reducers/ConfigurationMode/Selectors', () => {
    test('getSelectedConfigurationMode returns the currently selected mode', () => {
        const state = {
            configurationMode: {
                selectedMode: 'creator',
            },
        };
        expect(getSelectedConfigurationMode(state)).toEqual('creator');
    });

    test('getAvailableConfigurationModes returns the configuration mode availability map', () => {
        const state = {
            configurationMode: {
                availableModes: {
                    creator: true,
                },
            },
        };
        expect(getAvailableConfigurationModes(state)).toEqual({
            creator: true,
        });
    });

    test('getConfigurationModeOptions returns all available but the selected available modes', () => {
        const state1 = {
            configurationMode: {
                availableModes: {
                    creator: true,
                    designer: true,
                },
                selectedMode: 'creator',
            },
        };
        expect(getConfigurationModeOptions(state1)).toEqual(['designer']);

        const state2 = {
            configurationMode: {
                availableModes: {
                    creator: true,
                },
                selectedMode: 'creator',
            },
        };
        expect(getConfigurationModeOptions(state2)).toEqual([]);
    });

    test('isConfigurationModeAvailable returns if any mode is available', () => {
        const state1 = {
            configurationMode: {
                availableModes: {
                    creator: true,
                },
            },
        };
        expect(isConfigurationModeAvailable(state1)).toBe(true);

        const state2 = {
            configurationMode: {
                availableModes: {},
            },
        };
        expect(isConfigurationModeAvailable(state2)).toBe(false);
    });

    test('isConfigurationModeSwitchAvailable returns if more than one mode is available', () => {
        const state1 = {
            configurationMode: {
                availableModes: {
                    creator: true,
                    designer: true,
                },
            },
        };
        expect(isConfigurationModeSwitchAvailable(state1)).toBe(true);

        const state2 = {
            configurationMode: {
                availableModes: {
                    creator: true,
                },
            },
        };
        expect(isConfigurationModeSwitchAvailable(state2)).toBe(false);
    });

    test('isDesignerMode returns true for the input "designer", false otherwise', () => {
        expect(isDesignerMode('designer')).toBe(true);
        expect(isDesignerMode('creator')).toBe(false);
    });

    test('getAvailableLicenses returns the available licenses in an array', () => {
        expect(
            getAvailableLicenses({
                license: 'creator+designer',
            })
        ).toEqual(['creator', 'designer']);

        expect(
            getAvailableLicenses({
                license: 'designer+',
            })
        ).toEqual(['designer']);

        expect(
            getAvailableLicenses({
                license: 'aa',
            })
        ).toEqual(['aa']);

        expect(getAvailableLicenses({})).toEqual([]);

        expect(
            getAvailableLicenses({
                license: '',
            })
        ).toEqual([]);
    });
});
