import { mockAppRoot } from '@rocket.chat/mock-providers'; import { render, screen } from '@testing-library/react'; import dompurify from 'dompurify'; import MarkdownText, { supportedURISchemes } from './MarkdownText'; import '@testing-library/jest-dom'; import { emoji } from '../lib/emoji/lib'; import { getMarkdownParserLimit } from '../lib/getMarkdownParserLimit'; jest.mock('../lib/getMarkdownParserLimit'); const getMarkdownParserLimitMock = jest.mocked(getMarkdownParserLimit); const MOCKED_BASE_URI = 'http://localhost/'; // Mock getBaseURI from @rocket.chat/ui-client to ensure consistent behavior in tests // This will affect the isExternal function imported above. jest.mock('@rocket.chat/ui-client', () => ({ ...jest.requireActual('@rocket.chat/ui-client'), // Import and retain default behavior for other exports getBaseURI: jest.fn(() => MOCKED_BASE_URI), // Mock getBaseURI for consistent test behavior })); // List of common URI schemes. This list was taken from https://en.wikipedia.org/wiki/List_of_URI_schemes const commonUriSchemes = [ 'file', 'ftp', 'http', 'https', 'mailto', 'tel', 'imap', 'irc', 'nntp', 'acap', 'icap', 'mtqp', 'wss', 'admin', 'app', 'freeplane', 'geo', 'javascript', 'jdbc', 'msteams', 'ms-access', 'ms-excel', 'ms-infopath', 'ms-powerpoint', 'ms-project', 'ms-publisher', 'ms-spd', 'ms-visio', 'ms-word', 'odbc', 'psns', 'rdar', 's3', 'shortcuts', 'slack', 'stratum', 'trueconf', 'viber', 'zoommtgzoomus', ]; const nonSupportedUriSchemes = commonUriSchemes.filter((scheme) => !supportedURISchemes.includes(scheme)); const testUris = [ 'example.com', 'example.com/path', 'example.com/path/to/resource', 'localhost/home', 'localhost/path/to/', 'localhost/path/to/resource', ]; const getTestCases = (schemes: string[], uris: string[]): { scheme: string; links: string[] }[] => { return schemes.map((scheme) => { return { scheme, links: uris.map((uri) => `${scheme}://${uri}`), }; }); }; const isExternal = (link: string): boolean => link.indexOf(MOCKED_BASE_URI) !== 0; const normalizeHtml = (html: any) => { return html.replace(/\s+/g, ' ').trim(); }; const markdownText = ` # Heading 1 **Paragraph text**: *Bold with one asterisk* **Bold with two asterisks** Lorem ipsum dolor sit amet, consectetur adipiscing elit. ## Heading 2 _Italic Text_: _Italic with one underscore_ __Italic with two underscores__ Lorem ipsum dolor sit amet, consectetur adipiscing elit. ### Heading 3 Lists, Links and elements **Unordered List** - List Item 1 - List Item 2 - List Item 3 - List Item 4 **Ordered List** 1. List Item 1 2. List Item 2 3. List Item 3 4. List Item 4 **Links:** [Rocket.Chat](rocket.chat) gabriel.engel@rocket.chat +55991999999 \`Inline code\` \`\`\`typescript const test = 'this is code' \`\`\` **Bold text within __Italics__** *Bold text with single asterik and underscore within _Italics_* __Italics within **Bold** text__ _Italics within *Bold* text with single underscore and asterik_ `; it('should render html elements as expected using default parser', async () => { const { container } = render(, { wrapper: mockAppRoot().build(), }); const normalizedHtml = normalizeHtml(container.innerHTML); expect(normalizedHtml).toContain('

Heading 1

'); expect(normalizedHtml).toContain( 'Paragraph text: Bold with one asterisk Bold with two asterisks Lorem ipsum dolor sit amet', ); expect(normalizedHtml).toContain('

Heading 2

'); expect(normalizedHtml).toContain( 'Italic Text: Italic with one underscore Italic with two underscores Lorem ipsum dolor sit amet', ); expect(normalizedHtml).toContain('

Heading 3

'); expect(normalizedHtml).toContain('