import React from 'react'; import { render } from '@testing-library/react'; import Snippet from './Snippet'; const SnippetCode = ` import type { Medium } from 'types'; import { prismSyntaxLangs } from 'helpers/constants'; import { PrismAsyncLight as SyntaxHighlighter } from 'react-syntax-highlighter'; import { atomDark } from 'react-syntax-highlighter/dist/cjs/styles/prism'; import tsx from 'react-syntax-highlighter/dist/cjs/languages/prism/tsx'; import scss from 'react-syntax-highlighter/dist/cjs/languages/prism/scss'; import bash from 'react-syntax-highlighter/dist/cjs/languages/prism/bash'; import python from 'react-syntax-highlighter/dist/cjs/languages/prism/python'; import cpp from 'react-syntax-highlighter/dist/cjs/languages/prism/cpp'; interface Props { medium: Medium; preview?: boolean; } // These have to match prismSyntaxLangs SyntaxHighlighter.registerLanguage('tsx', tsx); SyntaxHighlighter.registerLanguage('scss', scss); SyntaxHighlighter.registerLanguage('bash', bash); SyntaxHighlighter.registerLanguage('python', python); SyntaxHighlighter.registerLanguage('cpp', cpp); const Snippet = ({ medium, preview = false }: Props) => { return ( medium.mimeType === l.mimeType, )?.lang ?? 'text' } > {medium.content?.length && medium.content.length > 200 && preview ? \`\${medium.content.slice(0, 200)}\n...\` : \`\${medium.content}\`} ); }; export default Snippet; `; it('renders SnippetUpload with js code', () => { const { container } = render( ); expect(container).toMatchSnapshot(); }); it('renders SnippetUpload with js code without line numbers', () => { const { container } = render( ); expect(container).toMatchSnapshot(); }); it('renders SnippetUpload with js code without copy button', () => { const { container } = render( ); expect(container).toMatchSnapshot(); }); it('renders SnippetUpload with react/tsx code', () => { const { container } = render( ); expect(container).toMatchSnapshot(); }); it('renders SnippetUpload with preview mode (clamping)', () => { const { container } = render( ); expect(container).toMatchSnapshot(); }); it('renders SnippetUpload with css code', () => { const { container } = render( ); expect(container).toMatchSnapshot(); }); it('renders SnippetUpload with html code', () => { const { container } = render( ciao

', }} /> ); expect(container).toMatchSnapshot(); }); it('renders SnippetUpload with text', () => { const { container } = render( ciao

', }} /> ); expect(container).toMatchSnapshot(); }); it('renders SnippetUpload with text as fallback', () => { const { container } = render( ciao

', }} /> ); expect(container).toMatchSnapshot(); });