Skip to content

Commit 6342f28

Browse files
committed
test: improve test coverage for MarkdownCode
1 parent 217ffb9 commit 6342f28

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

‎packages/frontend/test/unit/components/Content/MarkdownContent/MarkdownRenderer/MarkdownCode.test.tsx‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import { act, render } from '@testing-library/react';
1+
import { act, render, screen } from '@testing-library/react';
22
import React from 'react';
33
import { Provider } from 'react-redux';
44
import configureStore from 'redux-mock-store';
55
import MarkdownCode from '../../../../../../src/components/Content/MarkdownContent/MarkdownRenderer/MarkdownCode';
66

77
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);
815

916
describe('MarkdownCode', () => {
1017
let store: unknown;
@@ -47,4 +54,28 @@ describe('MarkdownCode', () => {
4754
});
4855
expect(asFragment()).toMatchSnapshot();
4956
});
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+
});
5081
});

0 commit comments

Comments
 (0)