Skip to content

Commit 4766db5

Browse files
committed
add ParallaxBanner tests
1 parent a5afa46 commit 4766db5

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

__tests__/ParallaxBanner.test.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
3+
import ReactDOM from 'react-dom';
4+
import renderer from 'react-test-renderer';
5+
import ParallaxBanner from 'components/ParallaxBanner';
6+
import ParallaxProvider from 'components/ParallaxProvider';
7+
import ParallaxController from 'libs/ParallaxController';
8+
9+
describe('Expect the <ParallaxBanner> component', () => {
10+
afterEach(() => {});
11+
12+
it('to render correctly', () => {
13+
// Workaround for refs
14+
// See https://github.com/facebook/react/issues/7740
15+
const div = document.createElement('div');
16+
function createNodeMock() {
17+
return {
18+
getBoundingClientRect: () => div.getBoundingClientRect(),
19+
};
20+
}
21+
22+
const tree = renderer
23+
.create(
24+
<ParallaxProvider>
25+
<ParallaxBanner
26+
className="test-class"
27+
disabled={false}
28+
layers={[
29+
{
30+
image: 'https://foo.com/bar.jpg',
31+
amount: 0.2,
32+
slowerScrollRate: false,
33+
},
34+
]}
35+
style={{
36+
backgroundColor: 'blue',
37+
border: '1px solid red',
38+
}}
39+
>
40+
<div>
41+
<h1>Foo Bar</h1>
42+
</div>
43+
</ParallaxBanner>
44+
</ParallaxProvider>,
45+
{
46+
createNodeMock,
47+
}
48+
)
49+
.toJSON();
50+
expect(tree).toMatchSnapshot();
51+
});
52+
53+
it('to render children', () => {
54+
const node = document.createElement('div');
55+
56+
let child = jest.fn();
57+
const Child = () => {
58+
child();
59+
return <div />;
60+
};
61+
62+
ReactDOM.render(
63+
<ParallaxProvider>
64+
<ParallaxBanner layers={[]}>
65+
<Child />
66+
</ParallaxBanner>
67+
</ParallaxProvider>,
68+
node
69+
);
70+
71+
expect(child).toBeCalled();
72+
});
73+
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Expect the <ParallaxBanner> component to render correctly 1`] = `
4+
<div
5+
className="parallax-banner test-class"
6+
style={
7+
Object {
8+
"backgroundColor": "blue",
9+
"border": "1px solid red",
10+
"height": "50vh",
11+
"overflow": "hidden",
12+
"position": "relative",
13+
"width": "100%",
14+
}
15+
}
16+
>
17+
<div
18+
className="parallax-outer"
19+
style={
20+
Object {
21+
"bottom": 0,
22+
"left": 0,
23+
"position": "absolute",
24+
"right": 0,
25+
"top": 0,
26+
}
27+
}
28+
>
29+
<div
30+
className="parallax-inner"
31+
style={
32+
Object {
33+
"bottom": 0,
34+
"left": 0,
35+
"position": "absolute",
36+
"right": 0,
37+
"top": 0,
38+
}
39+
}
40+
>
41+
<div
42+
className="parallax-banner-layer-0"
43+
style={
44+
Object {
45+
"backgroundImage": "url(https://foo.com/bar.jpg)",
46+
"backgroundPosition": "center",
47+
"backgroundSize": "cover",
48+
"bottom": "-20%",
49+
"left": 0,
50+
"position": "absolute",
51+
"right": 0,
52+
"top": "-20%",
53+
}
54+
}
55+
/>
56+
</div>
57+
</div>
58+
<div>
59+
<h1>
60+
Foo Bar
61+
</h1>
62+
</div>
63+
</div>
64+
`;

0 commit comments

Comments
 (0)