Files
Cloud-Tour-to-Libo/admin-web/tests/overviewCategories.test.ts
T

132 lines
3.4 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
buildGenericGraphCategories,
resolveOverviewCategoryView,
type EntityCategory,
} from "../src/panels/plaza/overviewCategories.ts";
const legacyCategories: EntityCategory[] = [
{ key: "candidate:Place", label: "审核地点", total: 9, sub: [] },
];
test("generic projects use real FalkorDB label counts", () => {
const categories = buildGenericGraphCategories(
{
connected: true,
label_counts: [
{ label: "Place", count: 2 },
{ label: "Hotel", count: 1 },
],
},
{ Place: "地点", Hotel: "酒店" },
);
assert.deepEqual(categories, [
{ key: "label:Place", label: "地点", total: 2, sub: [] },
{ key: "label:Hotel", label: "酒店", total: 1, sub: [] },
]);
});
test("invalid graph rows are ignored and duplicate labels are aggregated", () => {
const categories = buildGenericGraphCategories({
connected: true,
label_counts: [
{ label: "Place", count: 1 },
{ label: "Place", count: 2 },
{ label: "", count: 5 },
{ label: "Hotel", count: 0 },
{ label: "(no label)", count: 3 },
],
});
assert.deepEqual(categories, [
{ key: "label:Place", label: "Place", total: 3, sub: [] },
]);
});
test("disconnected graph does not present stale graph categories", () => {
assert.deepEqual(
buildGenericGraphCategories({
connected: false,
label_counts: [{ label: "Place", count: 2 }],
}),
[],
);
});
test("generic empty graphs never fall back to PostgreSQL candidate categories", () => {
assert.deepEqual(resolveOverviewCategoryView({
graph: { connected: true, label_counts: [] },
graphCategories: [],
legacyCategories,
allowLegacyFallback: false,
loading: false,
}), {
categories: [],
source: "graph",
status: "empty",
});
});
test("generic disconnected graphs never fall back to PostgreSQL candidate categories", () => {
assert.deepEqual(resolveOverviewCategoryView({
graph: { connected: false, error: "offline" },
graphCategories: [],
legacyCategories,
allowLegacyFallback: false,
loading: false,
}), {
categories: [],
source: "graph",
status: "disconnected",
});
});
test("generic loading state never flashes PostgreSQL candidate categories", () => {
assert.deepEqual(resolveOverviewCategoryView({
graph: { connected: true },
graphCategories: [],
legacyCategories,
allowLegacyFallback: false,
loading: true,
}), {
categories: [],
source: "graph",
status: "loading",
});
});
test("city and Libo knowledge maps retain the explicit legacy fallback", () => {
assert.deepEqual(resolveOverviewCategoryView({
graph: { connected: false, error: "offline" },
graphCategories: [],
legacyCategories,
allowLegacyFallback: true,
loading: false,
}), {
categories: legacyCategories,
source: "legacy-candidates",
status: "ready",
});
});
test("real FalkorDB categories win over the legacy fallback", () => {
const graphCategories: EntityCategory[] = [
{ key: "label:Place", label: "地点", total: 2, sub: [] },
];
assert.deepEqual(resolveOverviewCategoryView({
graph: { connected: true },
graphCategories,
legacyCategories,
allowLegacyFallback: true,
loading: false,
}), {
categories: graphCategories,
source: "graph",
status: "ready",
});
});