soapbox/tailwind/colors.test.ts

51 wiersze
1.6 KiB
TypeScript

2022-03-23 21:27:35 +00:00
import {
withOpacityValue,
parseColorMatrix,
2023-12-21 02:34:09 +00:00
} from './colors';
2022-03-23 21:27:35 +00: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-21 02:34:09 +00:00
expect(result).toBe('rgb(var(--color-primary-500) / <alpha-value>)');
2022-03-23 21:27:35 +00: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-21 02:34:09 +00:00
// @ts-ignore
expect(result.accent['300']).toEqual('rgb(var(--color-accent-300) / <alpha-value>)');
});
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],
'gradient-start': true,
'gradient-end': true,
};
const result = parseColorMatrix(colorMatrix);
2023-12-21 02:34:09 +00:00
expect(result['gradient-start']).toEqual('rgb(var(--color-gradient-start) / <alpha-value>)');
2022-03-23 21:27:35 +00:00
});
});