Files
openidea/src/platform/workflowSettings.test.ts
T
faysouandfaysou 8557b8d21e feat(vcs): make default Commit inclusion configurable (#4864)
Settings > Version Control > Commit gets Include changes in the commit by default. It is on by default, which keeps the current behaviour (the active changelist's changes start checked). Turned off, the Commit view starts with every file unchecked, partially staged files included. Explicit selections still apply, and staging-area mode still follows the Git index.

Co-authored-by: faysou <893862+faysou@users.noreply.github.com>

Co-authored-by: faysou <893862+faysou@users.noreply.github.com>
2026-11-21 03:32:16 +08:00

109 lines
4.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { splitCommandLine } from "./commandLine";
import { DEFAULT_WORKFLOW, validateWorkflow } from "./workflowSettings";
describe("validateWorkflow", () => {
it("defaults inline blame off and accepts only boolean values", () => {
expect(DEFAULT_WORKFLOW.vcs.git.inlineBlame).toBe(false);
expect(validateWorkflow({ vcs: { git: { inlineBlame: true } } }).vcs.git.inlineBlame).toBe(true);
expect(validateWorkflow({ vcs: { git: { inlineBlame: "true" } } }).vcs.git.inlineBlame).toBe(false);
});
it("keeps the inline blame label clickable unless switched off", () => {
const clickable = (inlineBlameClickable: unknown) =>
validateWorkflow({ vcs: { git: { inlineBlameClickable } } }).vcs.git.inlineBlameClickable;
expect(DEFAULT_WORKFLOW.vcs.git.inlineBlameClickable).toBe(true);
expect(clickable(false)).toBe(false);
expect(clickable("no")).toBe(true);
});
it("executes branch operations on all repositories unless switched off", () => {
const sync = (syncBranchOperations: unknown) =>
validateWorkflow({ vcs: { git: { syncBranchOperations } } }).vcs.git.syncBranchOperations;
expect(DEFAULT_WORKFLOW.vcs.git.syncBranchOperations).toBe(true);
expect(sync(false)).toBe(false);
expect(sync("off")).toBe(true);
});
it("includes commit changes by default unless explicitly switched off", () => {
const inclusion = (includeChangesByDefault: unknown) =>
validateWorkflow({ vcs: { commit: { includeChangesByDefault } } }).vcs.commit.includeChangesByDefault;
expect(inclusion(undefined)).toBe(true);
expect(inclusion(true)).toBe(true);
expect(inclusion(false)).toBe(false);
expect(inclusion("false")).toBe(true);
});
it("keeps the double-click choice unset until it is made", () => {
expect(DEFAULT_WORKFLOW.vcs.commit.doubleClickOpensDiff).toBeNull();
expect(validateWorkflow(undefined).vcs.commit.doubleClickOpensDiff).toBeNull();
const commit = (doubleClickOpensDiff: unknown) =>
validateWorkflow({ vcs: { commit: { doubleClickOpensDiff } } }).vcs.commit.doubleClickOpensDiff;
expect(commit(true)).toBe(true);
expect(commit(false)).toBe(false);
expect(commit("yes")).toBeNull();
});
it("defaults Build tool window open/focus and rejects unknown values", () => {
expect(DEFAULT_WORKFLOW.build).toEqual({ openToolWindow: "always", focusToolWindow: "never" });
expect(validateWorkflow({ build: { openToolWindow: "onError", focusToolWindow: "always" } }).build).toEqual({
openToolWindow: "onError",
focusToolWindow: "always",
});
expect(validateWorkflow({ build: { openToolWindow: "sometimes", focusToolWindow: 1 } }).build).toEqual(
DEFAULT_WORKFLOW.build,
);
});
it("falls back to defaults for missing or malformed values", () => {
expect(validateWorkflow(undefined)).toEqual(DEFAULT_WORKFLOW);
const v = validateWorkflow({
vcs: {
historyLimit: -5,
git: { updateMethod: "squash", incomingCheck: "never", incomingCheckInterval: 0, largeFileMb: 0 },
confirmation: { onPatchCreated: "always" },
issueNavigation: [{ pattern: "" }, { pattern: "#(\\d+)", link: "x/$1" }],
},
console: {
bufferKb: 1e12,
foldPatterns: ["a", 3, ""],
logColors: { enabled: false, error: "#ff0000", warn: 123 },
},
terminal: { cursorShape: "bar", env: { A: "1", B: 2 }, tabName: " " },
externalTools: [{ name: "Lint", id: "x" }, { name: "" }, { name: "Again", id: "x" }],
});
expect(v.vcs.historyLimit).toBe(10);
expect(v.vcs.git.updateMethod).toBe("merge");
expect(v.vcs.git.incomingCheck).toBe("never");
expect(v.vcs.git.incomingCheckInterval).toBe(1);
expect(v.vcs.git.largeFileMb).toBe(1);
expect(v.vcs.issueNavigation).toEqual([{ pattern: "#(\\d+)", link: "x/$1" }]);
expect(v.vcs.commit.nonModal).toBe(true);
expect(v.vcs.confirmation.onPatchCreated).toBe("ask");
expect(v.vcs.shelf.removeApplied).toBe(false);
expect(v.console.bufferKb).toBe(1_048_576);
expect(v.console.foldPatterns).toEqual(["a"]);
expect(v.console.logColors).toEqual({
enabled: false,
error: "#ff0000",
warn: "var(--ansi-yellow)",
info: "var(--ansi-green)",
debug: "var(--ansi-cyan)",
trace: "var(--ansi-magenta)",
});
expect(v.terminal).toMatchObject({ cursorShape: "bar", env: { A: "1" }, tabName: "Local" });
expect(v.externalTools.map((t) => [t.id, t.name])).toEqual([
["x", "Lint"],
["x_", "Again"],
]);
});
});
describe("splitCommandLine", () => {
it("honours quotes and escapes", () => {
expect(splitCommandLine(`/bin/zsh --login`)).toEqual(["/bin/zsh", "--login"]);
expect(splitCommandLine(`sh -c "echo 'a b'" x\\ y ''`)).toEqual(["sh", "-c", "echo 'a b'", "x y", ""]);
expect(splitCommandLine(" ")).toEqual([]);
});
});