Add more tests covering MethodRow

This commit is contained in:
Robert
2023-10-11 16:29:59 +01:00
parent b881a38703
commit 539ce245fc

View File

@@ -72,6 +72,33 @@ describe(MethodRow.name, () => {
expect(screen.queryByLabelText("Loading")).not.toBeInTheDocument();
});
it("can change the type when there is no modeled method", async () => {
render({ modeledMethods: [] });
onChange.mockReset();
await userEvent.selectOptions(
screen.getByRole("combobox", { name: "Model type" }),
"source",
);
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith(method.signature, [
{
type: "source",
input: "Argument[0]",
output: "ReturnValue",
kind: "value",
provenance: "manual",
signature: method.signature,
packageName: method.packageName,
typeName: method.typeName,
methodName: method.methodName,
methodParameters: method.methodParameters,
},
]);
});
it("can change the kind", async () => {
render();
@@ -182,6 +209,38 @@ describe(MethodRow.name, () => {
expect(kindInputs[0]).toHaveValue("source");
});
it("can update fields when there are multiple models", async () => {
render({
modeledMethods: [
{ ...modeledMethod, type: "source" },
{ ...modeledMethod, type: "sink", kind: "code-injection" },
{ ...modeledMethod, type: "summary" },
],
viewState: {
...viewState,
showMultipleModels: true,
},
});
onChange.mockReset();
expect(screen.getAllByRole("combobox", { name: "Kind" })[1]).toHaveValue(
"code-injection",
);
await userEvent.selectOptions(
screen.getAllByRole("combobox", { name: "Kind" })[1],
"sql-injection",
);
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith(method.signature, [
{ ...modeledMethod, type: "source" },
{ ...modeledMethod, type: "sink", kind: "sql-injection" },
{ ...modeledMethod, type: "summary" },
]);
});
it("renders an unmodelable method", () => {
render({
methodCanBeModeled: false,