|
| 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