Skip to content

Commit 5a8909f

Browse files
committed
test(Rotate): add unit tests
1 parent 013240f commit 5a8909f

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import { motionTokens } from '@fluentui/react-motion';
2+
import { rotateAtom } from './rotate-atom';
3+
4+
describe('rotateAtom', () => {
5+
it('creates enter keyframes with rotation from angle to 0', () => {
6+
const atom = rotateAtom({
7+
direction: 'enter',
8+
duration: 300,
9+
easing: motionTokens.curveEasyEase,
10+
angle: -90,
11+
});
12+
13+
expect(atom).toMatchObject({
14+
duration: 300,
15+
easing: motionTokens.curveEasyEase,
16+
keyframes: [{ rotate: 'y -90deg' }, { rotate: 'y 0deg' }],
17+
});
18+
});
19+
20+
it('creates exit keyframes with rotation from 0 to exitAngle', () => {
21+
const atom = rotateAtom({
22+
direction: 'exit',
23+
duration: 250,
24+
easing: motionTokens.curveAccelerateMin,
25+
exitAngle: 90,
26+
});
27+
28+
expect(atom).toMatchObject({
29+
duration: 250,
30+
easing: motionTokens.curveAccelerateMin,
31+
keyframes: [{ rotate: 'y 0deg' }, { rotate: 'y 90deg' }],
32+
});
33+
});
34+
35+
it('uses default angle when not provided', () => {
36+
const atom = rotateAtom({
37+
direction: 'enter',
38+
duration: 300,
39+
});
40+
41+
expect(atom.keyframes).toEqual([{ rotate: 'y -90deg' }, { rotate: 'y 0deg' }]);
42+
});
43+
44+
it('uses default easing when not provided', () => {
45+
const atom = rotateAtom({
46+
direction: 'enter',
47+
duration: 300,
48+
angle: 45,
49+
});
50+
51+
expect(atom.easing).toBe(motionTokens.curveLinear);
52+
});
53+
54+
it('uses default axis when not provided', () => {
55+
const atom = rotateAtom({
56+
direction: 'enter',
57+
duration: 300,
58+
angle: 180,
59+
});
60+
61+
expect(atom.keyframes[0]).toEqual({ rotate: 'y 180deg' });
62+
expect(atom.keyframes[1]).toEqual({ rotate: 'y 0deg' });
63+
});
64+
65+
it('handles different rotation axes', () => {
66+
const atomX = rotateAtom({
67+
direction: 'enter',
68+
duration: 300,
69+
axis: 'x',
70+
angle: 45,
71+
});
72+
73+
const atomY = rotateAtom({
74+
direction: 'enter',
75+
duration: 300,
76+
axis: 'y',
77+
angle: 45,
78+
});
79+
80+
const atomZ = rotateAtom({
81+
direction: 'enter',
82+
duration: 300,
83+
axis: 'z',
84+
angle: 45,
85+
});
86+
87+
expect(atomX.keyframes[0]).toEqual({ rotate: 'x 45deg' });
88+
expect(atomY.keyframes[0]).toEqual({ rotate: 'y 45deg' });
89+
expect(atomZ.keyframes[0]).toEqual({ rotate: 'z 45deg' });
90+
});
91+
92+
it('uses exitAngle when direction is exit', () => {
93+
const atom = rotateAtom({
94+
direction: 'exit',
95+
duration: 300,
96+
angle: -90,
97+
exitAngle: 45,
98+
});
99+
100+
expect(atom.keyframes).toEqual([{ rotate: 'y 0deg' }, { rotate: 'y 45deg' }]);
101+
});
102+
103+
it('uses negated angle as default exitAngle', () => {
104+
const atom = rotateAtom({
105+
direction: 'exit',
106+
duration: 300,
107+
angle: -90,
108+
});
109+
110+
expect(atom.keyframes).toEqual([{ rotate: 'y 0deg' }, { rotate: 'y 90deg' }]);
111+
});
112+
113+
it('handles positive and negative angle values', () => {
114+
const atomPositive = rotateAtom({
115+
direction: 'enter',
116+
duration: 300,
117+
angle: 90,
118+
});
119+
120+
const atomNegative = rotateAtom({
121+
direction: 'enter',
122+
duration: 300,
123+
angle: -45,
124+
});
125+
126+
expect(atomPositive.keyframes[0]).toEqual({ rotate: 'y 90deg' });
127+
expect(atomNegative.keyframes[0]).toEqual({ rotate: 'y -45deg' });
128+
});
129+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { expectPresenceMotionFunction, expectPresenceMotionArray } from '../../testing/testUtils';
2+
import { Rotate } from './Rotate';
3+
4+
describe('Rotate', () => {
5+
it('stores its motion definition as a static function', () => {
6+
expectPresenceMotionFunction(Rotate);
7+
});
8+
9+
it('generates a motion definition from the static function', () => {
10+
expectPresenceMotionArray(Rotate);
11+
});
12+
});

0 commit comments

Comments
 (0)