File size: 2,434 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import React from 'react';
import Enzyme, { shallow, mount } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import Panel, { PanelConsumer } from '../Panel';

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

describe('Panel', () => {
  it('expect to render', () => {
    const wrapper = shallow(
      <Panel>
        <div>Hello content</div>
      </Panel>
    );

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

  it('expect to render with custom className', () => {
    const props = {
      className: 'ais-Panel-Breadcrumb',
    };

    const wrapper = shallow(
      <Panel {...props}>
        <div>Hello content</div>
      </Panel>
    );

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

  it('expect to render without refinement', () => {
    const wrapper = shallow(
      <Panel>
        <div>Hello content</div>
      </Panel>
    );

    wrapper.setState({ canRefine: false });

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

  it('expect to render with header', () => {
    const props = {
      header: <p>Header</p>,
    };

    const wrapper = shallow(
      <Panel {...props}>
        <div>Hello content</div>
      </Panel>
    );

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

  it('expect to render with footer', () => {
    const props = {
      footer: <p>Footer</p>,
    };

    const wrapper = shallow(
      <Panel {...props}>
        <div>Hello content</div>
      </Panel>
    );

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

  it('expect to expose context to its children', () => {
    let provided;
    const wrapper = mount(
      <Panel>
        <PanelConsumer>
          {(setCanRefine) => {
            provided = setCanRefine;
            return null;
          }}
        </PanelConsumer>
      </Panel>
    );

    expect(provided).toEqual(wrapper.instance().setCanRefine);
  });

  it('expect to render when setCanRefine is called', () => {
    const wrapper = mount(
      <Panel>
        <PanelConsumer>
          {(setCanRefine) => (
            <button onClick={() => setCanRefine(false)}>
              call setCanRefine
            </button>
          )}
        </PanelConsumer>
      </Panel>
    );

    expect(wrapper.state('canRefine')).toBe(true);
    expect(wrapper).toMatchSnapshot();

    // Simulate context call
    wrapper.find('button').simulate('click');

    expect(wrapper.state('canRefine')).toBe(false);
    expect(wrapper).toMatchSnapshot();
  });
});