File size: 2,487 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import React from 'react';
import Enzyme, { shallow } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import { createFakeMapInstance } from '../../test/mockGoogleMaps';
import { Control } from '../Control';

Enzyme.configure({ adapter: new Adapter() });

describe('Control', () => {
  const defaultProps = {
    googleMapsInstance: createFakeMapInstance(),
    translate: (x) => x,
    isRefineOnMapMove: true,
    hasMapMoveSinceLastRefine: false,
    toggleRefineOnMapMove: () => {},
    refineWithInstance: () => {},
  };

  it('expect to render correctly with refine on map move', () => {
    const props = {
      ...defaultProps,
    };

    const wrapper = shallow(<Control {...props} />);

    expect(wrapper).toMatchSnapshot();
    expect(wrapper.find('input').props().checked).toBe(true);
  });

  it('expect to render correctly without refine on map move', () => {
    const props = {
      ...defaultProps,
      isRefineOnMapMove: false,
    };

    const wrapper = shallow(<Control {...props} />);

    expect(wrapper).toMatchSnapshot();
    expect(wrapper.find('input').props().checked).toBe(false);
  });

  it('expect to render correctly without refine on map move when the map has moved', () => {
    const props = {
      ...defaultProps,
      isRefineOnMapMove: false,
      hasMapMoveSinceLastRefine: true,
    };

    const wrapper = shallow(<Control {...props} />);

    expect(wrapper).toMatchSnapshot();
  });

  it('expect to call toggleRefineOnMapMove on input change', () => {
    const props = {
      ...defaultProps,
      toggleRefineOnMapMove: jest.fn(),
    };

    const wrapper = shallow(<Control {...props} />);

    expect(props.toggleRefineOnMapMove).toHaveBeenCalledTimes(0);

    wrapper.find('input').simulate('change');

    expect(props.toggleRefineOnMapMove).toHaveBeenCalledTimes(1);
  });

  it('expect to call refineWithInstance on button click', () => {
    const mapInstance = createFakeMapInstance();

    const props = {
      ...defaultProps,
      googleMapsInstance: mapInstance,
      isRefineOnMapMove: false,
      hasMapMoveSinceLastRefine: true,
      refineWithInstance: jest.fn(),
    };

    const wrapper = shallow(<Control {...props} />);

    expect(props.refineWithInstance).toHaveBeenCalledTimes(0);

    wrapper.find('button').simulate('click');

    expect(props.refineWithInstance).toHaveBeenCalledTimes(1);
    expect(props.refineWithInstance).toHaveBeenCalledWith(mapInstance);
  });
});