mirror of
https://github.com/pooyash1998/chartspark.git
synced 2026-07-22 06:53:29 +00:00
32 lines
927 B
TypeScript
32 lines
927 B
TypeScript
import { getColors, withOpacity } from '../../src/utils/colors';
|
|
|
|
describe('getColors', () => {
|
|
it('returns the requested number of colors', () => {
|
|
expect(getColors(3)).toHaveLength(3);
|
|
expect(getColors(10)).toHaveLength(10);
|
|
});
|
|
|
|
it('wraps around palette for counts > palette size', () => {
|
|
const colors = getColors(12);
|
|
expect(colors).toHaveLength(12);
|
|
colors.forEach(c => expect(c).toMatch(/^#[0-9a-f]{6}$/i));
|
|
});
|
|
|
|
it('returns hex strings', () => {
|
|
getColors(5).forEach(c => expect(c).toMatch(/^#[0-9a-f]{6}$/i));
|
|
});
|
|
});
|
|
|
|
describe('withOpacity', () => {
|
|
it('converts hex to rgba with correct opacity', () => {
|
|
expect(withOpacity('#4c9be8', 0.5)).toMatch(/^rgba\(76, 155, 232, 0\.5\)$/);
|
|
});
|
|
|
|
it('handles opacity 1', () => {
|
|
expect(withOpacity('#ff0000', 1)).toBe('rgba(255, 0, 0, 1)');
|
|
});
|
|
|
|
it('handles opacity 0', () => {
|
|
expect(withOpacity('#000000', 0)).toBe('rgba(0, 0, 0, 0)');
|
|
});
|
|
});
|