Skip to content

Commit cde557f

Browse files
committed
test: update ParallaxBanner tests using react-testing-library
1 parent 1a3aadf commit cde557f

File tree

6 files changed

+181
-270
lines changed

6 files changed

+181
-270
lines changed

jest-setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom';

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"/stories/"
5252
],
5353
"collectCoverage": true,
54-
"testURL": "http://localhost"
54+
"testURL": "http://localhost",
55+
"setupFilesAfterEnv": ["<rootDir>/jest-setup.ts"]
5556
},
5657
"peerDependencies": {
5758
"react": "^16.8.0-0 || >=17.0.1",
@@ -94,6 +95,7 @@
9495
"@storybook/addons": "^6.4.9",
9596
"@storybook/preset-scss": "^1.0.3",
9697
"@storybook/react": "^6.4.9",
98+
"@testing-library/jest-dom": "^5.16.1",
9799
"@testing-library/react": "^12.1.2",
98100
"@types/jest": "^27.0.3",
99101
"@types/react": "^17.0.35",
@@ -105,6 +107,7 @@
105107
"postcss": "^8",
106108
"react": "^17.0.2",
107109
"react-dom": "^17.0.2",
110+
"react-hooks-testing-library": "^0.6.0",
108111
"react-is": "^17.0.2",
109112
"react-test-renderer": "^17.0.1",
110113
"sass": "^1.43.4",
Lines changed: 15 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,179 +1,25 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Expect the <ParallaxBanner> component to render custom child banners 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-
>
3+
exports[`given a <ParallaxBanner> component with all props then it will render banners correctly 1`] = `
4+
<DocumentFragment>
175
<div
18-
style={
19-
Object {
20-
"bottom": 0,
21-
"left": 0,
22-
"position": "absolute",
23-
"right": 0,
24-
"top": 0,
25-
}
26-
}
6+
class="parallax-banner test-class"
7+
style="position: relative; overflow: hidden; width: 100%; height: 50vh; background-color: blue; border: 1px solid red;"
278
>
289
<div
29-
className="parallax-banner-layer-0"
30-
style={
31-
Object {
32-
"bottom": "-20px",
33-
"left": 0,
34-
"position": "absolute",
35-
"right": 0,
36-
"top": "-20px",
37-
}
38-
}
10+
style="position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; will-change: transform; transform: translateY(-20px);"
3911
>
40-
<div>
41-
test
42-
</div>
12+
<div
13+
class="parallax-banner-layer-0"
14+
data-testid="layer-0"
15+
style="background-image: url(https://foo.com/bar.jpg); background-position: center; background-size: cover; position: absolute; top: -20px; right: 0px; bottom: -20px; left: 0px;"
16+
/>
4317
</div>
44-
</div>
45-
</div>
46-
`;
47-
48-
exports[`Expect the <ParallaxBanner> component to render image banners correctly 1`] = `
49-
<div
50-
className="parallax-banner test-class"
51-
style={
52-
Object {
53-
"backgroundColor": "blue",
54-
"border": "1px solid red",
55-
"height": "50vh",
56-
"overflow": "hidden",
57-
"position": "relative",
58-
"width": "100%",
59-
}
60-
}
61-
>
62-
<div
63-
style={
64-
Object {
65-
"bottom": 0,
66-
"left": 0,
67-
"position": "absolute",
68-
"right": 0,
69-
"top": 0,
70-
}
71-
}
72-
>
73-
<div
74-
className="parallax-banner-layer-0"
75-
style={
76-
Object {
77-
"backgroundImage": "url(https://foo.com/bar.jpg)",
78-
"backgroundPosition": "center",
79-
"backgroundSize": "cover",
80-
"bottom": "-20px",
81-
"left": 0,
82-
"position": "absolute",
83-
"right": 0,
84-
"top": "-20px",
85-
}
86-
}
87-
/>
88-
</div>
89-
<div>
90-
<h1>
91-
Foo Bar
92-
</h1>
93-
</div>
94-
</div>
95-
`;
96-
97-
exports[`Expect the <ParallaxBanner> component to render layers with custom props 1`] = `
98-
<div
99-
className="parallax-banner"
100-
style={
101-
Object {
102-
"height": "50vh",
103-
"overflow": "hidden",
104-
"position": "relative",
105-
"width": "100%",
106-
}
107-
}
108-
>
109-
<div
110-
style={
111-
Object {
112-
"bottom": 0,
113-
"left": 0,
114-
"position": "absolute",
115-
"right": 0,
116-
"top": 0,
117-
}
118-
}
119-
>
120-
<div
121-
className="parallax-banner-layer-0 my-custom-class"
122-
id="my-id"
123-
style={
124-
Object {
125-
"backgroundColor": "red",
126-
"bottom": "-20px",
127-
"left": 0,
128-
"position": "absolute",
129-
"right": 0,
130-
"top": "-20px",
131-
}
132-
}
133-
/>
134-
</div>
135-
</div>
136-
`;
137-
138-
exports[`Expect the <ParallaxBanner> component to render without expanded margins 1`] = `
139-
<div
140-
className="parallax-banner"
141-
style={
142-
Object {
143-
"height": "50vh",
144-
"overflow": "hidden",
145-
"position": "relative",
146-
"width": "100%",
147-
}
148-
}
149-
>
150-
<div
151-
style={
152-
Object {
153-
"bottom": 0,
154-
"left": 0,
155-
"position": "absolute",
156-
"right": 0,
157-
"top": 0,
158-
}
159-
}
160-
>
161-
<div
162-
className="parallax-banner-layer-0"
163-
style={
164-
Object {
165-
"bottom": 0,
166-
"left": 0,
167-
"position": "absolute",
168-
"right": 0,
169-
"top": 0,
170-
}
171-
}
172-
>
173-
<div>
174-
test
175-
</div>
18+
<div>
19+
<h1>
20+
Foo Bar
21+
</h1>
17622
</div>
17723
</div>
178-
</div>
24+
</DocumentFragment>
17925
`;

0 commit comments

Comments
 (0)