Skip to content

Commit cbbba7b

Browse files
zeyapmeta-codesync[bot]
authored andcommitted
jest tests for PlatformColor support (#54458)
Summary: Pull Request resolved: #54458 ## Changelog: [General] [Added] jest tests for PlatformColor support Reviewed By: yungsters Differential Revision: D86547464 fbshipit-source-id: b89e8d30c20dd0a507b312cf1d813891e6ccb077
1 parent efd2f67 commit cbbba7b

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

packages/react-native/Libraries/Animated/__tests__/Interpolation-test.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
* @format
99
*/
1010

11-
import type {InterpolationConfigType} from '../nodes/AnimatedInterpolation';
11+
import type {
12+
InterpolationConfigSupportedOutputType,
13+
InterpolationConfigType,
14+
} from '../nodes/AnimatedInterpolation';
1215

16+
import {PlatformColor} from '../../../Libraries/StyleSheet/PlatformColorValueTypes';
1317
import Easing from '../Easing';
1418
import AnimatedInterpolation from '../nodes/AnimatedInterpolation';
1519

16-
function createInterpolation<T: number | string>(
20+
function createInterpolation<T: InterpolationConfigSupportedOutputType>(
1721
config: InterpolationConfigType<T>,
1822
): number => T {
1923
let parentValue = null;
@@ -360,6 +364,31 @@ describe('Interpolation', () => {
360364
expect(interpolation(2 / 3)).toBe('rgba(0, 0, 0, 0.667)');
361365
});
362366

367+
it('should work with PlatformColor', () => {
368+
jest.spyOn(console, 'warn').mockImplementationOnce(() => {});
369+
const interpolation = createInterpolation({
370+
inputRange: [0, 1],
371+
outputRange: [
372+
PlatformColor('@android:color/white'),
373+
PlatformColor('@android:color/darker_gray'),
374+
],
375+
});
376+
377+
// NativeColorValue is deferred to the native side to interpolate
378+
expect(interpolation(0)).toStrictEqual(
379+
PlatformColor('@android:color/white'),
380+
);
381+
expect(interpolation(2 / 3)).toStrictEqual(
382+
PlatformColor('@android:color/white'),
383+
);
384+
expect(console.warn).toBeCalledWith(
385+
'PlatformColor interpolation should happen natively, here we fallback to the closest color',
386+
);
387+
expect(interpolation(1)).toStrictEqual(
388+
PlatformColor('@android:color/darker_gray'),
389+
);
390+
});
391+
363392
it.each([
364393
['radians', ['1rad', '2rad'], [1, 2]],
365394
['degrees', ['90deg', '180deg'], [Math.PI / 2, Math.PI]],

0 commit comments

Comments
 (0)