test(editor): cover context menu routing payloads

This commit is contained in:
LRcoding authored and GitHub committed 2026-07-15 20:53:22 +08:00
1 parent d3118256a4
commit 711d0ec57b
13 files changed
+484 -197

No files matched your search

+28 -2
View File
@@ -1,5 +1,17 @@
import { describe, expect, it } from "vitest";
import { extractIdentifierAt, extractIdentifierDetailsAt, isSqlKeyword, matchTable, splitQualifiedIdentifier, sqlObjectHoverDetail, sqlObjectNavigationTableType, sqlObjectNavigationTarget } from "@/lib/sql/sqlNavigation";
import {
extractIdentifierAt,
extractIdentifierDetailsAt,
isSqlKeyword,
matchTable,
mergeSqlObjectNavigationType,
splitQualifiedIdentifier,
sqlObjectHoverDetail,
sqlObjectNavigationSourceKind,
sqlObjectNavigationTableType,
sqlObjectNavigationTarget,
sqlObjectNavigationTypeFromTableType,
} from "@/lib/sql/sqlNavigation";
describe("extractIdentifierAt", () => {
it("extracts unquoted qualified identifiers", () => {
@@ -77,8 +89,9 @@ describe("matchTable", () => {
describe("SQL object navigation metadata", () => {
it("preserves view type and schema for command-click navigation", () => {
expect(sqlObjectNavigationTarget({ name: "active_users", schema: "dbo", type: "view" })).toEqual({
expect(sqlObjectNavigationTarget({ name: "active_users", database: "app", schema: "dbo", type: "view" })).toEqual({
name: "active_users",
database: "app",
schema: "dbo",
type: "view",
});
@@ -86,11 +99,24 @@ describe("SQL object navigation metadata", () => {
it("uses the object type in hover details", () => {
expect(sqlObjectHoverDetail({ name: "active_users", schema: "dbo", type: "view" })).toBe("view in dbo");
expect(sqlObjectHoverDetail({ name: "active_users_mv", schema: "dbo", type: "materialized_view" })).toBe("materialized view in dbo");
expect(sqlObjectHoverDetail({ name: "users", schema: "dbo", type: "table" })).toBe("table in dbo");
});
it("maps navigation types to table metadata types", () => {
expect(sqlObjectNavigationTableType({ name: "active_users", type: "view" })).toBe("VIEW");
expect(sqlObjectNavigationTableType({ name: "active_users_mv", type: "materialized_view" })).toBe("MATERIALIZED_VIEW");
expect(sqlObjectNavigationTableType({ name: "users", type: "table" })).toBe("TABLE");
expect(sqlObjectNavigationSourceKind({ name: "active_users", type: "view" })).toBe("VIEW");
expect(sqlObjectNavigationSourceKind({ name: "active_users_mv", type: "materialized_view" })).toBe("MATERIALIZED_VIEW");
expect(sqlObjectNavigationSourceKind({ name: "users", type: "table" })).toBeUndefined();
});
it("normalizes relation metadata without collapsing materialized views", () => {
expect(sqlObjectNavigationTypeFromTableType("BASE TABLE")).toBe("table");
expect(sqlObjectNavigationTypeFromTableType("VIEW")).toBe("view");
expect(sqlObjectNavigationTypeFromTableType("materialized view")).toBe("materialized_view");
expect(mergeSqlObjectNavigationType("view", "materialized_view")).toBe("materialized_view");
expect(mergeSqlObjectNavigationType("table", "view")).toBe("view");
});
});