ci / api / api (push) Successful in 19m12s
ci / ts / ts (packages + web) (push) Successful in 2m44s
ci / module boundaries / boundaries (push) Successful in 18m23s
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 59s
ci / db / db (push) Failing after 18s
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 1m18s
34 lines
1.8 KiB
TypeScript
34 lines
1.8 KiB
TypeScript
import { createI18n } from '@pipu/i18n';
|
|
import { cleanup, render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { I18nextProvider } from 'react-i18next';
|
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
import { MessageText } from './ChatMusic';
|
|
|
|
afterEach(cleanup);
|
|
|
|
describe('message text', () => {
|
|
it('compacts a long URL while preserving its full destination when text is collapsed', async () => {
|
|
const i18n = await createI18n('ru');
|
|
const url = `https://example.com/music/${'long-path-'.repeat(90)}?share=abc`;
|
|
render(<I18nextProvider i18n={i18n}><MessageText text={`Послушай ${url}`} /></I18nextProvider>);
|
|
expect(screen.getByRole('link')).toHaveAttribute('href', url);
|
|
expect(screen.getByRole('link').textContent!.length).toBeLessThan(65);
|
|
const user = userEvent.setup();
|
|
await user.click(screen.getByRole('button', { name: 'Показать полностью' }));
|
|
expect(screen.getByRole('link')).toHaveAttribute('href', url);
|
|
expect(screen.getByRole('button', { name: 'Свернуть текст' })).toHaveAttribute('aria-expanded', 'true');
|
|
});
|
|
|
|
it('keeps encoded text and markup literal, with expansion for long messages', async () => {
|
|
const i18n = await createI18n('ru');
|
|
const text = `<script>alert(1)</script> ${'%D0%BC%20'.repeat(100)}`;
|
|
const { container } = render(<I18nextProvider i18n={i18n}><MessageText text={text} /></I18nextProvider>);
|
|
expect(container.querySelector('script')).toBeNull();
|
|
expect(container.textContent).toContain('%D0%BC%20');
|
|
expect(screen.queryByRole('link')).not.toBeInTheDocument();
|
|
await userEvent.setup().click(screen.getByRole('button', { name: 'Показать полностью' }));
|
|
expect(container.textContent).toContain(text);
|
|
});
|
|
});
|