adding tests for the processColorArray mapping (#27344)
Summary: The following pull-requests adds test for the `processColorArray` function. This ensures that the mapping is respected even in the `processColor` file changes. It also ensures that the mapping follows the basic expected functionality ## Changelog [General] [Added] - Add test for the `processColorArray` to make sure it maps correctly Pull Request resolved: https://github.com/facebook/react-native/pull/27344 Test Plan: - Run `npm run test Libraries/StyleSheet/__tests__/processColorArray-test.js` to ensure tests pass - Run `npm run lint` to make sure there are no styling conflicts. <img width="454" alt="Screen Shot 2019-11-26 at 3 24 44 PM" src="https://user-images.githubusercontent.com/31664059/69680816-e8641780-1060-11ea-89ca-336c5534eb16.png"> Differential Revision: D18770069 Pulled By: hramos fbshipit-source-id: 1a8647931818360b9912dc6fb50c339a91b9d4ea
This commit is contained in:
Родитель
97dd8cedc5
Коммит
3c4b1d6c4f
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @emails oncall+react_native
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const {OS} = require('../../Utilities/Platform');
|
||||
const processColorArray = require('../processColorArray');
|
||||
|
||||
const platformSpecific =
|
||||
OS === 'android'
|
||||
? unsigned => unsigned | 0 //eslint-disable-line no-bitwise
|
||||
: x => x;
|
||||
|
||||
describe('processColorArray', () => {
|
||||
describe('predefined color name array', () => {
|
||||
it('should convert array of color name type', () => {
|
||||
const colorFromStringArray = processColorArray(['red', 'white', 'black']);
|
||||
const expectedIntArray = [0xffff0000, 0xffffffff, 0xff000000].map(
|
||||
platformSpecific,
|
||||
);
|
||||
expect(colorFromStringArray).toEqual(expectedIntArray);
|
||||
});
|
||||
|
||||
it('should convert array of color type rgb(x, y, z)', () => {
|
||||
const colorFromRGBArray = processColorArray([
|
||||
'rgb(10, 20, 30)',
|
||||
'rgb(30, 20, 10)',
|
||||
'rgb(50, 150, 250)',
|
||||
]);
|
||||
const expectedIntArray = [0xff0a141e, 0xff1e140a, 0xff3296fa].map(
|
||||
platformSpecific,
|
||||
);
|
||||
expect(colorFromRGBArray).toEqual(platformSpecific(expectedIntArray));
|
||||
});
|
||||
|
||||
it('should convert array of color type hsl(x, y%, z%)', () => {
|
||||
const colorFromHSLArray = processColorArray([
|
||||
'hsl(318, 69%, 55%)',
|
||||
'hsl(218, 59%, 33%)',
|
||||
'hsl(118, 49%, 22%)',
|
||||
]);
|
||||
const expectedIntArray = [0xffdb3dac, 0xff234786, 0xff1e541d].map(
|
||||
platformSpecific,
|
||||
);
|
||||
expect(colorFromHSLArray).toEqual(platformSpecific(expectedIntArray));
|
||||
});
|
||||
|
||||
it('should return null if no array', () => {
|
||||
const colorFromNoArray = processColorArray(null);
|
||||
expect(colorFromNoArray).toEqual(null);
|
||||
});
|
||||
});
|
||||
});
|
Загрузка…
Ссылка в новой задаче