-
Notifications
You must be signed in to change notification settings - Fork 1
/
VMD.tsx
197 lines (193 loc) · 6 KB
/
VMD.tsx
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import { vi } from "vitest";
import { DataAccessorMock, Row } from "./DataAccessor";
import { FunctionAccessorMock } from "./FunctionAccessor.tsx";
import VMD, { Table, Schema, Column, TableDisplayType, View } from "../VMD";
export default {
...VMD,
getRowDataAccessor: vi.fn().mockImplementation(() => {
console.log("getRowDataAccessor in VMD mock was called.");
return new DataAccessorMock("/api/data");
}),
getRowsDataAccessor: vi.fn().mockImplementation((schema, table) => {
console.log("getRowsDataAccessor in VMD mock was called");
return new DataAccessorMock("/api/data");
}),
getRowsDataAccessorForOrder: vi.fn().mockImplementation(() => {
console.log("getRowsDataAccessorForOrder in VMD mock was called");
return new DataAccessorMock("/api/data");
}),
getUpdateRowDataAccessor: vi.fn().mockImplementation(() => {
console.log("getUpdateRowDataAccessor in VMD mock was called");
return new DataAccessorMock();
}),
getUpsertDataAccessor: vi.fn().mockImplementation(() => {
console.log("getUpsertDataAccessor in VMD mock was called");
return new DataAccessorMock();
}),
getSchema: vi.fn().mockImplementation(() => {
console.log("getSchema in VMD mock was called");
const mockSchema = new Schema("mock schema name");
mockSchema.tables = [
new TableMock("mock table name"),
new TableMock("mock table name 2"),
];
return mockSchema;
}),
getSchemas: vi.fn().mockImplementation(() => {
console.log("getSchemas in VMD mock was called");
return [
{ schema_name: "mock schema name" },
{ schema_name: "mock schema name 2" },
];
}),
getApplicationSchemas: vi.fn().mockImplementation(() => {
console.log("getSchemas in VMD mock was called");
return [
{ schema_name: "mock schema name" },
{ schema_name: "mock schema name 2" },
];
}),
getTable: vi.fn().mockImplementation(() => {
console.log("getTable in VMD mock was called");
return new TableMock("mock table name");
}),
getTables: vi.fn().mockImplementation(() => {
console.log("getTables in VMD mock was called");
return [
new TableMock("mock1"),
new TableMock("mock2"),
new TableMock("mock3"),
];
}),
getTableSchema: vi.fn().mockImplementation(() => {
console.log("getTableSchema in VMD mock was called");
return new Schema("mock schema name");
}),
getAllTables: vi.fn().mockImplementation(() => {
return [
new TableMock("mock1"),
new TableMock("mock2"),
new TableMock("mock3"),
];
}),
getFunctionAccessor: vi
.fn()
.mockImplementation((schema_name: string, function_name: string) => {
console.log("getFunctionAccessor in VMD mock was called");
return new FunctionAccessorMock(function_name);
}),
getViewRowDataAccessor: vi
.fn()
.mockImplementation(
(
schema_name: string,
view_name: string,
search_key: string[],
search_key_value: string[]
) => {
console.log("getViewRowDataAccessor in VMD mock was called.");
return new DataAccessorMock(view_name);
}
),
getViewRowsDataAccessor: vi
.fn()
.mockImplementation(
(
schema_name: string,
view_name: string,
search_key: string[],
search_key_value: string[]
) => {
console.log("getViewRowsDataAccessor in VMD mock was called");
return new DataAccessorMock(view_name);
}
),
getRemoveRowAccessor: vi.fn().mockImplementation(() => {
console.log("getRemoveRowAccessor in VMD mock was called");
return new DataAccessorMock();
}),
getAddRowDataAccessor: vi.fn().mockImplementation(() => {
console.log("getAddRowDataAccessor in VMD mock was called");
return new DataAccessorMock();
}),
getRowsDataAccessorForLookUpTable: vi.fn().mockImplementation(() => {
console.log("getRowsDataAccessorForLookUpTable in VMD mock was called");
return new DataAccessorMock();
}),
getUpsertRowDataAccessor: vi
.fn()
.mockImplementation(
(
schema_name: string,
table_name: string,
primary_keys: string[],
params: { [key: string]: string },
row: Row
) => {
console.log("getUpsertRowData in VMD mock was called");
return new DataAccessorMock(table_name);
}
),
refetchSchemas: vi.fn().mockImplementation(() => {
console.log("refetchSchemas in VMD mock was called.");
}),
TableDisplayType: TableDisplayType,
View: View,
};
export class TableMock extends Table {
constructor(name: string) {
super(name);
}
addColumn = vi
.fn()
.mockImplementation(
(
column: Column,
references_table: string,
is_editable: boolean,
references_by: string,
referenced_table: string,
referenced_by: string
) => {
console.log("addColumn in Table mock was called");
super.addColumn(
column,
references_table,
is_editable,
references_by,
referenced_table,
referenced_by
);
}
);
getColumns = vi.fn().mockImplementation(() => {
console.log("getColumns in Table mock was called");
return [
new ColumnMock("Column1"),
new ColumnMock("Column2"),
new ColumnMock("Column3"),
new ColumnMock("name"),
];
});
getEnumViewColumn = vi.fn().mockImplementation(() => {
console.log("getEnumViewColumn in Table mock was called");
return new ColumnMock("type");
});
setLookupTables = vi.fn().mockImplementation((lookupTables: string) => {
console.log("setLookupTables in Table mock was called");
super.setLookupTables(lookupTables);
});
}
export class ColumnMock extends Column {
constructor(name: string) {
super(name);
}
getVisibility = vi.fn().mockImplementation(() => {
console.log("getVisibility in Column mock was called");
return true;
});
setVisibility = vi.fn().mockImplementation(() => {
console.log("setVisibility in Column mock was called");
super.setVisibility(true);
});
}