2022-03-23 14:27:35 -07:00
|
|
|
import {
|
|
|
|
withOpacityValue,
|
|
|
|
parseColorMatrix,
|
2023-12-20 18:34:09 -08:00
|
|
|
} from './colors';
|
2022-03-23 14:27:35 -07:00
|
|
|
|
|
|
|
describe('withOpacityValue()', () => {
|
|
|
|
it('returns a Tailwind color function with alpha support', () => {
|
|
|
|
const result = withOpacityValue('--color-primary-500');
|
|
|
|
|
|
|
|
// It returns a function
|
|
|
|
expect(typeof result).toBe('function');
|
|
|
|
|
|
|
|
// Test calling the function
|
2023-12-20 18:34:09 -08:00
|
|
|
expect(result).toBe('rgb(var(--color-primary-500) / <alpha-value>)');
|
2022-03-23 14:27:35 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('parseColorMatrix()', () => {
|
|
|
|
it('returns a Tailwind color object', () => {
|
|
|
|
const colorMatrix = {
|
|
|
|
gray: [50, 100, 200, 300, 400, 500, 600, 700, 800, 900],
|
|
|
|
primary: [50, 100, 200, 300, 400, 500, 600, 700, 800, 900],
|
|
|
|
success: [50, 100, 200, 300, 400, 500, 600, 700, 800, 900],
|
|
|
|
danger: [50, 100, 200, 300, 400, 500, 600, 700, 800, 900],
|
|
|
|
accent: [300, 500],
|
|
|
|
};
|
|
|
|
|
|
|
|
const result = parseColorMatrix(colorMatrix);
|
|
|
|
|
|
|
|
// Colors are mapped to functions which return CSS values
|
2023-12-20 18:34:09 -08:00
|
|
|
// @ts-ignore
|
|
|
|
expect(result.accent['300']).toEqual('rgb(var(--color-accent-300) / <alpha-value>)');
|
2022-03-23 14:51:42 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('parses single-tint values', () => {
|
|
|
|
const colorMatrix = {
|
|
|
|
gray: [50, 100, 200, 300, 400, 500, 600, 700, 800, 900],
|
|
|
|
primary: [50, 100, 200, 300, 400, 500, 600, 700, 800, 900],
|
|
|
|
success: [50, 100, 200, 300, 400, 500, 600, 700, 800, 900],
|
|
|
|
danger: [50, 100, 200, 300, 400, 500, 600, 700, 800, 900],
|
|
|
|
accent: [300, 500],
|
2022-05-07 13:23:43 -07:00
|
|
|
'gradient-start': true,
|
|
|
|
'gradient-end': true,
|
2022-03-23 14:51:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const result = parseColorMatrix(colorMatrix);
|
|
|
|
|
2023-12-20 18:34:09 -08:00
|
|
|
expect(result['gradient-start']).toEqual('rgb(var(--color-gradient-start) / <alpha-value>)');
|
2022-03-23 14:27:35 -07:00
|
|
|
});
|
|
|
|
});
|