tui-sidebar-render.test.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import assert from "node:assert/strict";
  2. import test from "node:test";
  3. import { testRender } from "@mbears/opentui-react/test-utils";
  4. import { getZCodeCopy } from "@zcode/i18n";
  5. import React, { act } from "react";
  6. import type { SidebarState } from "../src/app-model.js";
  7. import { Sidebar } from "../src/app-sidebar.js";
  8. test("renders localized sidebar rows without section title glyph tails", async () => {
  9. let view: Awaited<ReturnType<typeof testRender>> | undefined;
  10. await act(async () => {
  11. view = await testRender(
  12. React.createElement(
  13. "box",
  14. { style: { height: 44, width: 42 } },
  15. React.createElement(Sidebar, {
  16. ...baseSidebarState,
  17. copy: getZCodeCopy("zh-CN").tui,
  18. developerMode: true,
  19. status: "就绪。",
  20. }),
  21. ),
  22. {
  23. height: 44,
  24. kittyKeyboard: true,
  25. otherModifiersMode: true,
  26. width: 42,
  27. },
  28. );
  29. await view.flush();
  30. });
  31. try {
  32. assert.ok(view);
  33. const lines = view
  34. .captureCharFrame()
  35. .split("\n")
  36. .map((line) => line.trimEnd());
  37. // Todos 改为可折叠区块,标题与 API 等区块一样带展开标记。
  38. assert.ok(lines.includes(" ▼ Todos"));
  39. assert.ok(lines.includes(" 进度 0/0"));
  40. assert.ok(lines.includes(" ▼ API"));
  41. assert.ok(lines.includes(" 模型 -"));
  42. assert.equal(
  43. lines.some((line) => line.includes("进度s")),
  44. false,
  45. );
  46. assert.equal(
  47. lines.some((line) => line.includes("模型I")),
  48. false,
  49. );
  50. } finally {
  51. await act(async () => {
  52. view?.renderer.destroy();
  53. });
  54. }
  55. });
  56. const baseSidebarState: SidebarState = {
  57. busy: false,
  58. contextUsage: {},
  59. draft: "",
  60. lastEvent: "idle",
  61. messageCount: 0,
  62. mcpStatus: {
  63. loading: false,
  64. servers: {},
  65. },
  66. mode: "build",
  67. model: "glm-4.6",
  68. modifiedFiles: [],
  69. networkRequests: [],
  70. status: "Ready.",
  71. statusDetails: [],
  72. thoughtLevel: "medium",
  73. todos: [],
  74. };