Skip to content

Commit

Permalink
initial 1.0 extraction of HoverImage
Browse files Browse the repository at this point in the history
  • Loading branch information
jwo committed Oct 19, 2017
0 parents commit 90b4e72
Show file tree
Hide file tree
Showing 9 changed files with 5,864 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .babelrc
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"
]
}
58 changes: 58 additions & 0 deletions __tests__/HoverImage.test.js
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()
});
60 changes: 60 additions & 0 deletions __tests__/__snapshots__/HoverImage.test.js.snap
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,
},
},
},
}
`;
Loading

0 comments on commit 90b4e72

Please sign in to comment.