Files
openidea/src/platform/projectPresentation.test.ts
T
kevinh 2a6cc686eb feat(project-view): show Maven and Gradle module folders in bold (#835)
Module folders below the project root are shown in bold in the Project view, from the same build presentation the module icons use; the root and plain folders keep their style.

Fixes #813

Co-authored-by: kevinh458 <[email protected]>
2026-11-02 20:13:31 +08:00

76 lines
2.7 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { buildPresentation, isModuleFolder, moduleFolderIcon } from "./projectPresentation";
import type { BuildModel } from "./ipc";
const model = (partial: unknown) => ({ maven: null, gradle: null, ...(partial as object) }) as BuildModel;
describe("build presentation context", () => {
it.each(["maven", "gradle"] as const)("uses distinct %s root and nested module glyphs", (tool) => {
const modules = new Map([
["", tool],
["app", tool],
]);
expect(moduleFolderIcon("", true, modules)).toBe(`${tool}-project`);
expect(moduleFolderIcon("app", false, modules)).toBe(`${tool}-module`);
expect(moduleFolderIcon("plain", false, modules)).toBeNull();
});
it("marks nested module folders, not the project root or plain folders", () => {
const modules = new Map<string, "maven" | "gradle">([
["", "maven"],
["core", "maven"],
["services/api", "gradle"],
]);
expect(isModuleFolder("core", false, modules)).toBe(true);
expect(isModuleFolder("services/api", false, modules)).toBe(true);
expect(isModuleFolder("", true, modules)).toBe(false);
expect(isModuleFolder("services", false, modules)).toBe(false);
expect(isModuleFolder("core/src", false, modules)).toBe(false);
});
it("includes Maven aggregators and modules without source roots", () => {
const context = buildPresentation(
model({
maven: {
projects: [
{ dir: "", dependencies: [], plugins: [] },
{ dir: "app", dependencies: [{ groupId: "org.springframework.boot" }], plugins: [] },
],
},
}),
);
expect([...context.modules]).toEqual([
["", "maven"],
["app", "maven"],
]);
expect(context.spring).toBe(true);
});
it("includes Gradle root and nested project directories", () => {
const context = buildPresentation(
model({
gradle: {
projects: [
{ dir: "", tasks: [] },
{ dir: "lib/core", tasks: [] },
],
},
}),
);
expect([...context.modules]).toEqual([
["", "gradle"],
["lib/core", "gradle"],
]);
expect(context.spring).toBe(false);
});
it("detects Spring build plugins and Gradle Boot tasks", () => {
expect(
buildPresentation(
model({
maven: { projects: [{ dir: "", dependencies: [], plugins: [{ groupId: "org.springframework.boot" }] }] },
}),
).spring,
).toBe(true);
expect(buildPresentation(model({ gradle: { projects: [{ dir: "", tasks: [{ name: "bootRun" }] }] } })).spring).toBe(
true,
);
});
it("keeps plain folders plain", () => expect(buildPresentation(model({})).modules.size).toBe(0));
});