From 34886cc25adfb73536db40d56770ea87592c3d06 Mon Sep 17 00:00:00 2001 From: "Ziyuan (Jerry) Zhang" Date: Mon, 8 Apr 2024 22:36:22 -0400 Subject: [PATCH] refactoring --- demo/src/App.tsx | 11 +++-------- demo/src/__tests__/MemoryModelsSample.spec.tsx | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/demo/src/App.tsx b/demo/src/App.tsx index 4a5c69e8..4a0c3c4d 100644 --- a/demo/src/App.tsx +++ b/demo/src/App.tsx @@ -19,12 +19,10 @@ export default function App() { const [svgResult, setSvgResult] = useState(null); const [failureBanner, setFailureBanner] = useState(""); - const onSubmit = (event, data) => { - if (event) { - event.preventDefault(); - } + const onTextDataSubmit = (event?) => { + event?.preventDefault(); try { - setJsonResult(JSON.parse(data)); + setJsonResult(JSON.parse(textData)); setFailureBanner(""); } catch (error) { const errorMessage = `Error parsing inputted JSON: ${error.message}`; @@ -33,9 +31,6 @@ export default function App() { setJsonResult(null); } }; - const onTextDataSubmit = (event?) => { - onSubmit(event || null, textData); - }; return ( <> diff --git a/demo/src/__tests__/MemoryModelsSample.spec.tsx b/demo/src/__tests__/MemoryModelsSample.spec.tsx index 6d1516b5..ad773e76 100644 --- a/demo/src/__tests__/MemoryModelsSample.spec.tsx +++ b/demo/src/__tests__/MemoryModelsSample.spec.tsx @@ -53,11 +53,11 @@ describe("MemoryModelsSample", () => { // Wait for state updates and side effects to complete await waitFor(() => { - // expect(onSubmitMock).toHaveBeenCalledWith(); expect(setTextDataMock).toHaveBeenCalledWith( JSON.stringify({ sample: "automation" }, null, 2) ); expect(nextState).toEqual({ config: "config" }); + expect(onSubmitMock).toHaveBeenCalled(); }); }); });