fix(export): use real file name and reveal for background table-export tasks
This commit is contained in:
4 files changed
+253
-6
No files matched your search
@@ -0,0 +1,82 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { createApp, defineComponent, h, nextTick, type App } from "vue";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import i18n from "@/i18n";
|
||||
|
||||
vi.mock("@/components/ui/dialog", async () => {
|
||||
const { defineComponent, h } = await import("vue");
|
||||
const passthrough = defineComponent({
|
||||
setup(_props, { slots }) {
|
||||
return () => h("div", slots.default?.());
|
||||
},
|
||||
});
|
||||
return { Dialog: passthrough, DialogContent: passthrough, DialogHeader: passthrough, DialogTitle: passthrough, DialogFooter: passthrough };
|
||||
});
|
||||
|
||||
vi.mock("@/components/ui/button", async () => {
|
||||
const { defineComponent, h } = await import("vue");
|
||||
return {
|
||||
Button: defineComponent({
|
||||
setup(_props, { slots }) {
|
||||
return () => h("button", slots.default?.());
|
||||
},
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
import ExportProgressDialog from "@/components/export/ExportProgressDialog.vue";
|
||||
|
||||
const mountedApps: App[] = [];
|
||||
|
||||
afterEach(() => {
|
||||
for (const app of mountedApps.splice(0)) app.unmount();
|
||||
document.body.innerHTML = "";
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
async function mountDialog(props: Record<string, unknown>) {
|
||||
const container = document.createElement("div");
|
||||
document.body.append(container);
|
||||
const app = createApp(
|
||||
defineComponent({
|
||||
setup() {
|
||||
return () => h(ExportProgressDialog, props);
|
||||
},
|
||||
}),
|
||||
);
|
||||
mountedApps.push(app);
|
||||
app.use(i18n);
|
||||
app.mount(container);
|
||||
await nextTick();
|
||||
}
|
||||
|
||||
const baseProps = {
|
||||
open: true,
|
||||
title: "Export Table Data",
|
||||
tableName: "Query Result",
|
||||
format: "sql",
|
||||
rowsExported: 10,
|
||||
totalRows: 10,
|
||||
status: "Done",
|
||||
errorMessage: null,
|
||||
};
|
||||
|
||||
describe("ExportProgressDialog display name", () => {
|
||||
it("shows the real saved file name instead of the synthetic table label", async () => {
|
||||
i18n.global.locale.value = "en";
|
||||
await mountDialog({ ...baseProps, filePath: "C:\\exports\\自定义.sql" });
|
||||
|
||||
expect(document.body.textContent).toContain("自定义.sql");
|
||||
expect(document.body.textContent).not.toContain("Query Result (.sql)");
|
||||
const titleHolder = [...document.body.querySelectorAll("[title]")].find((el) => el.getAttribute("title") === "C:\\exports\\自定义.sql");
|
||||
expect(titleHolder).toBeTruthy();
|
||||
});
|
||||
|
||||
it("falls back to the table label when no file path is available", async () => {
|
||||
i18n.global.locale.value = "en";
|
||||
await mountDialog({ ...baseProps, tableName: "audit_log", format: "csv", filePath: null });
|
||||
|
||||
expect(document.body.textContent).toContain("audit_log (.csv)");
|
||||
});
|
||||
});
|
||||
@@ -25,8 +25,17 @@ vi.mock("@/components/ui/button", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => true }));
|
||||
|
||||
vi.mock("@/lib/backend/api", async (importOriginal) => {
|
||||
const original = await importOriginal<typeof import("@/lib/backend/api")>();
|
||||
return { ...original, revealPathInFileManager: vi.fn() };
|
||||
});
|
||||
|
||||
import ExportProgressPopover from "@/components/export/ExportProgressPopover.vue";
|
||||
import { useExportTracker } from "@/composables/useExportTracker";
|
||||
import { useToast } from "@/composables/useToast";
|
||||
import * as api from "@/lib/backend/api";
|
||||
|
||||
const mountedApps: App[] = [];
|
||||
let now = 0;
|
||||
@@ -250,3 +259,111 @@ describe("ExportProgressPopover task duration", () => {
|
||||
expect(document.body.textContent).not.toContain("failure 100");
|
||||
});
|
||||
});
|
||||
|
||||
describe("ExportProgressPopover file name and reveal action", () => {
|
||||
it("shows the saved file name instead of the synthetic query-result label", async () => {
|
||||
const tracker = useExportTracker();
|
||||
tracker.addTask("Query Result", "sql", "C:\\exports\\自定义.sql");
|
||||
tracker.addTask("Query Result", "xlsx", "/home/dbx/downloads/report-final.xlsx");
|
||||
|
||||
await mountPopover();
|
||||
|
||||
expect(document.body.textContent).toContain("自定义.sql");
|
||||
expect(document.body.textContent).toContain("report-final.xlsx");
|
||||
expect(document.body.textContent).not.toContain("Query Result.sql");
|
||||
expect(document.body.textContent).not.toContain("Query Result.xlsx");
|
||||
});
|
||||
|
||||
it("falls back to the table label when the task has no file path", async () => {
|
||||
const tracker = useExportTracker();
|
||||
tracker.addTask("audit_log", "csv", "");
|
||||
|
||||
await mountPopover();
|
||||
|
||||
expect(document.body.textContent).toContain("audit_log.csv");
|
||||
});
|
||||
|
||||
it("reveals the containing folder for a finished export from the task row", async () => {
|
||||
const revealMock = vi.mocked(api.revealPathInFileManager);
|
||||
revealMock.mockReset();
|
||||
revealMock.mockResolvedValue(undefined);
|
||||
const tracker = useExportTracker();
|
||||
const task = tracker.addTask("Query Result", "sql", "C:\\exports\\自定义.sql");
|
||||
tracker.updateTableExportTask(task.exportId, {
|
||||
exportId: task.exportId,
|
||||
tableName: "Query Result",
|
||||
rowsExported: 10,
|
||||
totalRows: 10,
|
||||
status: "Done",
|
||||
errorMessage: undefined,
|
||||
});
|
||||
|
||||
await mountPopover();
|
||||
|
||||
const revealButton = document.body.querySelector<HTMLButtonElement>('button[title="Open containing folder"]');
|
||||
expect(revealButton).not.toBeNull();
|
||||
revealButton?.click();
|
||||
await nextTick();
|
||||
await vi.waitFor(() => expect(revealMock).toHaveBeenCalledWith("C:\\exports\\自定义.sql"));
|
||||
});
|
||||
|
||||
it("hides the reveal button for active tasks and tasks without a file path", async () => {
|
||||
const tracker = useExportTracker();
|
||||
tracker.addTask("running_export", "csv", "C:\\exports\\running.csv");
|
||||
const doneTask = tracker.addTask("finished_export", "csv", "");
|
||||
tracker.updateTableExportTask(doneTask.exportId, {
|
||||
exportId: doneTask.exportId,
|
||||
tableName: "finished_export",
|
||||
rowsExported: 1,
|
||||
totalRows: 1,
|
||||
status: "Done",
|
||||
errorMessage: undefined,
|
||||
});
|
||||
|
||||
await mountPopover();
|
||||
|
||||
expect(document.body.querySelector('button[title="Open containing folder"]')).toBeNull();
|
||||
});
|
||||
|
||||
it("hides the reveal button for sql-file tasks whose path is a joined list of input scripts", async () => {
|
||||
const tracker = useExportTracker();
|
||||
const task = tracker.addSqlFileTask("sql-batch", "a.sql (+1)", "C:\\scripts\\a.sql; C:\\scripts\\b.sql");
|
||||
tracker.updateSqlFileTask(task.exportId, {
|
||||
executionId: task.exportId,
|
||||
status: "done",
|
||||
statementIndex: 2,
|
||||
successCount: 2,
|
||||
failureCount: 0,
|
||||
affectedRows: 0,
|
||||
elapsedMs: 10,
|
||||
statementSummary: "",
|
||||
});
|
||||
|
||||
await mountPopover();
|
||||
|
||||
expect(document.body.querySelector('button[title="Open containing folder"]')).toBeNull();
|
||||
});
|
||||
|
||||
it("shows a toast when revealing the folder fails", async () => {
|
||||
const revealMock = vi.mocked(api.revealPathInFileManager);
|
||||
revealMock.mockReset();
|
||||
revealMock.mockRejectedValue(new Error("file does not exist: C:\\exports\\gone.sql"));
|
||||
const tracker = useExportTracker();
|
||||
const task = tracker.addTask("Query Result", "sql", "C:\\exports\\gone.sql");
|
||||
tracker.updateTableExportTask(task.exportId, {
|
||||
exportId: task.exportId,
|
||||
tableName: "Query Result",
|
||||
rowsExported: 10,
|
||||
totalRows: 10,
|
||||
status: "Done",
|
||||
errorMessage: undefined,
|
||||
});
|
||||
|
||||
await mountPopover();
|
||||
|
||||
document.body.querySelector<HTMLButtonElement>('button[title="Open containing folder"]')?.click();
|
||||
await vi.waitFor(() => {
|
||||
expect(useToast().message.value).toContain("Failed to open folder");
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user