Skip to content

Commit b38f86f

Browse files
authored
Add tests for border radius shared layout animations (#3047)
* Latest * Latest
1 parent c549c5a commit b38f86f

File tree

3 files changed

+111
-1
lines changed

3 files changed

+111
-1
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ test-e2e: test-nextjs test-html test-react test-react-19
9595
yarn test-playwright
9696

9797
test-single: build test-mkdir
98-
yarn start-server-and-test "yarn dev-server" http://localhost:9990 "cd packages/framer-motion && cypress run --headless --spec cypress/integration/animate-style.ts"
98+
yarn start-server-and-test "yarn dev-server" http://localhost:9990 "cd packages/framer-motion && cypress run --headless --spec cypress/integration/layout-shared.ts"
99+
99100

100101
lint: bootstrap
101102
yarn lint
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { motion, MotionConfig } from "framer-motion"
2+
import { useState } from "react"
3+
4+
const transition = {
5+
// ease: () => 0.5,
6+
duration: 10,
7+
}
8+
9+
function BoxA({ isOpen }: { isOpen: boolean }) {
10+
return (
11+
<div style={container}>
12+
<motion.div
13+
style={{ ...a, borderRadius: 24 }}
14+
transition={transition}
15+
layoutId="boxA"
16+
/>
17+
{isOpen && (
18+
<motion.div
19+
className="measure-box"
20+
style={{ ...b, borderRadius: 0 }}
21+
transition={transition}
22+
layoutId="boxA"
23+
/>
24+
)}
25+
</div>
26+
)
27+
}
28+
29+
function BoxB({ isOpen }: { isOpen: boolean }) {
30+
return (
31+
<div style={container}>
32+
{!isOpen ? (
33+
<motion.div
34+
key="a"
35+
style={{ ...a, borderRadius: 24 }}
36+
transition={transition}
37+
layoutId="boxB"
38+
/>
39+
) : (
40+
<motion.div
41+
key="b"
42+
className="measure-box"
43+
style={{ ...b, borderRadius: 0 }}
44+
transition={transition}
45+
layoutId="boxB"
46+
/>
47+
)}
48+
</div>
49+
)
50+
}
51+
52+
export const App = () => {
53+
const [isOpen, setOpen] = useState(false)
54+
55+
return (
56+
<MotionConfig transition={{ duration: 1 }}>
57+
<button id="next" onClick={() => setOpen(!isOpen)}>
58+
Next
59+
</button>
60+
<BoxA isOpen={isOpen} />
61+
<BoxB isOpen={isOpen} />
62+
</MotionConfig>
63+
)
64+
}
65+
66+
const box = {
67+
background: "red",
68+
gridArea: "1 / 1",
69+
}
70+
71+
const container = {
72+
display: "flex",
73+
justifyContent: "center",
74+
alignItems: "center",
75+
gap: 20,
76+
width: 300,
77+
height: 300,
78+
}
79+
80+
const a = {
81+
...box,
82+
width: 80,
83+
height: 80,
84+
}
85+
86+
const b = {
87+
...box,
88+
left: 200,
89+
width: 140,
90+
height: 140,
91+
}

packages/framer-motion/cypress/integration/layout-shared.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,3 +1184,21 @@ describe("Shared layout: Measures rotated elements correctly when animation is i
11841184
})
11851185
})
11861186
})
1187+
1188+
describe("Shared layout: Border radius", () => {
1189+
it("Should animate border radius", () => {
1190+
cy.visit("?test=layout-shared-border-radius")
1191+
.wait(50)
1192+
.get("#next")
1193+
.click()
1194+
.wait(200)
1195+
.get(".measure-box")
1196+
.should(([$boxA, $boxB]: any) => {
1197+
const boxAStyle = window.getComputedStyle($boxA)
1198+
const boxBStyle = window.getComputedStyle($boxB)
1199+
expect(boxAStyle.borderRadius).not.to.equal("0%")
1200+
expect(boxBStyle.borderRadius).not.to.equal("0%")
1201+
expect(boxBStyle.borderRadius).to.equal(boxAStyle.borderRadius)
1202+
})
1203+
})
1204+
})

0 commit comments

Comments
 (0)