@homebound/beam 2.321.1 → 2.322.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,7 +29,7 @@ export declare function rowAnd(r: RenderResult, rowNum: number, testId: string):
29
29
  "
30
30
  `);
31
31
  * */
32
- export declare function tableSnapshot(r: RenderResult): string;
32
+ export declare function tableSnapshot(r: RenderResult, columnNames?: string[]): string;
33
33
  /** RTL wrapper for Beam's SuperDrawer/Modal context. */
34
34
  export declare const withBeamRTL: Wrapper;
35
35
  /**
package/dist/utils/rtl.js CHANGED
@@ -76,17 +76,30 @@ exports.rowAnd = rowAnd;
76
76
  "
77
77
  `);
78
78
  * */
79
- function tableSnapshot(r) {
79
+ function tableSnapshot(r, columnNames = []) {
80
80
  const tableEl = r.getByTestId("gridTable");
81
81
  const dataRows = Array.from(tableEl.querySelectorAll("[data-gridrow]"));
82
82
  const hasExpandableHeader = !!tableEl.querySelector(`[data-testid="expandableColumn"]`);
83
- const tableDataAsStrings = dataRows.map((row) => {
83
+ let tableDataAsStrings = dataRows.map((row) => {
84
84
  return Array.from(row.childNodes).map(getTextFromTableCellNode);
85
85
  });
86
- return toMarkupTableString({ tableRows: tableDataAsStrings, hasExpandableHeader });
86
+ // If the user wants a subset of columns, look for column names
87
+ if (columnNames.length > 0) {
88
+ const headerCells = tableDataAsStrings[0];
89
+ if (headerCells) {
90
+ const columnIndices = columnNames.map((name) => {
91
+ const i = headerCells.indexOf(name);
92
+ if (i === -1)
93
+ throw new Error(`Could not find header '${name}' in ${headerCells.join(", ")}`);
94
+ return i;
95
+ });
96
+ tableDataAsStrings = tableDataAsStrings.map((row) => columnIndices.map((index) => row[index]));
97
+ }
98
+ }
99
+ return toMarkupTableString(tableDataAsStrings, hasExpandableHeader);
87
100
  }
88
101
  exports.tableSnapshot = tableSnapshot;
89
- function toMarkupTableString({ tableRows, hasExpandableHeader, }) {
102
+ function toMarkupTableString(tableRows, hasExpandableHeader) {
90
103
  // Find the largest width of each column to set a consistent width for each row
91
104
  const columnWidths = tableRows.reduce((acc, row) => {
92
105
  row.forEach((cell, columnIndex) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.321.1",
3
+ "version": "2.322.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",