Skip to content

Commit 217ffb9

Browse files
committed
test: improve test coverage for MarkdownContent
1 parent 90d1e38 commit 217ffb9

1 file changed

Lines changed: 61 additions & 1 deletion

File tree

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

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { act, fireEvent, render, screen } from '@testing-library/react';
22
import React from 'react';
33
import { Provider } from 'react-redux';
4-
import { BrowserRouter } from 'react-router-dom';
4+
import { BrowserRouter, MemoryRouter } from 'react-router-dom';
55
import configureStore from 'redux-mock-store';
66
import { thunk } from 'redux-thunk';
77
import MarkdownContent from '../../../../../src/components/Content/MarkdownContent/MarkdownContent';
@@ -359,4 +359,64 @@ describe('MarkdownContent', () => {
359359
await screen.findByText('Test Heading');
360360
expect(scrollIntoViewMock).toHaveBeenCalledWith({ behavior: 'smooth', block: 'start' });
361361
});
362+
363+
test('renders tag and category chips and fetches previous diff in diff-prev mode', async () => {
364+
const contentWithMetadata = [
365+
'---',
366+
'title: Release Notes',
367+
'tags:',
368+
' - alpha',
369+
' - beta',
370+
'categories:',
371+
' - docs',
372+
' - guides',
373+
'---',
374+
'# Markdown Content',
375+
].join('\n');
376+
377+
store = mockStore({
378+
content: {
379+
content: contentWithMetadata,
380+
loading: false,
381+
error: null,
382+
},
383+
diff: defaultDiffState,
384+
fileTree: {
385+
loading: false,
386+
isGitRepository: true,
387+
},
388+
history: {
389+
currentPath: '/path/to/test.md',
390+
isDirectory: false,
391+
},
392+
appSetting: {
393+
contentMode: 'compact',
394+
},
395+
config: {
396+
fontFamily: 'Roboto',
397+
fontFamilyMonospace: 'monospace',
398+
fontSize: 14,
399+
}
400+
});
401+
402+
await act(async () => {
403+
render(
404+
<Provider store={store}>
405+
<MemoryRouter initialEntries={['/?tab=diff-prev']}>
406+
<MarkdownContent scrollToId={null} />
407+
</MemoryRouter>
408+
</Provider>
409+
);
410+
});
411+
412+
expect(screen.getByRole('heading', { name: 'Release Notes' })).toBeInTheDocument();
413+
['alpha', 'beta', 'docs', 'guides'].forEach((value) => {
414+
expect(screen.getByText(value)).toBeInTheDocument();
415+
});
416+
expect(store.getActions()).toEqual([
417+
{ type: 'content/fetchContent', payload: '/path/to/test.md' },
418+
{ type: 'diff/fetchDiff', payload: '/path/to/test.md' },
419+
{ type: 'diff/fetchDiffPrev', payload: '/path/to/test.md' },
420+
]);
421+
});
362422
});

0 commit comments

Comments
 (0)