EvalueTonSavoir/client/src/__tests__/components/GiftTemplate/constants/styles.test.tsx

37 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-03-29 20:08:34 -04:00
//styles.test.tsx
import React from 'react';
2024-03-29 20:08:34 -04:00
import { render } from '@testing-library/react';
import '@testing-library/jest-dom';
2025-01-16 12:37:07 -05:00
import { ParagraphStyle } from 'src/components/GiftTemplate/constants';
2024-03-29 20:08:34 -04:00
describe('ParagraphStyle', () => {
test('applies styles correctly', () => {
const theme = 'light';
const paragraphText = 'Test paragraph';
const styles = ParagraphStyle(theme);
const { container } = render(
<p style={convertStylesToObject(styles)}>{paragraphText}</p>
);
const paragraphElement = container.firstChild;
expect(paragraphElement).toHaveStyle(`color: rgb(0, 0, 0);`);
});
});
function convertStylesToObject(styles: string): React.CSSProperties {
const styleObject: React.CSSProperties = {};
styles.split(';').forEach((style) => {
const [property, value] = style.split(':');
if (property && value) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2024-03-29 20:08:34 -04:00
(styleObject as any)[property.trim()] = value.trim();
}
});
return styleObject;
}