feat(editor): add ignore action to sql parameter dialog

This commit is contained in:
zipg authored and GitHub committed 2026-09-04 09:50:46 +08:00
1 parent 97f5a37ba8
commit d7941572b8
10 files changed
+58

No files matched your search

@@ -96,6 +96,11 @@ function clearParameterValues() {
values.value = next;
}
function ignoreParameters() {
open.value = false;
emit("execute", props.sql);
}
function updateValue(name: string, value: string) {
const matchedHistory = histories.value[name]?.find((entry) => entry.value === value);
values.value[name] = { ...(values.value[name] ?? { kind: "string" }), ...(matchedHistory ? { kind: matchedHistory.kind } : {}), value };
@@ -226,6 +231,9 @@ async function copyResolvedSql() {
</div>
<DialogFooter>
<Button type="button" variant="outline" data-testid="sql-parameters-ignore" @click="ignoreParameters">
{{ t("sqlParameters.ignore") }}
</Button>
<Button variant="outline" @click="open = false">{{ t("dangerDialog.cancel") }}</Button>
<Button variant="outline" @click="copyResolvedSql">
<Copy class="mr-1.5 h-4 w-4" />
@@ -86,6 +86,10 @@ function clearActionButton(): HTMLButtonElement | null {
return document.body.querySelector('[data-testid="sql-parameters-clear-values"]');
}
function ignoreActionButton(): HTMLButtonElement | null {
return document.body.querySelector('[data-testid="sql-parameters-ignore"]');
}
function clickRawAction() {
const button = actionButton();
expect(button).not.toBeNull();
@@ -98,6 +102,12 @@ function clickClearAction() {
button!.click();
}
function clickIgnoreAction() {
const button = ignoreActionButton();
expect(button).not.toBeNull();
button!.click();
}
function buttonWithText(text: string): HTMLButtonElement | undefined {
return Array.from(document.body.querySelectorAll("button")).find((button) => button.textContent?.trim() === text);
}
@@ -183,6 +193,38 @@ describe("SqlParameterDialog raw parameter action", () => {
});
});
describe("SqlParameterDialog ignore parameter action", () => {
it("closes the dialog and emits the original SQL without remembering or mutating values", async () => {
const { state, onExecute } = await mountDialog();
clickIgnoreAction();
await nextTick();
expect(state.open).toBe(false);
expect(onExecute).toHaveBeenCalledOnce();
expect(onExecute).toHaveBeenCalledWith(SQL);
expect(historyMocks.remember).not.toHaveBeenCalled();
expect(parameterInputs().map((input) => input.value)).toEqual(PARAMETERS.map((parameter) => MIXED_VALUES[parameter.key]?.value ?? ""));
});
it("does not apply current parameter edits when ignoring", async () => {
const { state, onExecute } = await mountDialog();
const firstInput = parameterInputs()[0];
expect(firstInput).not.toBeUndefined();
firstInput!.value = "changed";
firstInput!.dispatchEvent(new Event("input", { bubbles: true }));
await nextTick();
clickIgnoreAction();
await nextTick();
expect(state.open).toBe(false);
expect(onExecute).toHaveBeenCalledWith(SQL);
expect(historyMocks.remember).not.toHaveBeenCalled();
});
});
describe("SqlParameterDialog clear parameter values action", () => {
it("clears every displayed value while preserving kinds and updating the preview", async () => {
const { state, onExecute } = await mountDialog();