Skip to content
Snippets Groups Projects
Unverified Commit c1b850ef authored by Emmad Usmani's avatar Emmad Usmani Committed by GitHub
Browse files

handle errors without crashing in SliceNameWidget (#47729)

* handle errors without crashing in SliceNameWidget

* add test
parent 07dd373f
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@ export function SliceNameWidget({
const row = pieRows.find(row => row.key === initialKey);
if (row == null) {
throw Error(`Could not find pieRow with key ${initialKey}`);
return null;
}
return (
......
import { render, screen } from "@testing-library/react";
import { SliceNameWidget } from "./SliceNameWidget";
const MOCK_PIE_ROW = {
key: "some-key",
name: "some-name",
originalName: "some-original-name",
color: "#509EE3",
defaultColor: true,
enabled: true,
hidden: false,
isOther: false,
};
describe("SliceNameWidget", () => {
it("should render the name of the pieRow with initialKey", () => {
render(
<SliceNameWidget
initialKey={MOCK_PIE_ROW.key}
pieRows={[MOCK_PIE_ROW, { ...MOCK_PIE_ROW, key: "some-other-key" }]}
updateRowName={() => null}
/>,
);
expect(screen.getByDisplayValue(MOCK_PIE_ROW.name)).toBeInTheDocument();
});
it("should return null if a pieRow with initialKey cannot be found", () => {
const { container } = render(
<SliceNameWidget
initialKey={"non-present-key"}
pieRows={[MOCK_PIE_ROW]}
updateRowName={() => null}
/>,
);
expect(container).toBeEmptyDOMElement();
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment