-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathMethodRow.spec.tsx
More file actions
193 lines (163 loc) · 5.6 KB
/
MethodRow.spec.tsx
File metadata and controls
193 lines (163 loc) · 5.6 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import * as React from "react";
import {
getAllByRole,
render as reactRender,
screen,
} from "@testing-library/react";
import { createMethod } from "../../../../test/factories/model-editor/method-factories";
import { Mode } from "../../../model-editor/shared/mode";
import { MethodRow, MethodRowProps } from "../MethodRow";
import { ModeledMethod } from "../../../model-editor/modeled-method";
import userEvent from "@testing-library/user-event";
import { ModelEditorViewState } from "../../../model-editor/shared/view-state";
import { createMockExtensionPack } from "../../../../test/factories/model-editor/extension-pack";
describe(MethodRow.name, () => {
const method = createMethod({
library: "sql2o",
libraryVersion: "1.6.0",
signature: "org.sql2o.Connection#createQuery(String)",
packageName: "org.sql2o",
typeName: "Connection",
methodName: "createQuery",
methodParameters: "(String)",
supported: false,
});
const modeledMethod: ModeledMethod = {
...method,
type: "summary",
input: "Argument[0]",
output: "ReturnValue",
kind: "taint",
provenance: "df-generated",
};
const onChange = jest.fn();
const viewState: ModelEditorViewState = {
mode: Mode.Application,
showFlowGeneration: false,
showLlmButton: false,
showMultipleModels: false,
extensionPack: createMockExtensionPack(),
sourceArchiveAvailable: true,
};
const render = (props: Partial<MethodRowProps> = {}) =>
reactRender(
<MethodRow
method={method}
methodCanBeModeled={true}
modeledMethods={[modeledMethod]}
methodIsUnsaved={false}
modelingInProgress={false}
revealedMethodSignature={null}
viewState={viewState}
onChange={onChange}
{...props}
/>,
);
it("renders a modelable method", () => {
render();
expect(screen.queryAllByRole("combobox")).toHaveLength(4);
expect(screen.getByLabelText("Method modeled")).toBeInTheDocument();
expect(screen.queryByLabelText("Loading")).not.toBeInTheDocument();
});
it("renders when there is no modeled method", () => {
render({ modeledMethods: [] });
expect(screen.queryAllByRole("combobox")).toHaveLength(4);
expect(screen.getByLabelText("Method not modeled")).toBeInTheDocument();
expect(screen.queryByLabelText("Loading")).not.toBeInTheDocument();
});
it("can change the kind", async () => {
render();
onChange.mockReset();
expect(screen.getByRole("combobox", { name: "Kind" })).toHaveValue("taint");
await userEvent.selectOptions(
screen.getByRole("combobox", { name: "Kind" }),
"value",
);
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith({
...modeledMethod,
kind: "value",
});
});
it("has the correct input options", () => {
render();
const inputDropdown = screen.getByRole("combobox", { name: "Input" });
expect(inputDropdown).toHaveValue("Argument[0]");
const options = getAllByRole(inputDropdown, "option");
expect(options).toHaveLength(2);
expect(options[0]).toHaveTextContent("Argument[this]");
expect(options[1]).toHaveTextContent("Argument[0]");
});
it("has the correct output options", () => {
render();
const inputDropdown = screen.getByRole("combobox", { name: "Output" });
expect(inputDropdown).toHaveValue("ReturnValue");
const options = getAllByRole(inputDropdown, "option");
expect(options).toHaveLength(3);
expect(options[0]).toHaveTextContent("ReturnValue");
expect(options[1]).toHaveTextContent("Argument[this]");
expect(options[2]).toHaveTextContent("Argument[0]");
});
it("shows the modeling status indicator when unsaved", () => {
render({
methodIsUnsaved: true,
});
expect(
screen.getByLabelText("Changes have not been saved"),
).toBeInTheDocument();
});
it("shows the modeling status indicator when unmodeled", () => {
render({
modeledMethods: [],
});
expect(screen.getByLabelText("Method not modeled")).toBeInTheDocument();
});
it("shows the in progress indicator when in progress", () => {
render({
modelingInProgress: true,
});
expect(screen.getByLabelText("Loading")).toBeInTheDocument();
});
it("can render multiple models", () => {
render({
modeledMethods: [
{ ...modeledMethod, type: "source" },
{ ...modeledMethod, type: "sink" },
{ ...modeledMethod, type: "summary" },
],
viewState: {
...viewState,
showMultipleModels: true,
},
});
const kindInputs = screen.getAllByRole("combobox", { name: "Model type" });
expect(kindInputs).toHaveLength(3);
expect(kindInputs[0]).toHaveValue("source");
expect(kindInputs[1]).toHaveValue("sink");
expect(kindInputs[2]).toHaveValue("summary");
});
it("renders only first model when showMultipleModels feature flag is disabled", () => {
render({
modeledMethods: [
{ ...modeledMethod, type: "source" },
{ ...modeledMethod, type: "sink" },
{ ...modeledMethod, type: "summary" },
],
viewState: {
...viewState,
showMultipleModels: false,
},
});
const kindInputs = screen.getAllByRole("combobox", { name: "Model type" });
expect(kindInputs.length).toBe(1);
expect(kindInputs[0]).toHaveValue("source");
});
it("renders an unmodelable method", () => {
render({
methodCanBeModeled: false,
modeledMethods: [],
});
expect(screen.queryByRole("combobox")).not.toBeInTheDocument();
expect(screen.getByText("Method already modeled")).toBeInTheDocument();
});
});