Skip to content

Commit cec5419

Browse files
committed
Fixes + add test
1 parent 2bb2550 commit cec5419

File tree

5 files changed

+76
-6
lines changed

5 files changed

+76
-6
lines changed

src/main/frontend/common/components/dropdown.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import React, { useEffect, useRef } from "react";
22

3+
declare global {
4+
interface Window {
5+
Behaviour: any;
6+
}
7+
}
8+
39
/**
410
* Provides a bridge between React and the Jenkins' dropdown component
511
*/
@@ -32,8 +38,7 @@ export default function Dropdown({ items, disabled }: DropdownProps) {
3238
`;
3339
buttonRef.current.parentNode?.appendChild(template);
3440

35-
// @ts-ignore
36-
Behaviour.applySubtree(buttonRef.current.parentNode, true);
41+
window.Behaviour?.applySubtree(buttonRef.current.parentNode, true);
3742
}, []);
3843

3944
return (

src/main/frontend/common/components/tooltip.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import React, { useEffect, useRef } from "react";
22

3+
declare global {
4+
interface Window {
5+
Behaviour: any;
6+
}
7+
}
8+
39
/**
410
* Provides a bridge between React and the Jenkins' tooltip component
511
*/
@@ -11,8 +17,7 @@ export default function Tooltip({ text, children }: TooltipProps) {
1117
return;
1218
}
1319

14-
// @ts-ignore
15-
Behaviour.applySubtree(ref.current.parentNode, true);
20+
window.Behaviour?.applySubtree(ref.current.parentNode, true);
1621
}, []);
1722

1823
return (
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/** * @jest-environment jsdom */
2+
3+
import React from "react";
4+
import { render, screen } from "@testing-library/react";
5+
import { Result, StageInfo } from "../../../pipeline-graph-view/pipeline-graph/main";
6+
import { paused } from "../../../common/utils/timings";
7+
import StageDetails from "./stage-details";
8+
9+
describe("StageDetails", () => {
10+
it("renders null when stage is null", () => {
11+
const { container } = render(<StageDetails stage={null} />);
12+
13+
expect(container.firstChild).toBeNull();
14+
});
15+
16+
it("renders stage name and status color class", () => {
17+
render(<StageDetails stage={mockStage} />);
18+
19+
const heading = screen.getByRole("heading", { level: 2 });
20+
expect(heading).toHaveTextContent("Build");
21+
const wrapper = heading.closest(".pgv-stage-details");
22+
expect(wrapper?.className).toMatch("pgv-stage-details jenkins-!-success-color");
23+
});
24+
25+
it("shows running bar if stage is running", () => {
26+
render(<StageDetails stage={{ ...mockStage, state: Result.running }} />);
27+
28+
const runningIndicator = document.querySelector(".pgv-stage-details__running");
29+
expect(runningIndicator).toBeInTheDocument()
30+
});
31+
32+
it("does not show pause time if pauseDurationMillis is 0", () => {
33+
render(<StageDetails stage={{ ...mockStage, pauseDurationMillis: 0 }} />);
34+
35+
expect(screen.queryByText(paused(0))).not.toBeInTheDocument();
36+
});
37+
38+
it("disables dropdown if stage is synthetic", () => {
39+
render(<StageDetails stage={{ ...mockStage, synthetic: true }} />);
40+
41+
expect(screen.queryByRole("button")).toBeDisabled();
42+
});
43+
});
44+
45+
const mockStage: StageInfo = {
46+
name: "Build",
47+
state: Result.success,
48+
skeleton: false,
49+
completePercent: 100,
50+
id: 1,
51+
title: "Build",
52+
type: "STAGE",
53+
agent: "agent-1",
54+
children: [],
55+
pauseDurationMillis: 5000,
56+
startTimeMillis: 1713440000000,
57+
totalDurationMillis: 120000,
58+
url: "",
59+
};

src/main/frontend/setupTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
require("@testing-library/react");
1+
require("@testing-library/jest-dom");

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"jsx": "react",
1010
"resolveJsonModule": true,
1111
"esModuleInterop": true,
12-
"useUnknownInCatchVariables": false
12+
"useUnknownInCatchVariables": false,
13+
"types": ["node", "jest", "@testing-library/jest-dom"]
1314
}
1415
}

0 commit comments

Comments
 (0)