File size: 3,707 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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | import React from 'react';
import Enzyme, { shallow } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import Connected, { CurrentRefinements } from '../CurrentRefinements';
Enzyme.configure({ adapter: new Adapter() });
describe('CurrentRefinements', () => {
const defaultProps = {
items: [],
canRefine: true,
refine: () => {},
translate: (x) => x,
};
it('expect to render a list of current refinements', () => {
const props = {
...defaultProps,
items: [
{ label: 'color: Red', value: () => {} },
{
label: 'category:',
value: () => {},
items: [
{ label: 'iPhone', value: () => {} },
{ label: 'iPad', value: () => {} },
],
},
],
};
const wrapper = shallow(<CurrentRefinements {...props} />);
expect(wrapper).toMatchSnapshot();
});
it('expect to render a list without refinements', () => {
const props = {
...defaultProps,
canRefine: false,
};
const wrapper = shallow(<CurrentRefinements {...props} />);
expect(wrapper).toMatchSnapshot();
});
it('expect to render a list with a custom className', () => {
const props = {
...defaultProps,
className: 'MyCustomCurrentRefinements',
};
const wrapper = shallow(<CurrentRefinements {...props} />);
expect(wrapper).toMatchSnapshot();
});
it('expect to refine the "color" onClick', () => {
const value = () => {};
const props = {
...defaultProps,
items: [
{ label: 'color: Red', value },
{
label: 'category:',
value: () => {},
items: [
{ label: 'iPhone', value: () => {} },
{ label: 'iPad', value: () => {} },
],
},
],
refine: jest.fn(),
};
const wrapper = shallow(<CurrentRefinements {...props} />);
expect(props.refine).not.toHaveBeenCalled();
wrapper.find('li').first().find('button').simulate('click');
expect(props.refine).toHaveBeenCalledWith(value);
});
it('expect to refine the "category: iPad" onClick', () => {
const value = () => {};
const props = {
...defaultProps,
items: [
{ label: 'color: Red', value: () => {} },
{
label: 'category:',
value: () => {},
items: [
{ label: 'iPhone', value: () => {} },
{ label: 'iPad', value },
],
},
],
refine: jest.fn(),
};
const wrapper = shallow(<CurrentRefinements {...props} />);
expect(props.refine).not.toHaveBeenCalled();
wrapper.find('li').last().find('button').last().simulate('click');
expect(props.refine).toHaveBeenCalledWith(value);
});
});
describe('CurrentRefinements - Connected', () => {
const defaultProps = {
items: [
{ label: 'color: Red', value: () => {} },
{
label: 'category:',
value: () => {},
items: [
{ label: 'iPhone', value: () => {} },
{ label: 'iPad', value: () => {} },
],
},
],
canRefine: true,
refine: () => {},
};
it('expect to render a list of current refinements', () => {
const props = {
...defaultProps,
};
const wrapper = shallow(<Connected {...props} />).dive();
expect(wrapper).toMatchSnapshot();
});
it('expect to render a list of current refinements with custom translations', () => {
const props = {
...defaultProps,
translations: {
clearFilter: 'DELETE',
},
};
const wrapper = shallow(<Connected {...props} />).dive();
expect(wrapper).toMatchSnapshot();
});
});
|