Merge pull request #2969 from github/koesie10/fix-unmodeled-unsaved

Fix unmodeled methods always being marked as unsaved
This commit is contained in:
Koen Vlaswinkel
2023-10-16 15:07:18 +02:00
committed by GitHub
2 changed files with 45 additions and 5 deletions

View File

@@ -62,12 +62,11 @@ export const ModelKindDropdown = ({
);
useEffect(() => {
const value = modeledMethod?.kind;
if (value === undefined && kinds.length > 0) {
onChangeKind(kinds[0]);
}
const value = modeledMethod?.kind ?? "";
if (value !== undefined && !kinds.includes(value)) {
if (kinds.length === 0 && value !== "") {
onChangeKind("");
} else if (kinds.length > 0 && !kinds.includes(value)) {
onChangeKind(kinds[0]);
}
}, [modeledMethod?.kind, kinds, onChangeKind]);

View File

@@ -92,4 +92,45 @@ describe(ModelKindDropdown.name, () => {
}),
);
});
it("does not call onChange when unmodeled and the kind is valid", () => {
const method = createMethod();
const modeledMethod = createModeledMethod({
type: "none",
kind: "",
});
render(
<ModelKindDropdown
method={method}
modeledMethod={modeledMethod}
onChange={onChange}
/>,
);
expect(onChange).not.toHaveBeenCalled();
});
it("calls onChange when unmodeled and the kind is valid", () => {
const method = createMethod();
const modeledMethod = createModeledMethod({
type: "none",
kind: "local",
});
render(
<ModelKindDropdown
method={method}
modeledMethod={modeledMethod}
onChange={onChange}
/>,
);
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith(
expect.objectContaining({
kind: "",
}),
);
});
});