Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com
Open History to see the last commit

analytics-charts.test.tsx

29 lines1.0 KB

1import { renderToStaticMarkup } from "react-dom/server";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { ChartTable } from "./analytics-charts";
5import { folderChartRows } from "./analytics-data";
6​
7describe("ChartTable", () => {
8 it("is a real table of the chart's rows, with headers for columns and rows", () => {
9 const rows = folderChartRows(
10 [
11 { id: "work", name: "Work" },
12 { id: "travel", name: "Travel" },
13 ],
14 [{ folderId: "work", notes: 6, words: 1253 }],
15 );
16 const html = renderToStaticMarkup(
17 <ChartTable
18 columns={["Folder", "Words"]}
19 rows={rows.map((row) => ({ key: row.folderId, cells: [row.name, row.words] }))}
20 />,
21 );
22 expect(html).toContain("<table");
23 expect(html.match(/<th scope="col"/g)).toHaveLength(2);
24 expect(html).toContain('<th scope="row" class="py-1.5 text-left font-normal">Work</th>');
25 expect(html).toContain(">1,253</td>");
26 expect(html).toContain(">Travel</th>");
27 expect(html).toContain(">0</td>");
28 });
29});