import React from 'react';
import { render, mount } from 'enzyme';
import ConfigurationModeSwitch from './ConfigurationModeSwitch';
import ServiceLocator from 'App/ServiceLocator';

const noop = () => {};

describe('ConfigurationModeSwitch', () => {
    let analyticsSrvc;
    beforeEach(() => {
        analyticsSrvc = new (class {
            static serviceName = 'AnalyticsService';
            triggerEvent = jest.fn();
        })();
        ServiceLocator.provide(analyticsSrvc);
    });
    it('renders empty if the configurationModeOptions prop is empty', () => {
        const tree = render(<ConfigurationModeSwitch onChange={noop} />);
        expect(tree).toMatchSnapshot();
    });
    it('renders the first of configurationModeOptions', () => {
        const tree = render(
            <ConfigurationModeSwitch configurationModeOptions={['designer']} onChange={noop} />
        );
        expect(tree).toMatchSnapshot();
    });
    it('calls the onChange event with the selected (currently first) mode', () => {
        const onChange = jest.fn();
        const wrapper = mount(
            <ConfigurationModeSwitch configurationModeOptions={['designer']} onChange={onChange} />
        );
        wrapper.find('button').simulate('click');
        expect(onChange).toHaveBeenCalledWith('designer');
    });
});
