{"size": 2095, "ext": "js", "max_stars_repo_path": "src/components/icon-toolbar/icon-toolbar.test.js", "max_stars_repo_name": "rossann9119/kedro-viz", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/icon-toolbar/icon-toolbar.test.js", "max_issues_repo_name": "rossann9119/kedro-viz", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/icon-toolbar/icon-toolbar.test.js", "max_forks_repo_name": "rossann9119/kedro-viz", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.8088235294, "max_line_length": 78, "alphanum_fraction": 0.6243436754}
import React from 'react';
import IconToolbar, { mapStateToProps, mapDispatchToProps } from './index';
import { mockState, setup } from '../../utils/state.mock';

describe('IconToolbar', () => {
  it('renders without crashing', () => {
    const wrapper = setup.mount(<IconToolbar />);
    expect(wrapper.find('.pipeline-icon-button').length).toBe(3);
  });

  it('hides both buttons when visible prop is false for each of them', () => {
    const visible = {
      themeBtn: false,
      labelBtn: false,
      exportBtn: false
    };
    const wrapper = setup.mount(<IconToolbar />, { visible });
    expect(wrapper.find('.pipeline-icon-button').length).toBe(0);
  });

  it('hides one button when visible prop is false for one of them', () => {
    const visible = {
      labelBtn: false
    };
    const wrapper = setup.mount(<IconToolbar />, { visible });
    expect(wrapper.find('.pipeline-icon-button').length).toBe(2);
  });

  it('shows the export modal on export button click', () => {
    const wrapper = setup.mount(<IconToolbar />);
    expect(wrapper.find('Modal').props().visible).toBe(false);
    wrapper
      .find({ icon: 'export' })
      .find('button')
      .simulate('click');
    expect(wrapper.find('Modal').props().visible).toBe(true);
  });

  it('maps state to props', () => {
    const expectedResult = {
      textLabels: expect.any(Boolean),
      theme: expect.stringMatching(/light|dark/),
      visible: expect.objectContaining({
        themeBtn: expect.any(Boolean),
        labelBtn: expect.any(Boolean),
        exportBtn: expect.any(Boolean)
      })
    };
    expect(mapStateToProps(mockState.lorem)).toEqual(expectedResult);
  });

  it('maps dispatch to props', () => {
    const dispatch = jest.fn();

    mapDispatchToProps(dispatch).onToggleTextLabels(false);
    expect(dispatch.mock.calls[0][0]).toEqual({
      textLabels: false,
      type: 'TOGGLE_TEXT_LABELS'
    });

    mapDispatchToProps(dispatch).onToggleTheme('light');
    expect(dispatch.mock.calls[1][0]).toEqual({
      theme: 'light',
      type: 'TOGGLE_THEME'
    });
  });
});
