mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-01 02:56:10 +00:00
This commit is contained in:
parent
c62afedebc
commit
3bc5b60c05
@ -103,7 +103,6 @@ export const customHTMLRenderer: CustomHTMLRenderer = {
|
||||
type: 'openTag',
|
||||
tagName: 'pre',
|
||||
classNames: preClasses,
|
||||
attributes: { 'data-content': codeText },
|
||||
},
|
||||
{
|
||||
type: 'html',
|
||||
@ -116,11 +115,9 @@ export const customHTMLRenderer: CustomHTMLRenderer = {
|
||||
data-testid="copied-message">
|
||||
{t('label.copied')}
|
||||
</span>
|
||||
<CopyIcon
|
||||
className="code-copy-button"
|
||||
data-copied="false"
|
||||
data-testid="code-block-copy-icon"
|
||||
/>
|
||||
<span data-testid="code-block-copy-icon">
|
||||
<CopyIcon className="code-copy-button" data-copied="false" />
|
||||
</span>
|
||||
</>
|
||||
),
|
||||
},
|
||||
|
||||
@ -29,6 +29,10 @@ const mockDescription =
|
||||
// eslint-disable-next-line max-len
|
||||
'**Headings**\n\n# H1\n## H2\n### H3\n\n***\n**Bold**\n\n**bold text**\n\n\n***\n**Italic**\n\n*italic*\n\n***\n**BlockQuote**\n\n> blockquote\n\n***\n**Ordered List**\n\n1. First item\n2. Second item\n3. Third item\n\n\n***\n**Unordered List**\n\n- First item\n- Second item\n- Third item\n\n\n***\n**Code**\n\n`code`\n\n\n***\n**Horizontal Rule**\n\n---\n\n\n***\n**Link**\n[title](https://www.example.com)\n\n\n***\n**Image**\n\n\n\n\n***\n**Table**\n\n| Syntax | Description |\n| ----------- | ----------- |\n| Header | Title |\n| Paragraph | Text |\n***\n\n**Fenced Code Block**\n\n```\n{\n "firstName": "John",\n "lastName": "Smith",\n "age": 25\n}\n```\n\n\n***\n**Strikethrough**\n~~The world is flat.~~\n';
|
||||
|
||||
const mockCodeBlockMarkdown =
|
||||
// eslint-disable-next-line max-len
|
||||
"```\nIFERROR ( \n IF (\n SUM ( 'Запасы'[СЗ, руб2] ) <> BLANK (),\n CALCULATE (\n DIVIDE ( SUM ( 'Запасы'[СЗ, руб2] ), [Количество дней в периоде_new] ),\n FILTER ( 'Место отгрузки', [Код предприятия] <> \"7001\" ),\n FILTER ( 'Запасы', [Код типа запаса] <> \"E\" )\n ),\n BLANK ()\n ),\n 0\n)\n```";
|
||||
|
||||
const mockProp: PreviewerProp = {
|
||||
markdown: mockDescription,
|
||||
className: '',
|
||||
@ -435,4 +439,22 @@ describe('Test RichTextEditor Previewer Component', () => {
|
||||
expect(screen.getByText(markdown)).toBeInTheDocument();
|
||||
expect(screen.queryByTestId('read-more-button')).toBeNull();
|
||||
});
|
||||
|
||||
it('Should render code block with copy button', async () => {
|
||||
const { container } = render(
|
||||
<RichTextEditorPreviewer
|
||||
{...mockProp}
|
||||
markdown={mockCodeBlockMarkdown}
|
||||
/>,
|
||||
{
|
||||
wrapper: MemoryRouter,
|
||||
}
|
||||
);
|
||||
|
||||
const markdownParser = await findByTestId(container, 'markdown-parser');
|
||||
|
||||
expect(markdownParser.querySelector('pre')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByTestId('code-block-copy-icon')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@ -71,8 +71,9 @@ const RichTextEditorPreviewer = ({
|
||||
const targetNodeDataTestId = targetNode.getAttribute('data-testid');
|
||||
|
||||
if (targetNodeDataTestId === 'code-block-copy-icon' && previousSibling) {
|
||||
const content =
|
||||
targetNode.parentElement?.getAttribute('data-content') ?? '';
|
||||
const codeNode = previousSibling.previousElementSibling;
|
||||
|
||||
const content = codeNode?.textContent ?? '';
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(content);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user