Skip to content

Commit 33e550c

Browse files
authored
test(motion): expand motion atom testing (microsoft#35079)
1 parent a8a05e7 commit 33e550c

File tree

8 files changed

+670
-1
lines changed

8 files changed

+670
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "test(motion): expand motion atom testing",
4+
"packageName": "@fluentui/react-motion-components-preview",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-motion-components-preview/library/src/atoms/fade-atom.test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
import { fadeAtom } from './fade-atom';
2+
import {
3+
expectValidAtomMotion,
4+
expectReversedKeyframes,
5+
expectCustomParameters,
6+
expectKeyframeProperty,
7+
} from '../testing/atomTestUtils';
8+
9+
/**
10+
* Test utility for validating fade-specific atom properties.
11+
*/
12+
function expectFadeAtom(
13+
atom: import('@fluentui/react-motion').AtomMotion,
14+
direction: 'enter' | 'exit',
15+
fromOpacity: number = 0,
16+
toOpacity: number = 1,
17+
) {
18+
expectValidAtomMotion(atom);
19+
20+
if (direction === 'enter') {
21+
expectKeyframeProperty(atom, 'opacity', [fromOpacity, toOpacity]);
22+
} else {
23+
expectKeyframeProperty(atom, 'opacity', [toOpacity, fromOpacity]);
24+
}
25+
}
226

327
describe('fadeAtom', () => {
428
it('creates proper keyframes for enter and exit directions', () => {
@@ -59,4 +83,51 @@ describe('fadeAtom', () => {
5983
fill: 'both',
6084
});
6185
});
86+
87+
// Enhanced tests using test utilities
88+
it('creates valid atom motion objects for both directions', () => {
89+
const enterAtom = fadeAtom({ direction: 'enter', duration: 300 });
90+
const exitAtom = fadeAtom({ direction: 'exit', duration: 300 });
91+
92+
expectValidAtomMotion(enterAtom);
93+
expectValidAtomMotion(exitAtom);
94+
});
95+
96+
it('creates properly reversed keyframes for enter and exit', () => {
97+
const enterAtom = fadeAtom({ direction: 'enter', duration: 300 });
98+
const exitAtom = fadeAtom({ direction: 'exit', duration: 300 });
99+
100+
expectReversedKeyframes(enterAtom, exitAtom);
101+
});
102+
103+
it('validates fade-specific behavior with test utility', () => {
104+
const enterAtom = fadeAtom({ direction: 'enter', duration: 300 });
105+
const exitAtom = fadeAtom({ direction: 'exit', duration: 300 });
106+
107+
expectFadeAtom(enterAtom, 'enter');
108+
expectFadeAtom(exitAtom, 'exit');
109+
});
110+
111+
it('validates custom opacity values with test utility', () => {
112+
const enterAtom = fadeAtom({ direction: 'enter', duration: 300, fromOpacity: 0.3 });
113+
const exitAtom = fadeAtom({ direction: 'exit', duration: 300, fromOpacity: 0.3 });
114+
115+
expectFadeAtom(enterAtom, 'enter', 0.3, 1);
116+
expectFadeAtom(exitAtom, 'exit', 0.3, 1);
117+
});
118+
119+
it('validates custom timing parameters with test utility', () => {
120+
const atom = fadeAtom({
121+
direction: 'enter',
122+
duration: 500,
123+
delay: 200,
124+
easing: 'ease-in-out',
125+
});
126+
127+
expectCustomParameters(atom, {
128+
duration: 500,
129+
delay: 200,
130+
easing: 'ease-in-out',
131+
});
132+
});
62133
});
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
import { scaleAtom } from './scale-atom';
2+
import {
3+
expectValidAtomMotion,
4+
expectReversedKeyframes,
5+
expectCustomParameters,
6+
expectKeyframeProperty,
7+
} from '../testing/atomTestUtils';
8+
9+
/**
10+
* Test utility for validating scale-specific atom properties.
11+
*/
12+
function expectScaleAtom(
13+
atom: import('@fluentui/react-motion').AtomMotion,
14+
direction: 'enter' | 'exit',
15+
fromScale: number = 0.9,
16+
toScale: number = 1,
17+
) {
18+
expectValidAtomMotion(atom);
19+
20+
if (direction === 'enter') {
21+
expectKeyframeProperty(atom, 'scale', [fromScale, toScale]);
22+
} else {
23+
expectKeyframeProperty(atom, 'scale', [toScale, fromScale]);
24+
}
25+
}
26+
27+
describe('scaleAtom', () => {
28+
it('creates proper keyframes for enter and exit directions', () => {
29+
const enterAtom = scaleAtom({
30+
direction: 'enter',
31+
duration: 300,
32+
});
33+
34+
const exitAtom = scaleAtom({
35+
direction: 'exit',
36+
duration: 300,
37+
});
38+
39+
expect(enterAtom.keyframes).toEqual([{ scale: 0.9 }, { scale: 1 }]);
40+
expect(exitAtom.keyframes).toEqual([{ scale: 1 }, { scale: 0.9 }]);
41+
});
42+
43+
it('applies custom fromScale and toScale values', () => {
44+
const atom = scaleAtom({
45+
direction: 'enter',
46+
duration: 300,
47+
fromScale: 0.5,
48+
toScale: 1.2,
49+
});
50+
51+
expect(atom.keyframes).toEqual([{ scale: 0.5 }, { scale: 1.2 }]);
52+
});
53+
54+
it('uses default scale values when not provided', () => {
55+
const atom = scaleAtom({
56+
direction: 'enter',
57+
duration: 300,
58+
});
59+
60+
expect(atom.keyframes).toEqual([{ scale: 0.9 }, { scale: 1 }]);
61+
});
62+
63+
it('handles zero scale values correctly', () => {
64+
const atom = scaleAtom({
65+
direction: 'enter',
66+
duration: 300,
67+
fromScale: 0,
68+
toScale: 1,
69+
});
70+
71+
expect(atom.keyframes).toEqual([{ scale: 0 }, { scale: 1 }]);
72+
});
73+
74+
it('handles scale values greater than 1', () => {
75+
const atom = scaleAtom({
76+
direction: 'enter',
77+
duration: 300,
78+
fromScale: 1.5,
79+
toScale: 2.0,
80+
});
81+
82+
expect(atom.keyframes).toEqual([{ scale: 1.5 }, { scale: 2.0 }]);
83+
});
84+
85+
it('applies custom easing and delay', () => {
86+
const atom = scaleAtom({
87+
direction: 'enter',
88+
duration: 250,
89+
easing: 'ease-out',
90+
delay: 100,
91+
});
92+
93+
expect(atom).toMatchObject({
94+
duration: 250,
95+
easing: 'ease-out',
96+
delay: 100,
97+
});
98+
});
99+
100+
it('includes all expected properties in the returned atom', () => {
101+
const atom = scaleAtom({
102+
direction: 'exit',
103+
duration: 400,
104+
delay: 75,
105+
easing: 'ease-in-out',
106+
fromScale: 0.8,
107+
toScale: 1.1,
108+
});
109+
110+
expect(atom).toMatchObject({
111+
keyframes: [{ scale: 1.1 }, { scale: 0.8 }], // Note: reversed for exit
112+
duration: 400,
113+
easing: 'ease-in-out',
114+
delay: 75,
115+
});
116+
});
117+
118+
it('handles fractional scale values', () => {
119+
const atom = scaleAtom({
120+
direction: 'enter',
121+
duration: 300,
122+
fromScale: 0.95,
123+
toScale: 1.05,
124+
});
125+
126+
expect(atom.keyframes).toEqual([{ scale: 0.95 }, { scale: 1.05 }]);
127+
});
128+
129+
// Enhanced tests using test utilities
130+
it('creates valid atom motion objects for both directions', () => {
131+
const enterAtom = scaleAtom({ direction: 'enter', duration: 300 });
132+
const exitAtom = scaleAtom({ direction: 'exit', duration: 300 });
133+
134+
expectValidAtomMotion(enterAtom);
135+
expectValidAtomMotion(exitAtom);
136+
});
137+
138+
it('creates properly reversed keyframes for enter and exit', () => {
139+
const enterAtom = scaleAtom({ direction: 'enter', duration: 300 });
140+
const exitAtom = scaleAtom({ direction: 'exit', duration: 300 });
141+
142+
expectReversedKeyframes(enterAtom, exitAtom);
143+
});
144+
145+
it('validates scale-specific behavior with test utility', () => {
146+
const enterAtom = scaleAtom({ direction: 'enter', duration: 300 });
147+
const exitAtom = scaleAtom({ direction: 'exit', duration: 300 });
148+
149+
expectScaleAtom(enterAtom, 'enter');
150+
expectScaleAtom(exitAtom, 'exit');
151+
});
152+
153+
it('validates custom scale values with test utility', () => {
154+
const enterAtom = scaleAtom({
155+
direction: 'enter',
156+
duration: 300,
157+
fromScale: 0.5,
158+
toScale: 1.2,
159+
});
160+
const exitAtom = scaleAtom({
161+
direction: 'exit',
162+
duration: 300,
163+
fromScale: 0.5,
164+
toScale: 1.2,
165+
});
166+
167+
expectScaleAtom(enterAtom, 'enter', 0.5, 1.2);
168+
expectScaleAtom(exitAtom, 'exit', 0.5, 1.2);
169+
});
170+
171+
it('validates custom timing parameters with test utility', () => {
172+
const atom = scaleAtom({
173+
direction: 'enter',
174+
duration: 350,
175+
delay: 75,
176+
easing: 'ease-out',
177+
});
178+
179+
expectCustomParameters(atom, {
180+
duration: 350,
181+
delay: 75,
182+
easing: 'ease-out',
183+
});
184+
});
185+
});

0 commit comments

Comments
 (0)