Files
paseo/packages/app/src/command-center/root-contributions.test.ts
T
Christoph LeiterandClaude Opus 5 07044136c8 feat(app): switch sidebar Group by from the command center (#3063)
Switching the sidebar between Project and Status grouping takes three
clicks today: open the display preferences menu, open Grouping, pick the
mode. It is the only sidebar preference with no fast path.

Typing "group" in the command center now offers a single entry that
switches to the mode you are not in, so it reads "Group by status" while
grouped by project and the reverse once you are in status mode. With
two modes a "cycle grouping" label would not say where you land, and an
entry that reads the same in both states looks like it does nothing.

The entry is query-only, so the default Cmd-K list is unchanged. It does
not clear the focus restore element, because it navigates nowhere and
focus has to return to whatever you were typing in.

The contribution is built by a pure function in root-contributions.ts so
its branches can be unit tested, mirroring workspace-contributions.ts.
The registration subscribes to groupMode with a narrow selector to avoid
re-registering every root action when host filters are reconciled.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 14:35:10 +00:00

77 lines
2.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { SidebarGroupMode } from "@/stores/sidebar-view-store";
import type { CommandCenterIconProps } from "./contributions";
import { buildGroupingContribution, type GroupingCommandCenterSource } from "./root-contributions";
function ProjectIcon(_props: CommandCenterIconProps) {
return null;
}
function StatusIcon(_props: CommandCenterIconProps) {
return null;
}
function source(groupMode: SidebarGroupMode): {
value: GroupingCommandCenterSource;
applied: SidebarGroupMode[];
} {
const applied: SidebarGroupMode[] = [];
return {
value: {
groupMode,
labels: {
section: "Actions",
groupByProject: "Group by project",
groupByStatus: "Group by status",
},
icons: { project: ProjectIcon, status: StatusIcon },
setGroupMode: (mode) => applied.push(mode),
},
applied,
};
}
describe("grouping command center contribution", () => {
it("offers status while grouped by project", () => {
const fixture = source("project");
const contribution = buildGroupingContribution(fixture.value);
expect(contribution.presentation).toMatchObject({
title: "Group by status",
icon: StatusIcon,
});
contribution.run();
expect(fixture.applied).toEqual(["status"]);
});
it("offers project while grouped by status", () => {
const fixture = source("status");
const contribution = buildGroupingContribution(fixture.value);
expect(contribution.presentation).toMatchObject({
title: "Group by project",
icon: ProjectIcon,
});
contribution.run();
expect(fixture.applied).toEqual(["project"]);
});
it("keeps a stable id across both modes so the registry tiebreak never moves", () => {
expect(buildGroupingContribution(source("project").value).id).toBe(
buildGroupingContribution(source("status").value).id,
);
});
it("stays out of the default empty-query list", () => {
for (const mode of ["project", "status"] as const) {
const contribution = buildGroupingContribution(source(mode).value);
expect(contribution.visibility).toBe("query");
expect(contribution.group).toBe("actions");
// 6 is keyboard-shortcuts and 7 belongs to the workspace actions in #3013.
expect(contribution.rank).toBe(8);
}
});
});