feat(transfer): persist reusable transfer tasks

This commit is contained in:
lizzzzz777 authored and GitHub committed 2026-08-14 18:25:05 +08:00
1 parent 1a10db4c18
commit 05361eb40d
26 files changed
+2628 -241

No files matched your search

@@ -7,7 +7,7 @@ describe("DataTransferDialog layout", () => {
it("keeps the header and footer outside the shrinking content region", () => {
expect(dialogSource).toContain('<DialogHeader class="shrink-0">');
expect(dialogSource).toContain('<DialogFooter class="shrink-0">');
expect(dialogSource).toContain('class="min-h-0 flex-1 overflow-y-auto pr-1 scrollbar-thin"');
expect(dialogSource).toContain('class="min-h-0 flex-1 overflow-y-auto pl-4 pr-1 scrollbar-thin"');
});
it("allows layout scrolling on short viewports to prevent content clipping", () => {
@@ -43,7 +43,7 @@ describe("DataTransferDialog transfer prefill", () => {
it("loads non-table object groups per source database kind", () => {
expect(dialogSource).toContain("transferObjectKindsForDatabase");
expect(dialogSource).toContain("api.listObjects(sourceConnectionId.value, sourceDatabase.value, schema, [kind]");
expect(dialogSource).toContain("api.listObjects(connectionId, database, schema, [kind]");
expect(dialogSource).toContain("groups[kind] = objects.map((o) => o.name)");
});
@@ -51,15 +51,15 @@ describe("DataTransferDialog transfer prefill", () => {
expect(dialogSource).toContain("const kinds = transferObjectKindsForDatabase(config?.db_type)");
expect(dialogSource).toContain("for (const kind of kinds)");
expect(dialogSource).toContain('if (kind === "TABLE")');
expect(dialogSource).toContain("await api.listTables(sourceConnectionId.value, sourceDatabase.value, schema");
expect(dialogSource).toContain("await api.listTables(connectionId, database, schema");
});
it("keeps MongoDB collection loading ahead of the generic object-kind path", () => {
const mongoCollectionBranch = dialogSource.indexOf("if (isMongoConnection(sourceConnectionId.value))");
const mongoCollectionBranch = dialogSource.indexOf("if (isMongoConnection(connectionId))");
const genericObjectKinds = dialogSource.indexOf("const kinds = transferObjectKindsForDatabase(config?.db_type)");
expect(mongoCollectionBranch).toBeGreaterThan(-1);
expect(dialogSource).toContain("await api.mongoListCollections(sourceConnectionId.value, sourceDatabase.value)");
expect(dialogSource).toContain("await api.mongoListCollections(connectionId, database)");
expect(mongoCollectionBranch).toBeLessThan(genericObjectKinds);
});
@@ -79,4 +79,13 @@ describe("DataTransferDialog transfer prefill", () => {
expect(dialogSource).toContain("fetchCatalogNamespaceOptions(connectionId, catalog, config)");
expect(dialogSource).toContain("store.refreshObjectListTreeNode(request.targetConnectionId, request.targetDatabase, request.targetSchema, request.targetCatalog)");
});
it("discards stale async results after the connection changes", () => {
// 竞态防护:切换连接后旧请求的回调必须丢弃,不能覆盖新选择的下拉选项
expect(dialogSource).toContain("if (isStale()) return;");
expect(dialogSource).toContain("sourceConnectionId.value !== connectionId");
expect(dialogSource).toContain("targetConnectionId.value !== connectionId");
expect(dialogSource).toContain("if (sourceConnectionId.value !== id) return;");
expect(dialogSource).toContain("if (targetConnectionId.value !== id) return;");
});
});
@@ -0,0 +1,39 @@
import { describe, expect, it } from "vitest";
import { createTaskLoadTracker } from "@/components/transfer/taskLoadTracker";
function deferred() {
let resolve!: () => void;
const promise = new Promise<void>((resolvePromise) => {
resolve = resolvePromise;
});
return { promise, resolve };
}
describe("taskLoadTracker", () => {
it("keeps task B active when task A resolves after it", async () => {
const tracker = createTaskLoadTracker();
const taskAGate = deferred();
const taskBGate = deferred();
const applied: string[] = [];
let activeTaskId: string | null = "task-a";
const taskAToken = tracker.begin("task-a");
const taskALoad = (async () => {
await taskAGate.promise;
if (tracker.isCurrent(taskAToken, activeTaskId)) applied.push("task-a");
})();
activeTaskId = "task-b";
const taskBToken = tracker.begin("task-b");
const taskBLoad = (async () => {
await taskBGate.promise;
if (tracker.isCurrent(taskBToken, activeTaskId)) applied.push("task-b");
})();
taskBGate.resolve();
await taskBLoad;
taskAGate.resolve();
await taskALoad;
expect(applied).toEqual(["task-b"]);
});
});