e2c076c71c
* feat(web): improve mobile task and kanban navigation * feat(web): refine mobile task navigation * fix(web): address mobile navigation review feedback * test(web): cover task title field modes * fix(web): keep mobile board navigator open across workflows * fix(web): address mobile workflow review feedback
129 lines
3.7 KiB
TypeScript
129 lines
3.7 KiB
TypeScript
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
import { autoSelectBranch, shouldShowTaskTitleField } from "./task-create-dialog-helpers";
|
|
const STORAGE_KEYS = { LAST_BRANCH: "kandev.dialog.lastBranch" } as const;
|
|
|
|
beforeEach(() => {
|
|
localStorage.clear();
|
|
});
|
|
|
|
describe("autoSelectBranch", () => {
|
|
const branches = [
|
|
{ name: "main", type: "local" as const },
|
|
{ name: "feature", type: "local" as const },
|
|
];
|
|
|
|
it("prefers a store-backed branch over a divergent localStorage branch", () => {
|
|
const setBranch = vi.fn();
|
|
localStorage.setItem(STORAGE_KEYS.LAST_BRANCH, JSON.stringify("feature"));
|
|
|
|
autoSelectBranch(branches, setBranch, { lastUsedBranch: "main" });
|
|
|
|
expect(setBranch).toHaveBeenCalledWith("main");
|
|
});
|
|
|
|
it("uses the backend last-used branch before settings finish loading", () => {
|
|
const setBranch = vi.fn();
|
|
|
|
autoSelectBranch(branches, setBranch, {
|
|
lastUsedBranch: "feature",
|
|
userSettingsLoaded: false,
|
|
});
|
|
|
|
expect(setBranch).toHaveBeenCalledWith("feature");
|
|
});
|
|
|
|
it("uses the backend last-used branch when browser storage is stale", () => {
|
|
const setBranch = vi.fn();
|
|
localStorage.setItem(STORAGE_KEYS.LAST_BRANCH, JSON.stringify("deleted"));
|
|
|
|
autoSelectBranch(branches, setBranch, {
|
|
lastUsedBranch: "feature",
|
|
userSettingsLoaded: true,
|
|
});
|
|
|
|
expect(setBranch).toHaveBeenCalledWith("feature");
|
|
});
|
|
|
|
it("defers preferred fallback while user settings are still loading", () => {
|
|
const setBranch = vi.fn();
|
|
|
|
autoSelectBranch(branches, setBranch, { userSettingsLoaded: false });
|
|
|
|
expect(setBranch).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("falls back to preferred branch after user settings have loaded without a valid last-used branch", () => {
|
|
const setBranch = vi.fn();
|
|
|
|
autoSelectBranch(branches, setBranch, { userSettingsLoaded: true });
|
|
|
|
expect(setBranch).toHaveBeenCalledWith("main");
|
|
});
|
|
|
|
it("ignores a stale localStorage branch after user settings have loaded", () => {
|
|
const setBranch = vi.fn();
|
|
localStorage.setItem(STORAGE_KEYS.LAST_BRANCH, JSON.stringify("feature"));
|
|
|
|
autoSelectBranch(branches, setBranch, { userSettingsLoaded: true });
|
|
|
|
expect(setBranch).toHaveBeenCalledWith("main");
|
|
});
|
|
|
|
it("matches remote branch display names for store-backed last-used branch", () => {
|
|
const setBranch = vi.fn();
|
|
|
|
autoSelectBranch([{ name: "feature", type: "remote" as const, remote: "origin" }], setBranch, {
|
|
lastUsedBranch: "origin/feature",
|
|
userSettingsLoaded: true,
|
|
});
|
|
|
|
expect(setBranch).toHaveBeenCalledWith("origin/feature");
|
|
});
|
|
|
|
it("does not pick a branch from an empty branch list", () => {
|
|
const setBranch = vi.fn();
|
|
|
|
autoSelectBranch([], setBranch, { lastUsedBranch: "main", userSettingsLoaded: true });
|
|
|
|
expect(setBranch).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe("shouldShowTaskTitleField", () => {
|
|
it.each([
|
|
{
|
|
name: "started edit",
|
|
isCreateMode: false,
|
|
isEditMode: true,
|
|
isTaskStarted: true,
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "new task",
|
|
isCreateMode: true,
|
|
isEditMode: false,
|
|
isTaskStarted: false,
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "create from running task",
|
|
isCreateMode: true,
|
|
isEditMode: false,
|
|
isTaskStarted: true,
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "session",
|
|
isCreateMode: false,
|
|
isEditMode: false,
|
|
isTaskStarted: false,
|
|
expected: false,
|
|
},
|
|
])(
|
|
"returns $expected for $name mode",
|
|
({ isCreateMode, isEditMode, isTaskStarted, expected }) => {
|
|
expect(shouldShowTaskTitleField(isCreateMode, isEditMode, isTaskStarted)).toBe(expected);
|
|
},
|
|
);
|
|
});
|