forked from deephaven/web-client-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIrisGridTestUtils.ts
More file actions
156 lines (135 loc) · 4.38 KB
/
IrisGridTestUtils.ts
File metadata and controls
156 lines (135 loc) · 4.38 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { type GridRangeIndex, type ModelSizeMap } from '@deephaven/grid';
import type { dh as DhType } from '@deephaven/jsapi-types';
import { Formatter, type SortDescriptor } from '@deephaven/jsapi-utils';
import IrisGridProxyModel from './IrisGridProxyModel';
import IrisGridUtils from './IrisGridUtils';
class IrisGridTestUtils {
static DEFAULT_TYPE = 'java.lang.String';
static valueForCell(
rowIndex: GridRangeIndex,
columnIndex: GridRangeIndex,
formatValue?: boolean
): string {
let value = `${rowIndex},${columnIndex}`;
if (formatValue !== undefined && formatValue) {
value = `(${value})`;
}
return value;
}
private dh: typeof DhType;
private irisGridUtils: IrisGridUtils;
constructor(dh: typeof DhType) {
this.dh = dh;
this.irisGridUtils = new IrisGridUtils(dh);
}
makeColumn(
name?: string,
type: string = IrisGridTestUtils.DEFAULT_TYPE,
index = 0
): DhType.Column {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new (this.dh as any).Column({ index, name, type });
}
makeRollupTableConfig(): DhType.RollupConfig {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new (this.dh as any).RollupTableConfig();
}
makeColumns(count = 5, prefix = ''): DhType.Column[] {
const columns = [];
for (let i = 0; i < count; i += 1) {
columns.push(
this.makeColumn(`${prefix}${i}`, IrisGridTestUtils.DEFAULT_TYPE, i)
);
}
return columns;
}
static makeUserColumnWidths(count = 5): ModelSizeMap {
const userColumnWidths = new Map();
for (let i = 0; i < count; i += 1) {
userColumnWidths.set(i.toString(), 100);
}
return userColumnWidths;
}
makeRow(i: number): DhType.Row {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const row = new (this.dh as any).Row({ index: i, name: `${i}` });
row.get = jest.fn(column =>
IrisGridTestUtils.valueForCell(i, column.index)
);
return row;
}
makeFilter(): DhType.FilterCondition {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new (this.dh as any).FilterCondition();
}
makeSort(column: DhType.Column = this.makeColumn()): DhType.Sort {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new (this.dh as any).Sort({ column });
}
hydrateSort(
sortDescriptor: readonly SortDescriptor[],
columns: DhType.Column[]
): DhType.Sort[] {
return this.irisGridUtils.hydrateDhSort(columns, sortDescriptor);
}
makeTable({
columns = this.makeColumns(),
size = 1000000000,
sort = [],
layoutHints = {},
}: {
columns?: DhType.Column[];
size?: number;
sort?: readonly SortDescriptor[];
layoutHints?: Partial<DhType.LayoutHints>;
} = {}): DhType.Table {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const table = new (this.dh as any).Table({ columns, size, sort });
table.copy = jest.fn(() => Promise.resolve(table));
table.freeze = jest.fn(() => Promise.resolve(table));
table.layoutHints = layoutHints;
return table;
}
makeTreeTable(
columns = this.makeColumns(),
aggregatedColumns: DhType.Column[] = [],
groupedColumns: DhType.Column[] = [],
size = 1000000000,
sort = [],
layoutHints?: Partial<DhType.LayoutHints>
): DhType.TreeTable {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const table = new (this.dh as any).TreeTable({
columns,
aggregatedColumns,
groupedColumns,
size,
sort,
layoutHints,
});
table.copy = jest.fn(() => Promise.resolve(table));
return table;
}
makeInputTable(keyColumns: DhType.Column[] = []): DhType.InputTable {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new (this.dh as any).InputTable(keyColumns);
}
makeSubscription(table = this.makeTable()): DhType.TableViewportSubscription {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new (this.dh as any).TableViewportSubscription({ table });
}
makeModel(
table = this.makeTable(),
formatter: Formatter | null = null,
inputTable: DhType.InputTable | null = null
): IrisGridProxyModel {
const { dh } = this;
return new IrisGridProxyModel(
dh,
table,
formatter ?? new Formatter(dh),
inputTable
);
}
}
export default IrisGridTestUtils;