2024-03-29 20:08:34 -04:00
|
|
|
//styles.test.tsx
|
2025-01-11 02:22:14 -05:00
|
|
|
import React from 'react';
|
2024-03-29 20:08:34 -04:00
|
|
|
import { render } from '@testing-library/react';
|
|
|
|
|
import '@testing-library/jest-dom';
|
|
|
|
|
|
|
|
|
|
import { ParagraphStyle } from '../../../../components/GiftTemplate/constants';
|
|
|
|
|
|
|
|
|
|
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) {
|
2025-01-11 02:22:14 -05:00
|
|
|
// 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;
|
|
|
|
|
}
|