-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathmarkdown-table-generator.service.test.ts
More file actions
50 lines (46 loc) · 1.58 KB
/
Copy pathmarkdown-table-generator.service.test.ts
File metadata and controls
50 lines (46 loc) · 1.58 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
import { describe, expect, it } from 'vitest';
import { createMarkdownTable, escapeMarkdownTableCell, generateMarkdownTable } from './markdown-table-generator.service';
describe('markdown-table-generator service', () => {
describe('createMarkdownTable', () => {
it('creates a table with default headers and empty rows', () => {
expect(createMarkdownTable({ rows: 1, columns: 2 })).toEqual({
headers: ['Column 1', 'Column 2'],
alignments: ['left', 'left'],
rows: [['', '']],
});
});
});
describe('escapeMarkdownTableCell', () => {
it('escapes pipes and converts line breaks to br tags', () => {
expect(escapeMarkdownTableCell(' foo | bar\nbaz ')).toBe('foo \\| bar<br>baz');
});
});
describe('generateMarkdownTable', () => {
it('generates a markdown table with column alignment', () => {
expect(generateMarkdownTable({
headers: ['Name', 'Count', 'Notes'],
alignments: ['left', 'right', 'center'],
rows: [
['Alpha', '10', 'Ready'],
['Beta', '3', 'Needs review'],
],
})).toMatchInlineSnapshot(`
"| Name | Count | Notes |
| :--- | ---: | :---: |
| Alpha | 10 | Ready |
| Beta | 3 | Needs review |"
`);
});
it('pads uneven rows to keep the table shape valid', () => {
expect(generateMarkdownTable({
headers: ['Name'],
alignments: ['left'],
rows: [['Alpha', 'Extra']],
})).toMatchInlineSnapshot(`
"| Name | |
| :--- | :--- |
| Alpha | Extra |"
`);
});
});
});