-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathmarkdoc.test.tsx
More file actions
164 lines (129 loc) · 4.84 KB
/
markdoc.test.tsx
File metadata and controls
164 lines (129 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import React from 'react';
import { render, screen } from '@testing-library/react';
import Markdown from '@/components/markdown/markdown';
// Mock the signal button to avoid needing full workflow context
jest.mock(
'@/components/markdown/markdoc-components/signal-button/signal-button',
() => {
return function MockSignalButton({ label }: { label: string }) {
return <button data-testid="signal-button">{label}</button>;
};
}
);
describe('Markdown with Markdoc', () => {
it('renders basic markdown', () => {
const content = '# Hello World\n\nThis is a test.';
render(<Markdown markdown={content} />);
expect(screen.getByText('Hello World')).toBeInTheDocument();
expect(screen.getByText('This is a test.')).toBeInTheDocument();
});
it('renders signal button tags', () => {
const content = `
# Test
{% signal signalName="test" label="Click Me" /%}
`;
render(<Markdown markdown={content} />);
expect(screen.getByText('Test')).toBeInTheDocument();
expect(screen.getByTestId('signal-button')).toBeInTheDocument();
expect(screen.getByText('Click Me')).toBeInTheDocument();
});
it('renders multiple signal buttons', () => {
const content = `
# Actions
{% signal signalName="approve" label="Approve" /%}
{% signal signalName="reject" label="Reject" /%}
`;
render(<Markdown markdown={content} />);
const buttons = screen.getAllByTestId('signal-button');
expect(buttons).toHaveLength(2);
expect(screen.getByText('Approve')).toBeInTheDocument();
expect(screen.getByText('Reject')).toBeInTheDocument();
});
it('renders markdown with mixed content', () => {
const content = `
# Approval Required
Please review the following:
- Item 1
- Item 2
- Item 3
{% signal signalName="approve" label="Approve All" /%}
`;
render(<Markdown markdown={content} />);
expect(screen.getByText('Approval Required')).toBeInTheDocument();
expect(
screen.getByText('Please review the following:')
).toBeInTheDocument();
expect(screen.getByText('Item 1')).toBeInTheDocument();
expect(screen.getByText('Approve All')).toBeInTheDocument();
});
it('renders code blocks', () => {
const content = `
# Code Example
\`\`\`javascript
console.log('Hello');
\`\`\`
`;
render(<Markdown markdown={content} />);
expect(screen.getByText('Code Example')).toBeInTheDocument();
expect(screen.getByText("console.log('Hello');")).toBeInTheDocument();
});
it('renders inline code', () => {
const content = 'Use the `signal` tag.';
render(<Markdown markdown={content} />);
expect(screen.getByText('signal')).toBeInTheDocument();
});
it('renders links', () => {
const content = '[Click here](https://example.com)';
render(<Markdown markdown={content} />);
const link = screen.getByText('Click here');
expect(link).toBeInTheDocument();
expect(link.tagName).toBe('A');
});
it('renders lists', () => {
const content = `
- First item
- Second item
- Third item
`;
render(<Markdown markdown={content} />);
expect(screen.getByText('First item')).toBeInTheDocument();
expect(screen.getByText('Second item')).toBeInTheDocument();
expect(screen.getByText('Third item')).toBeInTheDocument();
});
it('renders emphasis and strong', () => {
const content = '**Bold text** and *italic text*';
render(<Markdown markdown={content} />);
expect(screen.getByText('Bold text')).toBeInTheDocument();
expect(screen.getByText('italic text')).toBeInTheDocument();
});
it('renders style tag with color', () => {
const content = '{% style color="red" %}red text{% /style %}';
render(<Markdown markdown={content} />);
const styledEl = screen.getByText('red text');
expect(styledEl).toBeInTheDocument();
expect(styledEl).toHaveStyle({ color: 'red' });
});
it('renders style tag with background color', () => {
const content = '{% style bg="yellow" %}highlighted text{% /style %}';
render(<Markdown markdown={content} />);
const styledEl = screen.getByText('highlighted text');
expect(styledEl).toBeInTheDocument();
expect(styledEl).toHaveStyle({ backgroundColor: 'yellow' });
});
it('renders style tag with both color and background', () => {
const content =
'{% style color="white" bg="blue" %}styled text{% /style %}';
render(<Markdown markdown={content} />);
const styledEl = screen.getByText('styled text');
expect(styledEl).toBeInTheDocument();
expect(styledEl).toHaveStyle({ color: 'white', backgroundColor: 'blue' });
});
it('renders nested style tags', () => {
const content =
'{% style color="blue" %}outer {% style color="red" %}inner{% /style %}{% /style %}';
render(<Markdown markdown={content} />);
const innerEl = screen.getByText('inner');
expect(innerEl).toBeInTheDocument();
expect(innerEl).toHaveStyle({ color: 'red' });
});
});