|
1 | | -import { describe } from "vitest"; |
| 1 | +import { describe, expect } from "vitest"; |
2 | 2 |
|
3 | | -import { createNodeColumns } from "./PipelineGraphLayout.ts"; |
4 | | -import { Result, StageInfo, StageType } from "./PipelineGraphModel.tsx"; |
| 3 | +import { DEFAULT_LOCALE } from "../../../common/i18n/index.ts"; |
| 4 | +import { defaultMessages } from "../../../common/i18n/messages.ts"; |
| 5 | +import { createNodeColumns, layoutGraph } from "./PipelineGraphLayout.ts"; |
| 6 | +import { |
| 7 | + LayoutInfo, |
| 8 | + Result, |
| 9 | + StageInfo, |
| 10 | + StageType, |
| 11 | +} from "./PipelineGraphModel.tsx"; |
5 | 12 |
|
6 | 13 | describe("PipelineGraphLayout", () => { |
7 | | - describe("createNodeColumns", () => { |
8 | | - const baseStage: StageInfo = { |
9 | | - name: "", |
10 | | - title: "", |
11 | | - state: Result.success, |
12 | | - completePercent: 50, |
13 | | - id: 0, |
14 | | - type: "STAGE", |
15 | | - children: [], |
16 | | - pauseDurationMillis: 0, |
17 | | - startTimeMillis: 0, |
18 | | - totalDurationMillis: 0, |
19 | | - agent: "built-in", |
20 | | - url: "?selected-node=0", |
21 | | - }; |
| 14 | + const baseStage: StageInfo = { |
| 15 | + name: "", |
| 16 | + title: "", |
| 17 | + state: Result.success, |
| 18 | + completePercent: 50, |
| 19 | + id: 0, |
| 20 | + type: "STAGE", |
| 21 | + children: [], |
| 22 | + pauseDurationMillis: 0, |
| 23 | + startTimeMillis: 0, |
| 24 | + totalDurationMillis: 0, |
| 25 | + agent: "built-in", |
| 26 | + url: "?selected-node=0", |
| 27 | + }; |
22 | 28 |
|
23 | | - const makeStage = ( |
24 | | - id: number, |
25 | | - name: string, |
26 | | - children: Array<StageInfo> = [], |
27 | | - ): StageInfo => { |
28 | | - return { ...baseStage, id, name, children }; |
29 | | - }; |
| 29 | + const makeStage = ( |
| 30 | + id: number, |
| 31 | + name: string, |
| 32 | + children: Array<StageInfo> = [], |
| 33 | + ): StageInfo => { |
| 34 | + return { ...baseStage, id, name, children }; |
| 35 | + }; |
30 | 36 |
|
31 | | - const makeParallel = ( |
32 | | - id: number, |
33 | | - name: string, |
34 | | - children: Array<StageInfo> = [], |
35 | | - ): StageInfo => { |
36 | | - return { |
37 | | - ...baseStage, |
38 | | - id, |
39 | | - name, |
40 | | - children, |
41 | | - type: "PARALLEL" as StageType, |
42 | | - }; |
| 37 | + const makeParallel = ( |
| 38 | + id: number, |
| 39 | + name: string, |
| 40 | + children: Array<StageInfo> = [], |
| 41 | + ): StageInfo => { |
| 42 | + return { |
| 43 | + ...baseStage, |
| 44 | + id, |
| 45 | + name, |
| 46 | + children, |
| 47 | + type: "PARALLEL" as StageType, |
43 | 48 | }; |
| 49 | + }; |
44 | 50 |
|
| 51 | + describe("createNodeColumns", () => { |
45 | 52 | const makeNode = ( |
46 | 53 | id: number, |
47 | 54 | name: string, |
@@ -346,4 +353,64 @@ describe("PipelineGraphLayout", () => { |
346 | 353 | ]); |
347 | 354 | }); |
348 | 355 | }); |
| 356 | + |
| 357 | + describe("layoutGraph", () => { |
| 358 | + const layout: LayoutInfo = { |
| 359 | + nodeSpacingH: 140, |
| 360 | + parallelSpacingH: 140, |
| 361 | + nodeSpacingV: 70, |
| 362 | + nodeRadius: 12, |
| 363 | + terminalRadius: 10, |
| 364 | + curveRadius: 15, |
| 365 | + connectorStrokeWidth: 2, |
| 366 | + labelOffsetV: 22, |
| 367 | + smallLabelOffsetV: 15, |
| 368 | + ypStart: 55, |
| 369 | + }; |
| 370 | + |
| 371 | + const makeSmallLabel = (stageName: string) => { |
| 372 | + return { |
| 373 | + text: stageName, |
| 374 | + }; |
| 375 | + }; |
| 376 | + |
| 377 | + it("should not generate small labels for top stage columns with no children", () => { |
| 378 | + const graph = layoutGraph( |
| 379 | + [ |
| 380 | + makeStage(6, "Non-Parallel Stage"), |
| 381 | + makeStage(11, "Parallel Stage", [ |
| 382 | + makeParallel(15, "Branch A - P1"), |
| 383 | + makeParallel(16, "Branch B - P1"), |
| 384 | + makeParallel(17, "Branch C - P1", [ |
| 385 | + makeStage(25, "Nested 1 - P1"), |
| 386 | + makeStage(38, "Nested 2 - P1"), |
| 387 | + ]), |
| 388 | + ]), |
| 389 | + makeStage(49, "Skipped stage"), |
| 390 | + makeStage(53, "Parallel Stage 2", [ |
| 391 | + makeParallel(57, "Branch A - P2"), |
| 392 | + makeParallel(58, "Branch B - P2"), |
| 393 | + makeParallel(59, "Branch C - P2", [ |
| 394 | + makeStage(67, "Nested 1 - P2"), |
| 395 | + makeStage(80, "Nested 2 - P2"), |
| 396 | + ]), |
| 397 | + ]), |
| 398 | + ], |
| 399 | + layout, |
| 400 | + false, |
| 401 | + defaultMessages(DEFAULT_LOCALE), |
| 402 | + ); |
| 403 | + |
| 404 | + expect(graph.smallLabels).toMatchObject([ |
| 405 | + makeSmallLabel("Branch A - P1"), |
| 406 | + makeSmallLabel("Branch B - P1"), |
| 407 | + makeSmallLabel("Nested 1 - P1"), |
| 408 | + makeSmallLabel("Nested 2 - P1"), |
| 409 | + makeSmallLabel("Branch A - P2"), |
| 410 | + makeSmallLabel("Branch B - P2"), |
| 411 | + makeSmallLabel("Nested 1 - P2"), |
| 412 | + makeSmallLabel("Nested 2 - P2"), |
| 413 | + ]); |
| 414 | + }); |
| 415 | + }); |
349 | 416 | }); |
0 commit comments