Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {render, screen} from 'sentry-test/reactTestingLibrary';

import {
NotificationBodyFormattingBlockType,
NotificationBodyRenderer,
NotificationBodyTextBlockType,
} from './notificationBodyRenderer';

describe('NotificationBodyRenderer', () => {
it('renders markdown sections as markdown', async () => {
const body = [
{
type: NotificationBodyFormattingBlockType.MARKDOWN,
blocks: [
{
type: NotificationBodyTextBlockType.PLAIN_TEXT,
text: '**@Jane Doe** take a look',
},
],
},
];

render(<NotificationBodyRenderer body={body} />);

expect(await screen.findByText('@Jane Doe')).toBeInTheDocument();
expect(screen.getByText('@Jane Doe').tagName).toBe('STRONG');
expect(screen.queryByText(/\*\*/)).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import {Fragment} from 'react';
import styled from '@emotion/styled';

import {MarkedText} from 'sentry/utils/marked/markedText';

// Match the Python types from notifications/platform/types.py
enum NotificationBodyFormattingBlockType {
export enum NotificationBodyFormattingBlockType {
PARAGRAPH = 'paragraph',
CODE_BLOCK = 'code_block',
MARKDOWN = 'markdown',
}

enum NotificationBodyTextBlockType {
export enum NotificationBodyTextBlockType {
PLAIN_TEXT = 'plain_text',
BOLD_TEXT = 'bold_text',
CODE = 'code',
Expand Down Expand Up @@ -70,6 +73,15 @@ function renderFormattingBlock(
</div>
);
}
if (block.type === NotificationBodyFormattingBlockType.MARKDOWN) {
return (
<MarkedText
key={index}
text={block.blocks.map(textBlock => textBlock.text).join('\n')}
style={{marginBottom: '8px'}}
/>
);
}
return null;
}

Expand Down
Loading