Файли
openidea/src/platform/filePresentation.test.ts
T
l0ng-ai 9d670e6262 feat(project-tree): enrich JVM project view icons (#512)
Project rows only showed generic folder and filename icons, so JVM modules, packages and declarations looked alike.

Rows now show Maven and Gradle project and module icons, packages, Spring configuration and Boot application classes, runnable classes, test classes, Java and Kotlin declaration types, and generated, compiled and javadoc output folders. Editor tabs, Goto File and Recent Files use the same resolver. Types come from a bounded syntax parse of visible files, served locally and over remote RPC.

Spring stereotypes keep their ordinary type icons, and .class files stay binary.

Fixes #347
2026-10-31 10:40:24 +08:00

54 рядки
2.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { presentationIcon } from "./filePresentation";
import type { RootFolder } from "./languageSettings";
import type { JvmPresentation } from "./ipc";
const roots: RootFolder[] = [
{ path: "src/main/java", kind: "source", detectedFrom: "pom.xml" },
{ path: "src/test/java", kind: "test", detectedFrom: "pom.xml" },
{ path: "src/main/resources", kind: "resources", detectedFrom: "pom.xml" },
{ path: "src/test/resources", kind: "testResources", detectedFrom: "pom.xml" },
];
const type = (kind: JvmPresentation["kind"]): JvmPresentation => ({ kind, springBoot: false, runnable: false });
const icon = (path: string, info: JvmPresentation | null = null, spring = false) =>
presentationIcon(`/p/${path}`, info, roots, "/p", spring);
describe("JVM file presentation", () => {
it.each([
["class", "class"],
["abstractClass", "class-abstract"],
["interface", "interface"],
["enum", "enum"],
["record", "record"],
["annotation", "annotation"],
["exception", "exception"],
["object", "kotlin-object"],
] as const)("maps %s to %s", (kind, expected) => expect(icon("Foo.java", type(kind))).toBe(expected));
it.each(["LIMIT.java", "AUDIT.java", "Contest.java"])("keeps the type icon of %s", (path) =>
expect(icon(path, type("class"))).toBe("class"),
);
it.each(["FooTest.java", "FooTests.java", "FooIT.java", "FooTest.kt", "src/test/java/Anything.java"])(
"marks test classes: %s",
(path) => expect(icon(path, type("class"))).toBe("jvm-test"),
);
it("keeps files without declarations and binaries as file types", () => {
expect(icon("Foo.java", type(null))).toBe("file-java");
expect(icon("FooTest.java", type(null))).toBe("file-java");
expect(icon("Foo.kt")).toBe("file-kotlin");
expect(icon("Foo.class")).toBe("file-binary");
expect(icon("Contest.java", type("class"))).toBe("class");
});
it.each(["application.yml", "application-dev.yaml", "bootstrap.properties", "bootstrap-local.yml"])(
"requires Spring or a resource root: %s",
(name) => {
expect(icon(`src/main/resources/${name}`)).toBe("spring-config");
expect(icon(`src/test/resources/${name}`)).toBe("spring-config");
expect(icon(name, null, true)).toBe("spring-config");
expect(icon(name)).not.toBe("spring-config");
},
);
it("uses the entire Boot icon on application classes", () => {
expect(icon("App.java", { ...type("class"), springBoot: true, runnable: true })).toBe("spring-boot");
});
});