-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
ProfilingLink.component.test.tsx
71 lines (61 loc) · 2.75 KB
/
ProfilingLink.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
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import React from "react";
import "@testing-library/jest-dom";
import { TEST_APP_WRAPPER } from "../util/test-utils";
import { ProfilerButton } from "./ProfilingLink";
describe("ProfilerButton", () => {
const mockProps = {
profilerUrl: "http://localhost:3000/worker/memory_profile",
};
it("renders button correctly", () => {
render(<ProfilerButton {...mockProps} />, { wrapper: TEST_APP_WRAPPER });
const button = screen.getByLabelText(/Memory Profiling/);
expect(button).toBeInTheDocument();
});
it("opens the dialog when the button is clicked", async () => {
const user = userEvent.setup();
render(<ProfilerButton {...mockProps} />, { wrapper: TEST_APP_WRAPPER });
const button = screen.getByLabelText(/Memory Profiling/);
user.click(button);
// check all components exist in dialog
await waitFor(() => {
const dialogTitle = screen.getByText("Memory Profiling Config");
expect(dialogTitle).toBeInTheDocument();
const reportButton = screen.getByText(/Generate report/);
expect(reportButton).toBeInTheDocument();
const durationInput = screen.getByLabelText(/Duration/);
expect(durationInput).toBeInTheDocument();
const leaksCheckbox = screen.getByText(/Leaks/);
expect(leaksCheckbox).toBeInTheDocument();
const nativeCheckbox = screen.getByText(/Native/);
expect(nativeCheckbox).toBeInTheDocument();
const allocatorCheckbox = screen.getByText(/Python Allocator Tracing/);
expect(allocatorCheckbox).toBeInTheDocument();
});
});
it("closes the dialog when the cancel button is clicked", async () => {
const user = userEvent.setup();
render(<ProfilerButton {...mockProps} />, { wrapper: TEST_APP_WRAPPER });
const button = screen.getByLabelText(/Memory Profiling/);
await user.click(button);
const cancelButton = screen.getByRole("button", { name: /Cancel/ });
await user.click(cancelButton);
await waitFor(() => {
const dialogTitle = screen.queryByText(/Memory Profiling Config/);
expect(dialogTitle).not.toBeInTheDocument();
});
});
it('selects "flamegraph" as the default format', async () => {
const user = userEvent.setup();
render(<ProfilerButton {...mockProps} />, { wrapper: TEST_APP_WRAPPER });
const button = screen.getByLabelText(/Memory Profiling/);
await user.click(button);
const formatSelect = screen.getByLabelText(/flamegraph/);
expect(formatSelect).toBeInTheDocument();
expect(screen.getByText(/Generate report/)).toHaveAttribute(
"href",
`${mockProps.profilerUrl}&format=flamegraph&duration=5&leaks=1&native=0&trace_python_alocators=0`,
);
});
});