|
1 | | -import { act, render } from '@testing-library/react'; |
| 1 | +import { act, render, screen } from '@testing-library/react'; |
2 | 2 | import React from 'react'; |
3 | 3 | import { Provider } from 'react-redux'; |
4 | 4 | import configureStore from 'redux-mock-store'; |
5 | 5 | import MarkdownCode from '../../../../../../src/components/Content/MarkdownContent/MarkdownRenderer/MarkdownCode'; |
6 | 6 |
|
7 | 7 | const mockStore = configureStore([]); |
| 8 | +const hashDiagram = (diagram: string): string => |
| 9 | + Math.abs( |
| 10 | + Array.from(diagram).reduce((hash, char) => { |
| 11 | + const nextHash = (hash << 5) - hash + char.charCodeAt(0); |
| 12 | + return nextHash & nextHash; |
| 13 | + }, 0), |
| 14 | + ).toString(36); |
8 | 15 |
|
9 | 16 | describe('MarkdownCode', () => { |
10 | 17 | let store: unknown; |
@@ -47,4 +54,28 @@ describe('MarkdownCode', () => { |
47 | 54 | }); |
48 | 55 | expect(asFragment()).toMatchSnapshot(); |
49 | 56 | }); |
| 57 | + |
| 58 | + it('should render PlantUML renderer for puml code blocks', () => { |
| 59 | + const chart = '@startuml\nA --> B\n@enduml'; |
| 60 | + const hash = hashDiagram(chart); |
| 61 | + store = mockStore({ |
| 62 | + config: { |
| 63 | + fontFamilyMonospace: 'monospace', |
| 64 | + syntaxHighlighterTheme: 'github', |
| 65 | + }, |
| 66 | + plantUML: { |
| 67 | + svgCache: {}, |
| 68 | + loading: { [hash]: true }, |
| 69 | + errors: { [hash]: null }, |
| 70 | + }, |
| 71 | + }); |
| 72 | + |
| 73 | + render( |
| 74 | + <Provider store={store}> |
| 75 | + <MarkdownCode className="language-puml">{chart}</MarkdownCode> |
| 76 | + </Provider> |
| 77 | + ); |
| 78 | + |
| 79 | + expect(screen.getByText('Loading PlantUML diagram...')).toBeInTheDocument(); |
| 80 | + }); |
50 | 81 | }); |
0 commit comments