Files
MyGoNavi/frontend/src/utils/jvmDiagnosticCompletion.test.ts
Syngnat 38e71119a4 feat(jvm-diagnostic): 优化诊断控制台命令体验
- 诊断命令输入使用编辑器外观并支持 Arthas 命令补全

- 新增命令执行 pending 输出、前端终态兜底和历史刷新

- 会话、输出、历史记录统一展示中文语义状态

- 补充诊断控制台和补全展示测试
2026-04-26 14:34:23 +08:00

54 lines
1.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
resolveJVMDiagnosticCompletionItems,
resolveJVMDiagnosticCompletionMode,
} from "./jvmDiagnosticCompletion";
describe("jvmDiagnosticCompletion", () => {
it("suggests command keywords when typing the first token", () => {
const items = resolveJVMDiagnosticCompletionItems("t");
expect(items.some((item) => item.label === "thread")).toBe(true);
expect(items.some((item) => item.label === "trace")).toBe(true);
});
it("suggests the jvm command from the command input hint", () => {
const items = resolveJVMDiagnosticCompletionItems("jv");
expect(items.some((item) => item.label === "jvm")).toBe(true);
});
it("switches to argument mode after the command head", () => {
expect(resolveJVMDiagnosticCompletionMode("thread -")).toEqual({
head: "thread",
mode: "argument",
search: "-",
});
});
it("returns command-specific snippets for trace style commands", () => {
const items = resolveJVMDiagnosticCompletionItems("watch ");
expect(items.some((item) => item.label === "watch 模板")).toBe(true);
expect(items.some((item) => item.label === "展开层级 -x 2")).toBe(true);
expect(items.every((item) => item.scope === "argument")).toBe(true);
});
it("supports multiline commands by using the current line before cursor", () => {
const items = resolveJVMDiagnosticCompletionItems(
"thread -n 5\nclas",
);
expect(items.some((item) => item.label === "classloader")).toBe(true);
expect(items.some((item) => item.label === "watch")).toBe(false);
});
it("falls back to command suggestions for unknown heads", () => {
const items = resolveJVMDiagnosticCompletionItems("unknown ");
expect(items.some((item) => item.label === "dashboard")).toBe(true);
expect(items.some((item) => item.label === "thread")).toBe(true);
});
});