colors-test.js — react Source File
Architecture documentation for colors-test.js, a javascript file in the react codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR d1cea286_4e76_1b6b_5e61_cfa304dcb3d3["colors-test.js"] e8b75ea1_4270_75d6_defb_16c2f1811aef["colors.js"] d1cea286_4e76_1b6b_5e61_cfa304dcb3d3 --> e8b75ea1_4270_75d6_defb_16c2f1811aef 90ccfbcc_a5d2_19f7_e6e6_57b8c9f13294["hslaColorToString"] d1cea286_4e76_1b6b_5e61_cfa304dcb3d3 --> 90ccfbcc_a5d2_19f7_e6e6_57b8c9f13294 9d0a0842_1d90_d4fe_53ab_4de526a1dc17["dimmedColor"] d1cea286_4e76_1b6b_5e61_cfa304dcb3d3 --> 9d0a0842_1d90_d4fe_53ab_4de526a1dc17 8dce7fa7_d4a5_40fd_6aca_a2ba5fa2692a["ColorGenerator"] d1cea286_4e76_1b6b_5e61_cfa304dcb3d3 --> 8dce7fa7_d4a5_40fd_6aca_a2ba5fa2692a style d1cea286_4e76_1b6b_5e61_cfa304dcb3d3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import {hslaColorToString, dimmedColor, ColorGenerator} from '../colors';
describe('hslaColorToString', () => {
it('should transform colors to strings', () => {
expect(hslaColorToString({h: 1, s: 2, l: 3, a: 4})).toEqual(
'hsl(1deg 2% 3% / 4)',
);
expect(hslaColorToString({h: 3.14, s: 6.28, l: 1.68, a: 100})).toEqual(
'hsl(3.14deg 6.28% 1.68% / 100)',
);
});
});
describe('dimmedColor', () => {
it('should dim luminosity using delta', () => {
expect(dimmedColor({h: 1, s: 2, l: 3, a: 4}, 3)).toEqual({
h: 1,
s: 2,
l: 0,
a: 4,
});
expect(dimmedColor({h: 1, s: 2, l: 3, a: 4}, -3)).toEqual({
h: 1,
s: 2,
l: 6,
a: 4,
});
});
});
describe('ColorGenerator', () => {
describe('colorForID', () => {
it('should generate a color for an ID', () => {
expect(new ColorGenerator().colorForID('123')).toMatchInlineSnapshot(`
{
"a": 1,
"h": 190,
"l": 80,
"s": 67,
}
`);
});
it('should generate colors deterministically given an ID', () => {
expect(new ColorGenerator().colorForID('id1')).toEqual(
new ColorGenerator().colorForID('id1'),
);
expect(new ColorGenerator().colorForID('id2')).toEqual(
new ColorGenerator().colorForID('id2'),
);
});
it('should generate different colors for different IDs', () => {
expect(new ColorGenerator().colorForID('id1')).not.toEqual(
new ColorGenerator().colorForID('id2'),
);
});
it('should return colors that have been set manually', () => {
const generator = new ColorGenerator();
const manualColor = {h: 1, s: 2, l: 3, a: 4};
generator.setColorForID('id with set color', manualColor);
expect(generator.colorForID('id with set color')).toEqual(manualColor);
expect(generator.colorForID('some other id')).not.toEqual(manualColor);
});
it('should generate colors from fixed color spaces', () => {
const generator = new ColorGenerator(1, 2, 3, 4);
expect(generator.colorForID('123')).toEqual({h: 1, s: 2, l: 3, a: 4});
expect(generator.colorForID('234')).toEqual({h: 1, s: 2, l: 3, a: 4});
});
it('should generate colors from range color spaces', () => {
const generator = new ColorGenerator(
{min: 0, max: 360, count: 2},
2,
3,
4,
);
expect(generator.colorForID('123')).toEqual({h: 0, s: 2, l: 3, a: 4});
expect(generator.colorForID('234')).toEqual({h: 360, s: 2, l: 3, a: 4});
});
});
});
Domain
Dependencies
Source
Frequently Asked Questions
What does colors-test.js do?
colors-test.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain.
What does colors-test.js depend on?
colors-test.js imports 4 module(s): ColorGenerator, colors.js, dimmedColor, hslaColorToString.
Where is colors-test.js in the architecture?
colors-test.js is located at packages/react-devtools-timeline/src/content-views/utils/__tests__/colors-test.js (domain: BabelCompiler, directory: packages/react-devtools-timeline/src/content-views/utils/__tests__).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free