|
1 | 1 | import { act, fireEvent, render, screen } from '@testing-library/react'; |
2 | 2 | import React from 'react'; |
3 | 3 | import { Provider } from 'react-redux'; |
4 | | -import { BrowserRouter } from 'react-router-dom'; |
| 4 | +import { BrowserRouter, MemoryRouter } from 'react-router-dom'; |
5 | 5 | import configureStore from 'redux-mock-store'; |
6 | 6 | import { thunk } from 'redux-thunk'; |
7 | 7 | import MarkdownContent from '../../../../../src/components/Content/MarkdownContent/MarkdownContent'; |
@@ -359,4 +359,64 @@ describe('MarkdownContent', () => { |
359 | 359 | await screen.findByText('Test Heading'); |
360 | 360 | expect(scrollIntoViewMock).toHaveBeenCalledWith({ behavior: 'smooth', block: 'start' }); |
361 | 361 | }); |
| 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 | + }); |
362 | 422 | }); |
0 commit comments