-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial 1.0 extraction of HoverImage
- Loading branch information
0 parents
commit 90b4e72
Showing
9 changed files
with
5,864 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"presets": ["env", "stage-0", "react"], | ||
"plugins": [ | ||
"transform-object-rest-spread", | ||
"transform-react-jsx" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react'; | ||
import Enzyme, { shallow, mount, render } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
import HoverImage from '../src'; | ||
|
||
test('Displays initial src image', () => { | ||
const wrapper = mount( <HoverImage src={"/img/first.png"} hoverSrc={"/img/first-hover.png"} />) | ||
expect(wrapper.state().src).toBe("/img/first.png"); | ||
}) | ||
|
||
test('Changes to hoverSrc on mouseOver', () => { | ||
const wrapper = mount( <HoverImage src={"/img/first.png"} hoverSrc={"/img/first-hover.png"} />) | ||
wrapper.find("img").simulate('mouseover'); | ||
expect(wrapper.state().src).toBe("/img/first-hover.png"); | ||
}) | ||
|
||
test('When given an onClick, it gets called when clicked', () => { | ||
|
||
const doneChange = jest.fn(); | ||
|
||
const wrapper = shallow( | ||
<HoverImage onClick={doneChange} src={"/img/first.png"} hoverSrc={"/img/first-hover.png"} /> | ||
); | ||
wrapper.find('img').simulate('click'); | ||
expect(doneChange).toBeCalled(); | ||
}); | ||
|
||
test('When given an onClick, it does not get called when disabled', () => { | ||
|
||
const doneChange = jest.fn(); | ||
const disabled = true | ||
|
||
const wrapper = shallow(<HoverImage disabled={disabled} onClick={doneChange} src={"/img/first.png"} hoverSrc={"/img/first-hover.png"} />) | ||
wrapper.find('img').simulate('click'); | ||
|
||
expect(doneChange).not.toBeCalled(); | ||
}); | ||
|
||
test('No errors if click, but no onClick provided', () => { | ||
|
||
const wrapper = shallow(<HoverImage src={"/img/first.png"} hoverSrc={"/img/first-hover.png"} />) | ||
expect( () => { | ||
wrapper.find('img').simulate('click') | ||
}).not.toThrowError() | ||
|
||
}); | ||
|
||
test('Matches snapshot', () => { | ||
|
||
const doneChange = jest.fn(); | ||
const disabled = false | ||
|
||
const wrapper = shallow(<HoverImage disabled={disabled} onClick={doneChange} src={"/img/first.png"} hoverSrc={"/img/first-hover.png"} />) | ||
|
||
expect(wrapper).toMatchSnapshot() | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Matches snapshot 1`] = ` | ||
ShallowWrapper { | ||
"length": 1, | ||
Symbol(enzyme.__root__): [Circular], | ||
Symbol(enzyme.__unrendered__): <HoverImage | ||
disabled={false} | ||
hoverSrc="/img/first-hover.png" | ||
onClick={[Function]} | ||
src="/img/first.png" | ||
/>, | ||
Symbol(enzyme.__renderer__): Object { | ||
"batchedUpdates": [Function], | ||
"getNode": [Function], | ||
"render": [Function], | ||
"simulateEvent": [Function], | ||
"unmount": [Function], | ||
}, | ||
Symbol(enzyme.__node__): Object { | ||
"instance": null, | ||
"key": null, | ||
"nodeType": "host", | ||
"props": Object { | ||
"onClick": [Function], | ||
"onMouseOut": [Function], | ||
"onMouseOver": [Function], | ||
"src": "/img/first.png", | ||
"style": undefined, | ||
}, | ||
"ref": null, | ||
"rendered": null, | ||
"type": "img", | ||
}, | ||
Symbol(enzyme.__nodes__): Array [ | ||
Object { | ||
"instance": null, | ||
"key": null, | ||
"nodeType": "host", | ||
"props": Object { | ||
"onClick": [Function], | ||
"onMouseOut": [Function], | ||
"onMouseOver": [Function], | ||
"src": "/img/first.png", | ||
"style": undefined, | ||
}, | ||
"ref": null, | ||
"rendered": null, | ||
"type": "img", | ||
}, | ||
], | ||
Symbol(enzyme.__options__): Object { | ||
"adapter": ReactSixteenAdapter { | ||
"options": Object { | ||
"enableComponentDidUpdateOnSetState": true, | ||
}, | ||
}, | ||
}, | ||
} | ||
`; |
Oops, something went wrong.