This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(context): migrate Panel (#2203)
* chore(context): migrate Panel This migration is fairly straightforward, and has no impact on how the PanelCallbackHandler is used, although it adds a new component in that tree so it can read the context IFW-485
- Loading branch information
Showing
6 changed files
with
187 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 70 additions & 74 deletions
144
packages/react-instantsearch-dom/src/components/__tests__/PanelCallbackHandler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,118 @@ | ||
import React from 'react'; | ||
import Enzyme, { shallow } from 'enzyme'; | ||
import Enzyme, { shallow, mount } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
import PanelCallbackHandler from '../PanelCallbackHandler'; | ||
import { PanelProvider } from '../Panel'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
describe('PanelCallbackHandler', () => { | ||
it('expect to render', () => { | ||
const props = { | ||
canRefine: true, | ||
}; | ||
|
||
const wrapper = shallow( | ||
<PanelCallbackHandler {...props}> | ||
const wrapper = mount( | ||
<PanelCallbackHandler canRefine> | ||
<div>Hello content</div> | ||
</PanelCallbackHandler> | ||
); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
expect(wrapper).toMatchInlineSnapshot(` | ||
<PanelWrapper | ||
canRefine={true} | ||
> | ||
<PanelCallbackHandler | ||
canRefine={true} | ||
setCanRefine={[Function]} | ||
> | ||
<div> | ||
Hello content | ||
</div> | ||
</PanelCallbackHandler> | ||
</PanelWrapper> | ||
`); | ||
}); | ||
|
||
describe('willMount', () => { | ||
describe('didMount', () => { | ||
it('expect to call setCanRefine when the context is given', () => { | ||
const props = { | ||
canRefine: true, | ||
}; | ||
|
||
const context = { | ||
setCanRefine: jest.fn(), | ||
}; | ||
|
||
shallow( | ||
<PanelCallbackHandler {...props}> | ||
<div>Hello content</div> | ||
</PanelCallbackHandler>, | ||
{ context } | ||
const setCanRefine = jest.fn(); | ||
|
||
mount( | ||
<PanelProvider value={setCanRefine}> | ||
<PanelCallbackHandler canRefine> | ||
<div>Hello content</div> | ||
</PanelCallbackHandler> | ||
</PanelProvider> | ||
); | ||
|
||
expect(context.setCanRefine).toHaveBeenCalledTimes(1); | ||
expect(context.setCanRefine).toHaveBeenCalledWith(true); | ||
expect(setCanRefine).toHaveBeenCalledTimes(1); | ||
expect(setCanRefine).toHaveBeenCalledWith(true); | ||
}); | ||
|
||
it('expect to not throw when the context is not given', () => { | ||
const props = { | ||
canRefine: true, | ||
}; | ||
|
||
const trigger = () => | ||
expect(() => | ||
shallow( | ||
<PanelCallbackHandler {...props}> | ||
<PanelCallbackHandler canRefine> | ||
<div>Hello content</div> | ||
</PanelCallbackHandler> | ||
); | ||
|
||
expect(() => trigger()).not.toThrow(); | ||
) | ||
).not.toThrow(); | ||
}); | ||
}); | ||
|
||
describe('willReceiveProps', () => { | ||
describe('didUpdate', () => { | ||
it('expect to call setCanRefine when the context is given', () => { | ||
const props = { | ||
canRefine: true, | ||
}; | ||
|
||
const context = { | ||
setCanRefine: jest.fn(), | ||
}; | ||
|
||
const wrapper = shallow( | ||
<PanelCallbackHandler {...props}> | ||
<div>Hello content</div> | ||
</PanelCallbackHandler>, | ||
{ context } | ||
const setCanRefine = jest.fn(); | ||
|
||
const wrapper = mount( | ||
<PanelProvider value={setCanRefine}> | ||
<PanelCallbackHandler canRefine> | ||
<div>Hello content</div> | ||
</PanelCallbackHandler> | ||
</PanelProvider> | ||
); | ||
|
||
wrapper.setProps({ canRefine: false }); | ||
wrapper.setProps({ | ||
children: ( | ||
<PanelCallbackHandler canRefine={false}> | ||
<div>Hello content</div> | ||
</PanelCallbackHandler> | ||
), | ||
}); | ||
|
||
expect(context.setCanRefine).toHaveBeenCalledTimes(2); | ||
expect(context.setCanRefine).toHaveBeenLastCalledWith(false); | ||
expect(setCanRefine).toHaveBeenCalledTimes(2); | ||
expect(setCanRefine).toHaveBeenLastCalledWith(false); | ||
}); | ||
|
||
it('expect to not call setCanRefine when the nextProps is the same', () => { | ||
const props = { | ||
canRefine: true, | ||
}; | ||
|
||
const context = { | ||
setCanRefine: jest.fn(), | ||
}; | ||
|
||
const wrapper = shallow( | ||
<PanelCallbackHandler {...props}> | ||
<div>Hello content</div> | ||
</PanelCallbackHandler>, | ||
{ context } | ||
const setCanRefine = jest.fn(); | ||
|
||
const wrapper = mount( | ||
<PanelProvider value={setCanRefine}> | ||
<PanelCallbackHandler canRefine> | ||
<div>Hello content</div> | ||
</PanelCallbackHandler> | ||
</PanelProvider> | ||
); | ||
|
||
wrapper.setProps({ canRefine: true }); | ||
wrapper.setProps({ | ||
children: ( | ||
<PanelCallbackHandler canRefine> | ||
<div>Hello content</div> | ||
</PanelCallbackHandler> | ||
), | ||
}); | ||
|
||
expect(context.setCanRefine).toHaveBeenCalledTimes(1); | ||
expect(setCanRefine).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('expect to not throw when the context is not given', () => { | ||
const props = { | ||
canRefine: true, | ||
}; | ||
|
||
const trigger = () => { | ||
expect(() => { | ||
const wrapper = shallow( | ||
<PanelCallbackHandler {...props}> | ||
<PanelCallbackHandler canRefine> | ||
<div>Hello content</div> | ||
</PanelCallbackHandler> | ||
); | ||
|
||
wrapper.setProps({ canRefine: false }); | ||
}; | ||
|
||
expect(() => trigger()).not.toThrow(); | ||
}).not.toThrow(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.