Skip to content

Commit f8effcc

Browse files
authored
fix: add unit test for table parsing (#1547)
1 parent 2ce63d0 commit f8effcc

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
[
2+
{
3+
"id": "1",
4+
"type": "table",
5+
"props": {
6+
"textColor": "default"
7+
},
8+
"content": {
9+
"type": "tableContent",
10+
"columnWidths": [
11+
null
12+
],
13+
"rows": [
14+
{
15+
"cells": [
16+
{
17+
"type": "tableCell",
18+
"content": [
19+
{
20+
"type": "text",
21+
"text": "Company",
22+
"styles": {
23+
"underline": true
24+
}
25+
}
26+
],
27+
"props": {
28+
"colspan": 1,
29+
"rowspan": 1,
30+
"backgroundColor": "default",
31+
"textColor": "default",
32+
"textAlignment": "left"
33+
}
34+
}
35+
]
36+
},
37+
{
38+
"cells": [
39+
{
40+
"type": "tableCell",
41+
"content": [
42+
{
43+
"type": "text",
44+
"text": "Example Company Inc.",
45+
"styles": {
46+
"bold": true
47+
}
48+
},
49+
{
50+
"type": "text",
51+
"text": "\n \nName: [Company Representative]\nTitle: Chief Executive Officer",
52+
"styles": {}
53+
}
54+
],
55+
"props": {
56+
"colspan": 1,
57+
"rowspan": 1,
58+
"backgroundColor": "default",
59+
"textColor": "default",
60+
"textAlignment": "left"
61+
}
62+
}
63+
]
64+
}
65+
]
66+
},
67+
"children": []
68+
},
69+
{
70+
"id": "2",
71+
"type": "table",
72+
"props": {
73+
"textColor": "default"
74+
},
75+
"content": {
76+
"type": "tableContent",
77+
"columnWidths": [
78+
null
79+
],
80+
"rows": [
81+
{
82+
"cells": [
83+
{
84+
"type": "tableCell",
85+
"content": [
86+
{
87+
"type": "text",
88+
"text": "Advisor",
89+
"styles": {
90+
"underline": true
91+
}
92+
}
93+
],
94+
"props": {
95+
"colspan": 1,
96+
"rowspan": 1,
97+
"backgroundColor": "default",
98+
"textColor": "default",
99+
"textAlignment": "left"
100+
}
101+
}
102+
]
103+
},
104+
{
105+
"cells": [
106+
{
107+
"type": "tableCell",
108+
"content": [
109+
{
110+
"type": "text",
111+
"text": "[Advisor Name]",
112+
"styles": {}
113+
}
114+
],
115+
"props": {
116+
"colspan": 1,
117+
"rowspan": 1,
118+
"backgroundColor": "default",
119+
"textColor": "default",
120+
"textAlignment": "left"
121+
}
122+
}
123+
]
124+
}
125+
]
126+
},
127+
"children": []
128+
}
129+
]

packages/core/src/api/parsers/html/parseHTML.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,41 @@ describe("Parse HTML", () => {
346346
await parseHTMLAndCompareSnapshots(html, "parse-div-with-inline-content");
347347
});
348348

349+
it("Parses 2 tables", async () => {
350+
const html = `
351+
<table style="border-collapse:collapse;margin-left:255.478pt" cellspacing="0">
352+
<tr style="height:22pt">
353+
<td style="width:203pt">
354+
<p data-text-alignment="left" data-text-indent="0pt"><u>Company</u></p>
355+
</td>
356+
</tr>
357+
<tr style="height:86pt">
358+
<td style="width:203pt">
359+
<p data-text-alignment="left" data-text-indent="0pt"><b>Example Company Inc.</b></p>
360+
<p data-text-alignment="left" data-text-indent="0pt">
361+
<p>Name: [Company Representative]</p>
362+
</p>
363+
<p data-text-alignment="left" data-text-indent="0pt">Title: Chief Executive Officer</p>
364+
</td>
365+
</tr>
366+
</table>
367+
368+
<table style="border-collapse:collapse;margin-left:256.5pt" cellspacing="0">
369+
<tr style="height:58pt">
370+
<td style="width:209pt;border-bottom-style:solid;border-bottom-width:2pt">
371+
<p data-text-alignment="left" data-text-indent="0pt"><u>Advisor</u></p>
372+
</td>
373+
</tr>
374+
<tr style="height:13pt">
375+
<td style="width:209pt;border-top-style:solid;border-top-width:2pt">
376+
<p data-text-alignment="left" data-text-indent="0pt">[Advisor Name]</p>
377+
</td>
378+
</tr>
379+
</table>`;
380+
381+
await parseHTMLAndCompareSnapshots(html, "parse-2-tables");
382+
});
383+
349384
it("Parse Notion HTML", async () => {
350385
// A few notes on Notion output HTML:
351386
// - Does not preserve text/background colors

0 commit comments

Comments
 (0)