Skip to content

Commit

Permalink
Add tests to ensure markdown is rendered correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
  • Loading branch information
TG1999 committed Mar 24, 2024
1 parent db671c5 commit 7aeb49a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 6 additions & 2 deletions __tests__/Unit/Components/Issues/TaskRequestForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ describe('TaskRequestForm Component', () => {
/Description:/i
) as HTMLTextAreaElement;
fireEvent.change(descriptionTextarea, {
target: { value: 'Test description' },
target: { value: '## Heading' },
});
expect(descriptionTextarea.value).toBe('Test description');
expect(descriptionTextarea.value).toBe('## Heading');
fireEvent.click(previewButton);
const headingElement = screen.getByRole('heading', { level: 2 });
expect(headingElement).toBeInTheDocument();
expect(headingElement).toHaveTextContent('Heading');
});

test('renders form with default values', () => {
Expand Down
9 changes: 3 additions & 6 deletions src/components/MarkDownEditor/MarkDownEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Markdown from 'markdown-to-jsx';
import PropTypes from 'prop-types';
import { ChangeEvent, useState } from 'react';
import Markdown from 'markdown-to-jsx';

interface MarkDownEditorProps {
onChange?: (e: ChangeEvent<HTMLTextAreaElement>) => void;
Expand All @@ -18,7 +18,6 @@ const MarkDownEditor: React.FC<MarkDownEditorProps> = ({
}) => {
const [markdown, setMarkdown] = useState('');
const [mode, setMode] = useState<'description' | 'preview'>('description');

const handleClick = () => {
if (mode == 'preview') {
setMode('description');
Expand Down Expand Up @@ -61,10 +60,8 @@ const MarkDownEditor: React.FC<MarkDownEditorProps> = ({
</div>
)}
{mode === 'preview' && (
<div>
<Markdown className={previewClassName ?? ''}>
{markdown}
</Markdown>
<div className={previewClassName ?? ''}>
<Markdown>{markdown}</Markdown>
</div>
)}
</div>
Expand Down

0 comments on commit 7aeb49a

Please sign in to comment.