-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
Metrics.component.test.tsx
87 lines (81 loc) · 2.7 KB
/
Metrics.component.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { render, screen } from "@testing-library/react";
import React, { PropsWithChildren } from "react";
import { GlobalContext } from "../../App";
import { STYLE_WRAPPER } from "../../util/test-utils";
import { Metrics } from "./Metrics";
const Wrapper = ({ children }: PropsWithChildren<{}>) => {
return (
<GlobalContext.Provider
value={{
metricsContextLoaded: true,
grafanaHost: "localhost:3000",
dashboardUids: {
default: "rayDefaultDashboard",
serve: "rayServeDashboard",
serveDeployment: "rayServeDeploymentDashboard",
data: "rayDataDashboard",
},
prometheusHealth: true,
sessionName: "session-name",
nodeMap: {},
nodeMapByIp: {},
namespaceMap: {},
dashboardDatasource: "Prometheus",
}}
>
<STYLE_WRAPPER>{children}</STYLE_WRAPPER>
</GlobalContext.Provider>
);
};
const MetricsDisabledWrapper = ({ children }: PropsWithChildren<{}>) => {
return (
<GlobalContext.Provider
value={{
metricsContextLoaded: true,
grafanaHost: undefined,
dashboardUids: {
default: "rayDefaultDashboard",
serve: "rayServeDashboard",
serveDeployment: "rayServeDeploymentDashboard",
data: "rayDataDashboard",
},
prometheusHealth: false,
sessionName: undefined,
nodeMap: {},
nodeMapByIp: {},
namespaceMap: {},
dashboardDatasource: "Prometheus",
}}
>
<STYLE_WRAPPER>{children}</STYLE_WRAPPER>
</GlobalContext.Provider>
);
};
describe("Metrics", () => {
it("renders", async () => {
expect.assertions(5);
render(<Metrics />, { wrapper: Wrapper });
await screen.findByText(/View in Grafana/);
expect(screen.getByText(/5 minutes/)).toBeVisible();
expect(screen.getByText(/Tasks and Actors/)).toBeVisible();
expect(screen.getByText(/Ray Resource Usage/)).toBeVisible();
expect(screen.getByText(/Hardware Utilization/)).toBeVisible();
expect(
screen.queryByText(
/Set up Prometheus and Grafana for better Ray Dashboard experience/,
),
).toBeNull();
});
it("renders warning when ", async () => {
expect.assertions(5);
render(<Metrics />, { wrapper: MetricsDisabledWrapper });
await screen.findByText(
/Set up Prometheus and Grafana for better Ray Dashboard experience/,
);
expect(screen.queryByText(/View in Grafana/)).toBeNull();
expect(screen.queryByText(/5 minutes/)).toBeNull();
expect(screen.queryByText(/Tasks and Actors/)).toBeNull();
expect(screen.queryByText(/Ray Resource Usage/)).toBeNull();
expect(screen.queryByText(/Hardware Utilization/)).toBeNull();
});
});