Skip to content

Commit

Permalink
adding tests for the processColorArray mapping (#27344)
Browse files Browse the repository at this point in the history
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: #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
  • Loading branch information
talhaazhar authored and facebook-github-bot committed Dec 4, 2019
1 parent 97dd8ce commit 3c4b1d6
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Libraries/StyleSheet/__tests__/processColorArray-test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

0 comments on commit 3c4b1d6

Please sign in to comment.