Skip to content

Commit e7ae2b3

Browse files
committed
test: 💍 spinner component
1 parent 9c29a58 commit e7ae2b3

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"react-dom": "^16.12.0",
7272
"react-styleguidist": "^9.1.12",
7373
"react-test-renderer": "^16.13.0",
74+
"snapshot-diff": "^0.7.0",
7475
"style-loader": "^0.23.1",
7576
"typescript": "^3.7.5",
7677
"url-loader": "^2.1.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Spinner spec diffs snapshots with different colors 1`] = `
4+
"Snapshot Diff:
5+
- First value
6+
+ Second value
7+
8+
@@ -41,11 +41,11 @@
9+
class=\\"vtex-spinner_circle\\"
10+
cx=\\"50\\"
11+
cy=\\"50\\"
12+
fill=\\"none\\"
13+
r=\\"40\\"
14+
- stroke=\\"#000\\"
15+
+ stroke=\\"#fff\\"
16+
stroke-dasharray=\\"0 0 188.49555921538757 251.32741228718345\\"
17+
stroke-dashoffset=\\"1\\"
18+
stroke-linecap=\\"round\\"
19+
stroke-width=\\"10\\"
20+
/>"
21+
`;
22+
23+
exports[`Spinner spec diffs snapshots with different sizes 1`] = `
24+
"Snapshot Diff:
25+
- First value
26+
+ Second value
27+
28+
@@ -1,12 +1,12 @@
29+
<DocumentFragment>
30+
<svg
31+
class=\\"vtex__icon-spinner c-action-primary \\"
32+
- height=\\"50\\"
33+
+ height=\\"100\\"
34+
preserveAspectRatio=\\"xMidYMid\\"
35+
viewBox=\\"0 0 100 100\\"
36+
- width=\\"50\\"
37+
+ width=\\"100\\"
38+
xmlns=\\"http://www.w3.org/2000/svg\\"
39+
>
40+
<style>
41+
42+
@keyframes vtex-spinner-rotate {"
43+
`;
44+
45+
exports[`Spinner spec matches snapshot 1`] = `
46+
<DocumentFragment>
47+
<svg
48+
class="vtex__icon-spinner c-action-primary "
49+
height="40"
50+
preserveAspectRatio="xMidYMid"
51+
viewBox="0 0 100 100"
52+
width="40"
53+
xmlns="http://www.w3.org/2000/svg"
54+
>
55+
<style>
56+
57+
@keyframes vtex-spinner-rotate {
58+
from {
59+
transform-origin: 50% 50%;
60+
transform: rotate(0deg);
61+
}
62+
to {
63+
transform-origin: 50% 50%;
64+
transform: rotate(360deg);
65+
}
66+
}
67+
68+
@keyframes vtex-spinner-fill {
69+
0% {
70+
stroke-dasharray: 0 0 2 251.32741228718345;
71+
}
72+
50% {
73+
stroke-dasharray: 0 0 188.49555921538757 251.32741228718345;
74+
}
75+
100% {
76+
stroke-dasharray: 0 249.32741228718345 188.49555921538757 251.32741228718345;
77+
}
78+
}
79+
80+
.vtex-spinner_circle {
81+
animation: vtex-spinner-fill 1.25s infinite cubic-bezier(0.455, 0.030, 0.515, 0.955), vtex-spinner-rotate 0.625s infinite linear;
82+
}
83+
84+
</style>
85+
<circle
86+
class="vtex-spinner_circle"
87+
cx="50"
88+
cy="50"
89+
fill="none"
90+
r="40"
91+
stroke="currentColor"
92+
stroke-dasharray="0 0 188.49555921538757 251.32741228718345"
93+
stroke-dashoffset="1"
94+
stroke-linecap="round"
95+
stroke-width="10"
96+
/>
97+
</svg>
98+
</DocumentFragment>
99+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react'
2+
import { render } from '@testing-library/react'
3+
import snapshotDiff from 'snapshot-diff'
4+
5+
import Spinner from '../index'
6+
7+
describe('Spinner spec', () => {
8+
it('matches snapshot', () => {
9+
const component = render(<Spinner />)
10+
expect(component.asFragment()).toMatchSnapshot()
11+
})
12+
it('diffs snapshots with different colors', () => {
13+
const black = render(<Spinner color="#000" />)
14+
const white = render(<Spinner color="#fff" />)
15+
16+
expect(
17+
snapshotDiff(black.asFragment(), white.asFragment())
18+
).toMatchSnapshot()
19+
})
20+
it('diffs snapshots with different sizes', () => {
21+
const small = render(<Spinner size={50} />)
22+
const large = render(<Spinner size={100} />)
23+
24+
expect(
25+
snapshotDiff(small.asFragment(), large.asFragment())
26+
).toMatchSnapshot()
27+
})
28+
})

yarn.lock

+10
Original file line numberDiff line numberDiff line change
@@ -10014,6 +10014,16 @@ snapdragon@^0.8.1:
1001410014
source-map-resolve "^0.5.0"
1001510015
use "^3.1.0"
1001610016

10017+
snapshot-diff@^0.7.0:
10018+
version "0.7.0"
10019+
resolved "https://registry.yarnpkg.com/snapshot-diff/-/snapshot-diff-0.7.0.tgz#a9e93e848a90c9d3e6ffe645dfb89350e041f15e"
10020+
integrity sha512-KzFWZ02eu2BLAloZ4FlaMitUy7kw49Av8CGy50nZrl9mjqMAiibpYWgJppHDQwVcbPqt5HrdegDzF2J8Cmc+yg==
10021+
dependencies:
10022+
jest-diff "^25.1.0"
10023+
jest-snapshot "^25.1.0"
10024+
pretty-format "^25.1.0"
10025+
strip-ansi "^6.0.0"
10026+
1001710027
1001810028
version "1.4.0"
1001910029
resolved "https://registry.yarnpkg.com/sockjs-client/-/sockjs-client-1.4.0.tgz#c9f2568e19c8fd8173b4997ea3420e0bb306c7d5"

0 commit comments

Comments
 (0)