1 parent
747e9900df
commit
056e46504e
3 files changed
+188
-9
No files matched your search
+46
-5
@@ -152,10 +152,24 @@ vi.mock("@/components/ui/searchable-select", async () => {
|
||||
SearchableSelect: defineComponent({
|
||||
name: "SearchableSelect",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
modelValue: { type: String, default: "" },
|
||||
options: { type: Array, default: () => [] },
|
||||
allowCustom: { type: Boolean, default: false },
|
||||
},
|
||||
emits: ["update:modelValue"],
|
||||
setup:
|
||||
(_props, { attrs }) =>
|
||||
(props, { attrs, emit }) =>
|
||||
() =>
|
||||
h("div", attrs),
|
||||
h("button", {
|
||||
...attrs,
|
||||
type: "button",
|
||||
"data-searchable-select": "true",
|
||||
"data-model-value": props.modelValue,
|
||||
"data-options": JSON.stringify(props.options),
|
||||
"data-allow-custom": String(props.allowCustom),
|
||||
onClick: () => emit("update:modelValue", "custom_domain"),
|
||||
}),
|
||||
}),
|
||||
};
|
||||
});
|
||||
@@ -240,19 +254,19 @@ function draft(isPrimaryKey = false) {
|
||||
};
|
||||
}
|
||||
|
||||
async function mountEditor(databaseType: "sqlserver" | "postgres" | "sqlite" | "oracle" | "dameng" | "duckdb" | "informix", isPrimaryKey = false) {
|
||||
async function mountEditor(databaseType: "sqlserver" | "postgres" | "sqlite" | "oracle" | "dameng" | "duckdb" | "informix", isPrimaryKey = false, options: { database?: string; dynamicTypes?: string[] } = {}) {
|
||||
mocks.connection.db_type = databaseType;
|
||||
mocks.connection.name = databaseType;
|
||||
mocks.connection.driver_label = databaseType;
|
||||
mocks.ensureConnected.mockResolvedValue(undefined);
|
||||
mocks.listDataTypes.mockResolvedValue([]);
|
||||
mocks.listDataTypes.mockResolvedValue(options.dynamicTypes ?? []);
|
||||
mocks.buildTableStructureChangeSql.mockResolvedValue({ statements: [], warnings: [] });
|
||||
|
||||
const root = document.createElement("div");
|
||||
document.body.append(root);
|
||||
const app = createApp(TableStructureEditor, {
|
||||
connectionId: mocks.connection.id,
|
||||
database: "test",
|
||||
database: options.database ?? "test",
|
||||
schema: "SYSDBA",
|
||||
tableName: "users",
|
||||
draft: draft(isPrimaryKey),
|
||||
@@ -394,6 +408,33 @@ describe("TableStructureEditor primary key editing", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("TableStructureEditor data type options", () => {
|
||||
it("keeps dynamic Dameng types first and deduplicates fallback types case-insensitively", async () => {
|
||||
const root = await mountEditor("dameng", false, {
|
||||
database: "dynamic-types-5275",
|
||||
dynamicTypes: ["VARCHAR", "CUSTOM_DM_TYPE", "NUMBER"],
|
||||
});
|
||||
const picker = root.querySelector<HTMLElement>('[data-searchable-select="true"]');
|
||||
if (!picker) throw new Error("Missing data type picker");
|
||||
|
||||
await vi.waitFor(() => expect(JSON.parse(picker.dataset.options ?? "[]").slice(0, 3)).toEqual(["VARCHAR", "CUSTOM_DM_TYPE", "NUMBER"]));
|
||||
const options = JSON.parse(picker.dataset.options ?? "[]") as string[];
|
||||
expect(options.filter((option) => option.toLowerCase() === "varchar")).toEqual(["VARCHAR"]);
|
||||
expect(options.filter((option) => option.toLowerCase() === "number")).toEqual(["NUMBER"]);
|
||||
expect(options).toContain("longvarchar");
|
||||
});
|
||||
|
||||
it("continues to accept manually entered Dameng data types", async () => {
|
||||
const root = await mountEditor("dameng", false, { database: "manual-type-5275" });
|
||||
const picker = root.querySelector<HTMLButtonElement>('[data-searchable-select="true"]');
|
||||
if (!picker) throw new Error("Missing data type picker");
|
||||
|
||||
expect(picker.dataset.allowCustom).toBe("true");
|
||||
picker.click();
|
||||
await vi.waitFor(() => expect(mocks.buildTableStructureChangeSql).toHaveBeenLastCalledWith(expect.objectContaining({ columns: [expect.objectContaining({ dataType: "custom_domain" })] })));
|
||||
});
|
||||
});
|
||||
|
||||
describe("TableStructureEditor local column order notice", () => {
|
||||
it.each(["sqlserver", "postgres", "sqlite", "oracle", "dameng", "duckdb", "informix"] as const)("does not show the reorder notice when adding a %s column", async (databaseType) => {
|
||||
const root = await mountEditor(databaseType);
|
||||
|
||||
Reference in new issue
Block a user