mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-04 17:48:50 +01:00
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
|
|
import { render } from '@testing-library/react';
|
||
|
|
import SplitText from './SplitText';
|
||
|
|
|
||
|
|
// Mock IntersectionObserver
|
||
|
|
class MockIntersectionObserver {
|
||
|
|
observe = jest.fn();
|
||
|
|
unobserve = jest.fn();
|
||
|
|
disconnect = jest.fn();
|
||
|
|
}
|
||
|
|
|
||
|
|
Object.defineProperty(window, 'IntersectionObserver', {
|
||
|
|
writable: true,
|
||
|
|
configurable: true,
|
||
|
|
value: MockIntersectionObserver,
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('SplitText', () => {
|
||
|
|
it('renders emojis correctly', () => {
|
||
|
|
const emojis = ['🚧', '❤️🔥', '💜', '🦎', '❌', '✅', '⚠️'];
|
||
|
|
const originalText = emojis.join('');
|
||
|
|
|
||
|
|
const { container } = render(<SplitText text={originalText} />);
|
||
|
|
const textSpans = container.querySelectorAll('p > span > span.inline-block');
|
||
|
|
|
||
|
|
// Reconstruct the text by joining all span contents
|
||
|
|
const reconstructedText = Array.from(textSpans)
|
||
|
|
.map((span) => span.textContent)
|
||
|
|
.join('')
|
||
|
|
.trim();
|
||
|
|
// Compare the reconstructed text with the original
|
||
|
|
expect(reconstructedText).toBe(originalText);
|
||
|
|
|
||
|
|
// Check the first character specifically as the reconstructed text could hide issues
|
||
|
|
for (let i = 0; i < emojis.length; i++) {
|
||
|
|
expect(Array.from(textSpans)[i].textContent).toBe(emojis[i]);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|