workflowTimelineTracks.test.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. // @vitest-environment jsdom
  2. // 带与轨道在卡上的画法(docs/dynamic-workflow/presentation.md「Drawing the timeline」的「Bands on the card」):
  3. // 主线走最下面一行、分支叠在它上面、站头搬到站台行,分叉与汇合是曲线。没有带的时间线一像素不动。
  4. import { act, cleanup, fireEvent, render, waitFor } from "@testing-library/react";
  5. import { createElement } from "react";
  6. import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
  7. import type { WorkflowRunState } from "@zcode/shared/zcode-protocol-v4";
  8. import type { WorkflowCausalityGraphData } from "@/components/workflow-graph/types.js";
  9. import { buildWorkflowTimeline } from "@/components/workflow-timeline/timeline-model.js";
  10. import { timelineLayout, timelineWidth } from "@/components/workflow-timeline/timeline-geometry.js";
  11. import {
  12. timelineHeight,
  13. WorkflowTimeline,
  14. } from "@/components/workflow-timeline/WorkflowTimeline.js";
  15. import { timelineRailPieces } from "@/components/workflow-timeline/WorkflowTimelineTracks.js";
  16. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  17. interface GraphSpec {
  18. names: readonly string[];
  19. /** 站下标 → 与它并行的站下标。 */
  20. alongside?: Record<number, readonly number[]>;
  21. edges: readonly (readonly [number, number])[];
  22. }
  23. function graphOf({ alongside = {}, edges, names }: GraphSpec): WorkflowCausalityGraphData {
  24. return {
  25. steps: names.map((name, i) => ({
  26. id: `ask#${i + 1}`,
  27. kind: "ask",
  28. label: name,
  29. line: i + 1,
  30. column: 1,
  31. lane: "actor#1",
  32. phase: `phase#${i + 1}`,
  33. })),
  34. lanes: [{ id: "actor#1", name: "worker", line: 1, column: 1 }],
  35. participants: names.map((_, i) => ({
  36. id: `phase#${i + 1}:actor#1`,
  37. phase: `phase#${i + 1}`,
  38. lane: "actor#1",
  39. steps: [`ask#${i + 1}`],
  40. })),
  41. handoffs: [],
  42. phases: names.map((name, i) => ({
  43. id: `phase#${i + 1}`,
  44. name,
  45. line: i + 1,
  46. column: 1,
  47. ...(alongside[i] === undefined
  48. ? {}
  49. : { alongside: alongside[i]!.map((j) => `phase#${j + 1}`) }),
  50. })),
  51. phaseEdges: edges.map(([from, to]) => ({ from: `phase#${from + 1}`, to: `phase#${to + 1}` })),
  52. exits: [`phase#${names.length}`],
  53. } as WorkflowCausalityGraphData;
  54. }
  55. /** 测试台架:A ∥ B → C,B 与 A 并行;边 A → B、B → C。 */
  56. const TESTFIELD: GraphSpec = {
  57. alongside: { 1: [0] },
  58. edges: [
  59. [0, 1],
  60. [1, 2],
  61. ],
  62. names: ["A", "B", "C"],
  63. };
  64. /** 同一条带,前面多一个前驱 P。 */
  65. const WITH_PRED: GraphSpec = {
  66. alongside: { 2: [1] },
  67. edges: [
  68. [0, 1],
  69. [1, 2],
  70. [2, 3],
  71. ],
  72. names: ["P", "A", "B", "C"],
  73. };
  74. /** 带 [[A], [B, C]],前有 P、后有 J;B → C 里再来一条回边 C → B(同一条轨道上的弧)。 */
  75. const INNER_LOOP: GraphSpec = {
  76. alongside: { 2: [1], 3: [1] },
  77. edges: [
  78. [0, 1],
  79. [0, 2],
  80. [2, 3],
  81. [3, 4],
  82. [1, 4],
  83. [3, 2],
  84. ],
  85. names: ["P", "A", "B", "C", "J"],
  86. };
  87. function modelOf(spec: GraphSpec, run?: WorkflowRunState) {
  88. return buildWorkflowTimeline(graphOf(spec), run);
  89. }
  90. function renderTimeline(model: ReturnType<typeof buildWorkflowTimeline>) {
  91. return render(
  92. createElement(
  93. ZCodeIntlProvider,
  94. { initialLocale: "en-US" },
  95. createElement(WorkflowTimeline, { model }),
  96. ),
  97. );
  98. }
  99. /** 站 `running` 的 run:前面的站都结算过,最后一站在跑。 */
  100. function runWith(names: readonly string[], runningIndex: number): WorkflowRunState {
  101. return {
  102. runId: "dwfrun-1",
  103. toolCallId: "tool-1",
  104. status: "running",
  105. usage: { spentTokens: 1, nodesUsed: names.length },
  106. actors: [
  107. { siteId: "actor#1", ordinal: 1, name: "worker", sessionId: "s-1", status: "running" },
  108. ],
  109. nodes: names.map((_, i) => ({
  110. siteId: `ask#${i + 1}`,
  111. ordinal: 1,
  112. actorSiteId: "actor#1",
  113. actorOrdinal: 1,
  114. ...(i === runningIndex
  115. ? { phase: "executing" as const }
  116. : { phase: "settled" as const, outcome: "ok" as const }),
  117. })) as WorkflowRunState["nodes"],
  118. lastEventSequence: 1,
  119. };
  120. }
  121. const railsOf = (view: ReturnType<typeof render>) =>
  122. [...view.container.querySelectorAll("[data-testid='workflow-timeline-rail']")].map((rail) => ({
  123. d: rail.querySelector("path")?.getAttribute("d") ?? undefined,
  124. from: rail.getAttribute("data-rail-from"),
  125. ink: rail.getAttribute("data-rail-ink"),
  126. kind: rail.getAttribute("data-rail-kind"),
  127. to: rail.getAttribute("data-rail-to"),
  128. }));
  129. afterEach(cleanup);
  130. describe("timelineLayout", () => {
  131. it("without bands the rows are exactly the old rail row: 6px of air, no platform row", () => {
  132. const model = modelOf({ edges: [[0, 1]], names: ["A", "B"] });
  133. expect(model.bands).toHaveLength(0);
  134. expect(timelineLayout(model.arcs, model.bands)).toEqual({
  135. banded: false,
  136. capY: 18,
  137. inset: 0,
  138. pillsTop: 38,
  139. rowY: [18],
  140. });
  141. });
  142. it("with a band: branch rows stack above the main line, then a 24px platform row", () => {
  143. const model = modelOf(TESTFIELD);
  144. // 顶上一层空没有弧 → 6px 呼吸;分支行 24;主线的空 0;主线行 24;站台行 24;再 8px 到药丸。
  145. expect(timelineLayout(model.arcs, model.bands)).toEqual({
  146. banded: true,
  147. capY: 66,
  148. inset: 12,
  149. pillsTop: 86,
  150. rowY: [42, 18],
  151. });
  152. });
  153. it("an arc in the top air pushes that row down to leave the lane its 8px ceiling", () => {
  154. const model = modelOf({ ...TESTFIELD, edges: [...TESTFIELD.edges, [2, 0]] });
  155. expect(model.arcs).toEqual([{ air: 1, from: 2, ink: "faint", lane: 0, to: 0 }]);
  156. expect(timelineLayout(model.arcs, model.bands).rowY).toEqual([58, 34]);
  157. });
  158. });
  159. describe("WorkflowTimeline with bands", () => {
  160. it("draws two track rows, B on the branch, captions on the platform row, and only B gets a leader", () => {
  161. const model = modelOf(TESTFIELD);
  162. expect(model.stations.map((station) => station.track)).toEqual([0, 1, 0]);
  163. const view = renderTimeline(model);
  164. const layout = timelineLayout(model.arcs, model.bands);
  165. // 灯:A 与 C 在主线行,B 在分支行;x = 站左缘 + 17 − 5,整条轨道右移 12(带从站 0 起)。
  166. const lamps = [...view.container.querySelectorAll("[data-lamp]")] as HTMLElement[];
  167. expect(lamps.map((lamp) => lamp.getAttribute("data-lamp-track"))).toEqual(["0", "1", "0"]);
  168. expect(lamps.map((lamp) => lamp.style.top)).toEqual(["37px", "13px", "37px"]);
  169. expect(lamps.map((lamp) => lamp.style.left)).toEqual(["24px", "216px", "408px"]);
  170. // 站头:全部落在站台行上,左缘 = 站左缘 + 12,宽 168 − 12。
  171. const stations = view.getAllByTestId("workflow-timeline-station") as HTMLElement[];
  172. expect(stations.map((station) => station.getAttribute("data-station-track"))).toEqual([
  173. "0",
  174. "1",
  175. "0",
  176. ]);
  177. expect(stations.map((station) => station.style.top)).toEqual(["54px", "54px", "54px"]);
  178. expect(stations.map((station) => station.style.left)).toEqual(["24px", "216px", "408px"]);
  179. expect(stations.map((station) => station.style.width)).toEqual(["156px", "156px", "156px"]);
  180. expect(stations.map((station) => station.textContent)).toEqual(["A", "B", "C"]);
  181. // 引线只给分支轨道的站:主线的灯就在自己的名字正上方,不必再连一条。
  182. const leaders = view.getAllByTestId("workflow-timeline-leader");
  183. expect(leaders).toHaveLength(1);
  184. expect(leaders[0]!.getAttribute("data-leader-station")).toBe("1");
  185. expect(leaders[0]!.getAttribute("d")).toBe(`M221,25 V${layout.capY - 10}`);
  186. expect(leaders[0]!.getAttribute("stroke-dasharray")).toBe("1 2");
  187. expect(leaders[0]!.getAttribute("stroke-linecap")).toBe("round");
  188. });
  189. it("A → C rides the main row through fork and merge; B merges with a curve; A → B is not a rail", () => {
  190. const view = renderTimeline(modelOf(TESTFIELD));
  191. const rails = railsOf(view);
  192. // 带没有前驱:主线先是一小截尾巴,从 forkX − 4 一直到首站灯前 8px。
  193. expect(rails).toContainEqual({
  194. d: "M0,42 H21",
  195. from: null,
  196. ink: "faint",
  197. kind: "tail",
  198. to: "0",
  199. });
  200. // 分支轨道从同一个分叉点升起来,两段 8px 的四分之一圆。
  201. expect(rails).toContainEqual({
  202. d: "M4,42 Q12,42 12,34 V26 Q12,18 20,18 H213",
  203. from: null,
  204. ink: "faint",
  205. kind: "fork",
  206. to: "1",
  207. });
  208. // A → C 是主线上一条直线,横穿汇合点(mergeX = colX(2) − 10 = 386)。
  209. expect(rails).toContainEqual({
  210. d: "M37,42 H405",
  211. from: "0",
  212. ink: "faint",
  213. kind: null,
  214. to: "2",
  215. });
  216. // B → C 是汇合曲线:横到 xm − 8,落回主线。
  217. expect(rails).toContainEqual({
  218. d: "M229,18 H378 Q386,18 386,26 V34 Q386,42 394,42",
  219. from: "1",
  220. ink: "faint",
  221. kind: "merge",
  222. to: "2",
  223. });
  224. // A → B 被分叉吃掉了(控制经过了两条轨道,分叉已经说过);双线段不画在卡上。
  225. expect(rails.some((rail) => rail.from === "0" && rail.to === "1")).toBe(false);
  226. expect(rails).toHaveLength(4);
  227. });
  228. it("a leading band insets the whole rail by 12 and the box is exactly timelineHeight", () => {
  229. const model = modelOf(TESTFIELD);
  230. const view = renderTimeline(model);
  231. const box = view.getByTestId("workflow-timeline-scroller").firstElementChild as HTMLElement;
  232. expect(box.style.width).toBe(`${timelineWidth(3, 12)}px`);
  233. expect(box.style.width).toBe("564px");
  234. expect(box.style.height).toBe(`${timelineHeight(model)}px`);
  235. // 站台行的底 + 8 是药丸的顶;高度 = 药丸顶 + 最高的一列 + 8。
  236. const pills = view.getAllByTestId("workflow-timeline-pills") as HTMLElement[];
  237. expect(pills.map((column) => column.style.top)).toEqual(["86px", "86px", "86px"]);
  238. expect(pills.map((column) => column.style.left)).toEqual(["12px", "204px", "396px"]);
  239. expect(timelineHeight(model)).toBe(86 + 32 + 8);
  240. // 收起的运行卡把药丸清空(`WorkflowRunDigest`),轨道与站台行留着:高度正好是药丸的顶 + 8。
  241. const collapsed = { ...model, stations: model.stations.map((s) => ({ ...s, pills: [] })) };
  242. expect(timelineHeight(collapsed)).toBe(86 + 8);
  243. });
  244. it("with a predecessor there is no inset and the fork is a rail from P into B", () => {
  245. const model = modelOf(WITH_PRED);
  246. expect(model.bands[0]).toMatchObject({ from: 1, join: 3, pred: 0, to: 2 });
  247. const view = renderTimeline(model);
  248. expect(timelineLayout(model.arcs, model.bands).inset).toBe(0);
  249. const rails = railsOf(view);
  250. // P → B:分叉曲线,从 colX(1) − 16 = 176 起,墨随这条段自己。
  251. expect(rails).toContainEqual({
  252. d: "M176,42 Q184,42 184,34 V26 Q184,18 192,18 H393",
  253. from: "0",
  254. ink: "faint",
  255. kind: "fork",
  256. to: "2",
  257. });
  258. // P → A 与 A → C 都是主线上的直线;主线因此穿过分叉点与汇合点。
  259. expect(rails).toContainEqual({
  260. d: "M25,42 H201",
  261. from: "0",
  262. ink: "faint",
  263. kind: null,
  264. to: "1",
  265. });
  266. expect(rails).toContainEqual({
  267. d: "M217,42 H585",
  268. from: "1",
  269. ink: "faint",
  270. kind: null,
  271. to: "3",
  272. });
  273. // 没有尾巴、没有残段:两头都有站。
  274. expect(rails.map((rail) => rail.kind)).not.toContain("tail");
  275. expect(rails.map((rail) => rail.kind)).not.toContain("stub");
  276. });
  277. it("every rail into the running station marches, main row and merge alike", () => {
  278. const model = modelOf(TESTFIELD, runWith(TESTFIELD.names, 2));
  279. expect(model.stations.map((station) => station.status)).toEqual(["done", "done", "running"]);
  280. const view = renderTimeline(model);
  281. const marching = railsOf(view).filter((rail) => rail.ink === "march");
  282. expect(marching.map((rail) => [rail.from, rail.to, rail.kind])).toEqual([
  283. ["0", "2", null],
  284. ["1", "2", "merge"],
  285. ]);
  286. // 行进的段在同一条路径上叠一条亮着的光(不动):渐变描边,渐变沿这一段的首尾两点铺,
  287. // 在灯那一头(终点)满色。渐变的 id 各不相同,且都在这张 SVG 里。
  288. const lights = view.container.querySelectorAll(
  289. "[data-testid='workflow-timeline-rail'] path.wf-lit",
  290. );
  291. expect(lights).toHaveLength(2);
  292. const pieces = timelineRailPieces(model, timelineLayout(model.arcs, model.bands)).filter(
  293. (piece) => piece.ink === "march",
  294. );
  295. const ids = Array.from(lights).map((light) => {
  296. const stroke = light.getAttribute("stroke") ?? "";
  297. expect(light.getAttribute("data-testid")).toBe("workflow-march-light");
  298. expect(stroke).toMatch(/^url\(#.+\)$/);
  299. return stroke.slice(5, -1);
  300. });
  301. expect(new Set(ids).size).toBe(2);
  302. ids.forEach((id, k) => {
  303. const gradient = view.container.querySelector(`linearGradient[id="${id}"]`);
  304. expect(gradient?.getAttribute("gradientUnits")).toBe("userSpaceOnUse");
  305. expect(Number(gradient?.getAttribute("x1"))).toBe(pieces[k]!.start.x);
  306. expect(Number(gradient?.getAttribute("x2"))).toBe(pieces[k]!.end.x);
  307. });
  308. });
  309. it("a rail piece's start and end are the first and last points of its path", () => {
  310. const model = modelOf(TESTFIELD, runWith(TESTFIELD.names, 2));
  311. for (const piece of timelineRailPieces(model, timelineLayout(model.arcs, model.bands))) {
  312. // 沿着 M / H / V / Q 走一遍(轨道段只用这四个命令),落点就是终点。
  313. const tokens = piece.d
  314. .replace(/([MHVQ])/g, " $1 ")
  315. .trim()
  316. .split(/[\s,]+/);
  317. let x = 0;
  318. let y = 0;
  319. let start: { x: number; y: number } | undefined;
  320. for (let i = 0; i < tokens.length; ) {
  321. const command = tokens[i++];
  322. if (command === "M") {
  323. x = Number(tokens[i++]);
  324. y = Number(tokens[i++]);
  325. start ??= { x, y };
  326. } else if (command === "H") x = Number(tokens[i++]);
  327. else if (command === "V") y = Number(tokens[i++]);
  328. else if (command === "Q") {
  329. i += 2;
  330. x = Number(tokens[i++]);
  331. y = Number(tokens[i++]);
  332. } else throw new Error(`unexpected path command ${command} in ${piece.d}`);
  333. }
  334. expect(start).toEqual(piece.start);
  335. expect({ x, y }).toEqual(piece.end);
  336. }
  337. });
  338. it("a band-level arc lives in the top air but its riser starts and lands on the main row", () => {
  339. const model = modelOf({ ...TESTFIELD, edges: [...TESTFIELD.edges, [2, 0]] });
  340. const view = renderTimeline(model);
  341. const rowY = timelineLayout(model.arcs, model.bands).rowY;
  342. expect(rowY).toEqual([58, 34]);
  343. const arc = view.getByTestId("workflow-timeline-arc");
  344. expect(arc.getAttribute("data-arc-from")).toBe("2");
  345. expect(arc.getAttribute("data-arc-to")).toBe("0");
  346. // 源在带外 → 从 C 的灯那一行(主线,58)起飞,7px 之上;车道在最上面那层空里(ly = 34 − 26 = 8);
  347. // 目标是带 → 落在分叉点 x = 4 上,主线之上 4px——竖段一路穿过分支行,而不是停在它边上。
  348. expect(arc.querySelector("path")!.getAttribute("d")).toBe(
  349. "M413,51 V16 Q413,8 405,8 H12 Q4,8 4,16 V54",
  350. );
  351. expect(arc.querySelector("path")!.getAttribute("d")).toContain(`M413,${rowY[0]! - 7}`);
  352. expect(arc.querySelector("path")!.getAttribute("d")).toContain(`V${rowY[0]! - 4}`);
  353. });
  354. it("an arc inside one track stays in that track's air, lamp to lamp", () => {
  355. // 带 [[1], [2, 3]]:3 → 2 是同一条轨道上的回边,与带级的弧同住最上面那层空(R = 2),
  356. // 但它两端都是灯——认错了就会画成整条带的自环。
  357. const model = modelOf(INNER_LOOP);
  358. expect(model.bands[0]!.tracks.map((track) => track.stations)).toEqual([[1], [2, 3]]);
  359. expect(model.arcs).toEqual([{ air: 1, from: 3, ink: "faint", lane: 0, to: 2 }]);
  360. const view = renderTimeline(model);
  361. const arc = view.getByTestId("workflow-timeline-arc");
  362. expect(arc.querySelector("path")!.getAttribute("d")).toBe(
  363. "M593,27 V16 Q593,8 585,8 H409 Q401,8 401,16 V25",
  364. );
  365. });
  366. });
  367. describe("WorkflowTimeline without bands", () => {
  368. it("keeps the old DOM: rails are spans on the station row, no leaders, no platform row", () => {
  369. const model = modelOf({
  370. edges: [
  371. [0, 1],
  372. [1, 2],
  373. ],
  374. names: ["plan", "work", "verify"],
  375. });
  376. const view = renderTimeline(model);
  377. const rails = view.getAllByTestId("workflow-timeline-rail");
  378. expect(rails.map((rail) => rail.tagName)).toEqual(["SPAN", "SPAN"]);
  379. expect(rails.map((rail) => rail.className)).toEqual([
  380. expect.stringContaining("border-foreground-subtlest"),
  381. expect.stringContaining("border-foreground-subtlest"),
  382. ]);
  383. expect(view.queryAllByTestId("workflow-timeline-leader")).toHaveLength(0);
  384. const stations = view.getAllByTestId("workflow-timeline-station") as HTMLElement[];
  385. // 站头还排在轨道行里:没有绝对定位,也没有轨道号。
  386. expect(stations.map((station) => station.getAttribute("data-station-track"))).toEqual([
  387. null,
  388. null,
  389. null,
  390. ]);
  391. expect(stations.map((station) => station.style.top)).toEqual(["", "", ""]);
  392. expect(stations[0]!.querySelector("[data-lamp]")).not.toBeNull();
  393. const box = view.getByTestId("workflow-timeline-scroller").firstElementChild as HTMLElement;
  394. expect(box.style.width).toBe("552px");
  395. expect(box.style.height).toBe(`${timelineHeight(model)}px`);
  396. expect(timelineHeight(model)).toBe(6 + 24 + 8 + 32 + 8);
  397. });
  398. });
  399. // ── 边檐:带压扁之后,并行的两站之间是一条双线段 ─────────────────────────────
  400. const LEDGE_SPEC: GraphSpec = {
  401. alongside: { 1: [0] },
  402. edges: [0, 1, 2, 3, 4, 5, 6].map((i) => [i, i + 1] as const),
  403. names: ["A", "B", "C", "D", "E", "F", "G", "H"],
  404. };
  405. const VIEW = 960;
  406. let scrollLeftStore = 0;
  407. describe("WorkflowTimeline ledge with a band", () => {
  408. const scrollTo = vi.fn();
  409. beforeEach(() => {
  410. scrollLeftStore = 0;
  411. scrollTo.mockReset();
  412. const isScroller = (element: HTMLElement) =>
  413. element.dataset["testid"] === "workflow-timeline-scroller";
  414. Object.defineProperty(HTMLElement.prototype, "clientWidth", {
  415. configurable: true,
  416. get(this: HTMLElement) {
  417. return isScroller(this) ? VIEW : 0;
  418. },
  419. });
  420. Object.defineProperty(HTMLElement.prototype, "scrollWidth", {
  421. configurable: true,
  422. get(this: HTMLElement) {
  423. return isScroller(this) ? timelineWidth(8, 12) : 0;
  424. },
  425. });
  426. Object.defineProperty(HTMLElement.prototype, "scrollLeft", {
  427. configurable: true,
  428. get(this: HTMLElement) {
  429. return isScroller(this) ? scrollLeftStore : 0;
  430. },
  431. set(this: HTMLElement, value: number) {
  432. if (isScroller(this)) scrollLeftStore = value;
  433. },
  434. });
  435. Element.prototype.scrollTo = scrollTo as unknown as Element["scrollTo"];
  436. });
  437. afterEach(() => {
  438. cleanup();
  439. for (const key of ["clientWidth", "scrollWidth", "scrollLeft"]) {
  440. delete (HTMLElement.prototype as unknown as Record<string, unknown>)[key];
  441. }
  442. });
  443. it("folds A and B onto the left ledge and draws the twin between them as two 1px lines", async () => {
  444. const view = renderTimeline(modelOf(LEDGE_SPEC));
  445. scrollLeftStore = 400;
  446. await act(async () => {
  447. fireEvent.scroll(view.getByTestId("workflow-timeline-scroller"));
  448. await new Promise((resolve) => requestAnimationFrame(() => resolve(undefined)));
  449. });
  450. await waitFor(() => expect(view.getByTestId("workflow-timeline-ledge-left")).toBeTruthy());
  451. const ledge = view.getByTestId("workflow-timeline-ledge-left");
  452. const lamps = [...ledge.querySelectorAll("[data-testid='workflow-timeline-ledge-lamp']")];
  453. expect(lamps.map((lamp) => lamp.getAttribute("data-station-index"))).toEqual(["0", "1", "2"]);
  454. // A 与 B 之间是双线段;B 与 C 之间是汇合,画成一条普通的补线。
  455. const segments = [...ledge.querySelectorAll("[data-ledge-ink]")];
  456. expect(segments.map((segment) => segment.getAttribute("data-ledge-twin"))).toEqual([
  457. "true",
  458. null,
  459. null,
  460. ]);
  461. // 遮罩的轨道带一直盖到站台行的底(86 − 8 = 78),否则檐旁的名字会被硬切。
  462. expect(view.getByTestId("workflow-timeline-scroller").getAttribute("style")).toContain(
  463. "mask-position: 0 0, 0 78px",
  464. );
  465. const twin = segments[0]!;
  466. expect(twin.querySelectorAll("span")).toHaveLength(2);
  467. expect(
  468. [...twin.querySelectorAll("span")].map((line) => (line as HTMLElement).style.top),
  469. ).toEqual(["-1px", "1px"]);
  470. });
  471. });