Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
test(maps): test Provider mapValue reference
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Mar 6, 2019
1 parent a201bb2 commit f6d2411
Showing 1 changed file with 29 additions and 65 deletions.
94 changes: 29 additions & 65 deletions packages/react-instantsearch-dom-maps/src/__tests__/Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,130 +437,94 @@ describe('Provider', () => {
);
});

it('expect to pass same reference for toggleRefineOnMapMove when isRefineOnMapMove changes', () => {
it('expect to pass new mapValue reference when isRefineOnMapMove changes', () => {
const props = {
...defaultProps,
toggleRefineOnMapMove: jest.fn(),
};

const wrapper = shallow(<Provider {...props} />);
const mapValue = wrapper.instance().mapValue;

expect(wrapper.props().value.toggleRefineOnMapMove).toEqual(
wrapper.instance().mapValue.toggleRefineOnMapMove
);
expect(mapValue).toBe(wrapper.instance().mapValue);

wrapper.setProps({
isRefineOnMapMove: false,
});

expect(wrapper.props().value.toggleRefineOnMapMove).toEqual(
wrapper.instance().mapValue.toggleRefineOnMapMove
);
expect(mapValue).not.toBe(wrapper.instance().mapValue);
});

it('expect to pass same reference for toggleRefineOnMapMove when hasMapMoveSinceLastRefine changes', () => {
it('expect to pass new mapValue reference when hasMapMoveSinceLastRefine changes', () => {
const props = {
...defaultProps,
toggleRefineOnMapMove: jest.fn(),
hasMapMoveSinceLastRefine: false,
};

const wrapper = shallow(<Provider {...props}>{x => x}</Provider>);
const wrapper = shallow(<Provider {...props} />);
const mapValue = wrapper.instance().mapValue;

expect(wrapper.props().value.toggleRefineOnMapMove).toEqual(
wrapper.instance().mapValue.toggleRefineOnMapMove
);
expect(mapValue).toBe(wrapper.instance().mapValue);

wrapper.setProps({
hasMapMoveSinceLastRefine: false,
hasMapMoveSinceLastRefine: true,
});

expect(wrapper.props().value.toggleRefineOnMapMove).toEqual(
wrapper.instance().mapValue.toggleRefineOnMapMove
);
expect(mapValue).not.toBe(wrapper.instance().mapValue);
});

it('expect to pass same reference for setMapMoveSinceLastRefine when isRefineOnMapMove changes', () => {
it('expect to pass same mapValue reference when toggleRefineOnMapMove changes', () => {
const props = {
...defaultProps,
setMapMoveSinceLastRefine: jest.fn(),
toggleRefineOnMapMove: jest.fn(),
};

const wrapper = shallow(<Provider {...props}>{x => x}</Provider>);
const wrapper = shallow(<Provider {...props} />);
const mapValue = wrapper.instance().mapValue;

expect(wrapper.props().value.setMapMoveSinceLastRefine).toEqual(
wrapper.instance().mapValue.setMapMoveSinceLastRefine
);
expect(mapValue).toBe(wrapper.instance().mapValue);

wrapper.setProps({
isRefineOnMapMove: false,
toggleRefineOnMapMove: jest.fn(),
});

expect(wrapper.props().value.setMapMoveSinceLastRefine).toEqual(
wrapper.instance().mapValue.setMapMoveSinceLastRefine
);
expect(mapValue).toBe(wrapper.instance().mapValue);
});

it('expect to pass same reference for setMapMoveSinceLastRefine when hasMapMoveSinceLastRefine changes', () => {
it('expect to pass same mapValue reference when setMapMoveSinceLastRefine changes', () => {
const props = {
...defaultProps,
setMapMoveSinceLastRefine: jest.fn(),
};

const wrapper = shallow(<Provider {...props}>{x => x}</Provider>);
const wrapper = shallow(<Provider {...props} />);
const mapValue = wrapper.instance().mapValue;

expect(wrapper.props().value.setMapMoveSinceLastRefine).toEqual(
wrapper.instance().mapValue.setMapMoveSinceLastRefine
);
expect(mapValue).toBe(wrapper.instance().mapValue);

wrapper.setProps({
hasMapMoveSinceLastRefine: false,
setMapMoveSinceLastRefine: jest.fn(),
});

expect(wrapper.props().value.setMapMoveSinceLastRefine).toEqual(
wrapper.instance().mapValue.setMapMoveSinceLastRefine
);
expect(mapValue).toBe(wrapper.instance().mapValue);
});

it('expect to pass same reference for refineWithInstance when isRefineOnMapMove changes', () => {
it('expect to pass same mapValue reference when refineWithInstance changes', () => {
const props = {
...defaultProps,
refineWithInstance: jest.fn(),
};

const wrapper = shallow(<Provider {...props}>{x => x}</Provider>);
const wrapper = shallow(<Provider {...props} />);
const mapValue = wrapper.instance().mapValue;

expect(wrapper.props().value.refineWithInstance).toEqual(
wrapper.instance().mapValue.refineWithInstance
);
expect(mapValue).toBe(wrapper.instance().mapValue);

wrapper.setProps({
isRefineOnMapMove: false,
});

expect(wrapper.props().value.refineWithInstance).toEqual(
wrapper.instance().mapValue.refineWithInstance
);
});

it('expect to pass same reference for refineWithInstance when hasMapMoveSinceLastRefine changes', () => {
const props = {
...defaultProps,
refineWithInstance: jest.fn(),
};

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

expect(wrapper.props().value.refineWithInstance).toEqual(
wrapper.instance().mapValue.refineWithInstance
);

wrapper.setProps({
hasMapMoveSinceLastRefine: false,
});

expect(wrapper.props().value.refineWithInstance).toEqual(
wrapper.instance().mapValue.refineWithInstance
);
expect(mapValue).toBe(wrapper.instance().mapValue);
});
});
});

0 comments on commit f6d2411

Please sign in to comment.