|
6 | 6 | // SPDX-License-Identifier: Apache-2.0 |
7 | 7 |
|
8 | 8 | import React from "react"; |
9 | | -import Table from "../components/ReactTable.js"; |
| 9 | +import Table from "../components/ReactTable"; |
10 | 10 | import { HashRouter as Router } from "react-router-dom"; |
11 | 11 |
|
12 | 12 | import { test_snapshot_of } from "./utils"; |
13 | 13 |
|
14 | | -// Add a serializer that removes title attributes (irrelevant in our table) |
15 | 14 | type SnapshotSerializer = Parameters<typeof expect.addSnapshotSerializer>[0]; |
16 | 15 |
|
17 | | -const hasTitleProp = ( |
18 | | - val: unknown, |
19 | | -): val is { props: Record<string, unknown> } => |
20 | | - typeof val === "object" && |
21 | | - val !== null && |
22 | | - "props" in val && |
23 | | - typeof (val as { props?: unknown }).props === "object" && |
24 | | - (val as { props?: Record<string, unknown> }).props !== null && |
25 | | - Object.prototype.hasOwnProperty.call( |
26 | | - (val as { props: Record<string, unknown> }).props, |
27 | | - "title", |
28 | | - ); |
29 | | - |
30 | 16 | // Add a serializer that removes title attributes (irrelevant in our table) |
31 | | -const removeTitleSerializer: SnapshotSerializer = { |
32 | | - test: hasTitleProp, |
33 | | - print: (val, print) => { |
| 17 | +expect.addSnapshotSerializer({ |
| 18 | + print: (val, serialize) => { |
34 | 19 | const v = val as { props?: { title?: unknown } }; |
35 | | - if (v.props) { |
36 | | - delete v.props.title; |
37 | | - } |
38 | | - return print(val); |
| 20 | + delete v.props?.title; |
| 21 | + return serialize(val); |
39 | 22 | }, |
40 | | -}; |
41 | | - |
42 | | -expect.addSnapshotSerializer(removeTitleSerializer); |
43 | | - |
44 | | -type TableProps = React.ComponentProps<typeof Table>; |
45 | | - |
46 | | -type OverviewShape = { |
47 | | - tableHeader: TableProps["tableHeader"]; |
48 | | - originalTable: TableProps["tableData"]; |
49 | | - tools: TableProps["tools"]; |
50 | | - toggleSelectColumns: TableProps["selectColumn"]; |
51 | | - prepareTableValues: TableProps["prepareTableValues"]; |
52 | | - setFilter: TableProps["setFilter"]; |
53 | | - filterPlotData: TableProps["filterPlotData"]; |
54 | | - filteredData: TableProps["filters"]; |
55 | | - toggleLinkOverlay: TableProps["toggleLinkOverlay"]; |
56 | | - changeTab: TableProps["changeTab"]; |
57 | | - statusValues: TableProps["statusValues"]; |
58 | | - categoryValues: TableProps["categoryValues"]; |
59 | | - hiddenCols: TableProps["hiddenCols"]; |
60 | | -}; |
61 | | - |
62 | | -test_snapshot_of("Render ReactTable", (overview: unknown) => { |
63 | | - const o = overview as unknown as OverviewShape; |
64 | | - |
| 23 | + test: (val) => |
| 24 | + !!val && |
| 25 | + typeof val === "object" && |
| 26 | + "props" in (val as object) && |
| 27 | + !!(val as { props?: unknown }).props && |
| 28 | + Object.prototype.hasOwnProperty.call( |
| 29 | + (val as { props: Record<string, unknown> }).props, |
| 30 | + "title", |
| 31 | + ), |
| 32 | +} as SnapshotSerializer); |
| 33 | + |
| 34 | +test_snapshot_of("Render ReactTable", (overview) => { |
65 | 35 | return ( |
66 | 36 | <Router> |
67 | 37 | <Table |
68 | | - tableHeader={o.tableHeader} |
69 | | - tableData={o.originalTable} |
70 | | - tools={o.tools} |
71 | | - selectColumn={o.toggleSelectColumns} |
72 | | - prepareTableValues={o.prepareTableValues} |
73 | | - setFilter={o.setFilter} |
74 | | - filterPlotData={o.filterPlotData} |
75 | | - filters={o.filteredData} |
76 | | - toggleLinkOverlay={o.toggleLinkOverlay} |
77 | | - changeTab={o.changeTab} |
78 | | - statusValues={o.statusValues} |
79 | | - categoryValues={o.categoryValues} |
80 | | - hiddenCols={o.hiddenCols} |
| 38 | + tableHeader={overview.tableHeader} |
| 39 | + tableData={overview.originalTable} |
| 40 | + tools={overview.tools} |
| 41 | + selectColumn={overview.toggleSelectColumns} |
| 42 | + prepareTableValues={overview.prepareTableValues} |
| 43 | + setFilter={overview.setFilter} |
| 44 | + filterPlotData={overview.filterPlotData} |
| 45 | + filters={overview.filteredData} |
| 46 | + toggleLinkOverlay={overview.toggleLinkOverlay} |
| 47 | + changeTab={overview.changeTab} |
| 48 | + statusValues={overview.statusValues} |
| 49 | + categoryValues={overview.categoryValues} |
| 50 | + hiddenCols={overview.hiddenCols} |
81 | 51 | /> |
82 | 52 | </Router> |
83 | 53 | ); |
|
0 commit comments