feat(mongodb): improve document quick filters
This commit is contained in:
1 parent
c417e54698
commit
681da22c33
32 files changed
+1639
-116
No files matched your search
+26
-1
@@ -1,7 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "vitest";
|
||||
|
||||
import { buildDataGridCellDetail, buildDataGridColumnDetail, dataGridColumnDetailJson, dataGridColumnDetailTsv, buildDataGridRowDetail, dataGridRowDetailJson, dataGridRowDetailTsv, filterDataGridDetailFields, type DataGridCellDetail } from "../../apps/desktop/src/lib/dataGrid/dataGridDetail.ts";
|
||||
import { buildDataGridCellDetail, buildDataGridColumnDetail, dataGridColumnDetailJson, dataGridColumnDetailTsv, buildDataGridRowDetail, dataGridRowDetailJson, dataGridRowDetailTsv, filterDataGridDetailFields, jsonDetailDisplayValue, type DataGridCellDetail } from "../../apps/desktop/src/lib/dataGrid/dataGridDetail.ts";
|
||||
import type { CellValue } from "../../apps/desktop/src/lib/dataGrid/cellValue.ts";
|
||||
|
||||
test("buildDataGridCellDetail returns null for an invalid column", () => {
|
||||
@@ -202,9 +202,34 @@ test("dataGridRowDetailJson and dataGridRowDetailTsv format copy payloads", () =
|
||||
});
|
||||
|
||||
assert.equal(dataGridRowDetailJson(detail), '{\n "id": 1,\n "name": "Ada",\n "nickname": null\n}');
|
||||
assert.equal(dataGridRowDetailJson(detail, { id: 1, profile: { city: "Shanghai" } }), '{\n "id": 1,\n "profile": {\n "city": "Shanghai"\n }\n}');
|
||||
assert.equal(dataGridRowDetailTsv(detail), "1\tAda\tNULL");
|
||||
});
|
||||
|
||||
test("dataGridRowDetailJson uses the original MongoDB document for nested values", () => {
|
||||
const document = {
|
||||
_id: { $oid: "507f1f77bcf86cd799439011" },
|
||||
profile: { createdAt: { $date: "2025-01-02T03:04:05.000Z" }, labels: ["vip"] },
|
||||
};
|
||||
const detail = buildDataGridRowDetail({
|
||||
rowIndex: 0,
|
||||
rowId: 1,
|
||||
row: ['{"$oid":"507f1f77bcf86cd799439011"}', '{"createdAt":{"$date":"2025-01-02T03:04:05.000Z"},"labels":["vip"]}'],
|
||||
columns: ["_id", "profile"],
|
||||
columnIndexes: [0, 1],
|
||||
displayValue: (value) => String(value),
|
||||
});
|
||||
|
||||
assert.equal(dataGridRowDetailJson(detail, document), JSON.stringify(document, null, 2));
|
||||
assert.doesNotMatch(dataGridRowDetailJson(detail, document), /\\"\\$oid\\"/);
|
||||
});
|
||||
|
||||
test("jsonDetailDisplayValue expands JSON stored in MongoDB string fields", () => {
|
||||
assert.deepEqual(
|
||||
jsonDetailDisplayValue({ imparts: '{"insImpart":[{"impartId":"40-936","impartAnswer":"N,,"}]}' }),
|
||||
{ imparts: { insImpart: [{ impartId: "40-936", impartAnswer: "N,," }] } },
|
||||
);
|
||||
});
|
||||
test("buildDataGridColumnDetail maps a whole column across rows", () => {
|
||||
const typeByColumn = new Map([["name", "varchar"]]);
|
||||
const commentByColumn = new Map([["name", "display name"]]);
|
||||
|
||||
Reference in new issue
Block a user