-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
interactive-computational-graph/src/components/AddNodesPanel.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import Operation from "../core/Operation"; | ||
import Port from "../core/Port"; | ||
import { ADD_DFDX_CODE, ADD_F_CODE } from "../features/BuiltInCode"; | ||
import type FeatureNodeType from "../features/FeatureNodeType"; | ||
import type FeatureOperation from "../features/FeatureOperation"; | ||
import AddNodesPanel from "./AddNodesPanel"; | ||
|
||
test("should trigger event when clicking item in view mode", () => { | ||
const featureOperations = getFeatureOperations(); | ||
const handleAddNode = jest.fn(); | ||
const handleAddOperation = jest.fn(); | ||
const handleEditOperation = jest.fn(); | ||
render( | ||
<AddNodesPanel | ||
featureOperations={featureOperations} | ||
onAddNode={handleAddNode} | ||
onAddOperation={handleAddOperation} | ||
onEditOperation={handleEditOperation} | ||
/>, | ||
); | ||
|
||
const addItem = screen.getByText("Add"); | ||
fireEvent.click(addItem); | ||
const expectedNodeType: FeatureNodeType = { | ||
nodeType: "OPERATION", | ||
operationId: "add", | ||
}; | ||
expect(handleAddNode).toHaveBeenCalledWith(expectedNodeType); | ||
}); | ||
|
||
test("should trigger event when clicking add operation button", () => { | ||
const featureOperations = getFeatureOperations(); | ||
const handleAddNode = jest.fn(); | ||
const handleAddOperation = jest.fn(); | ||
const handleEditOperation = jest.fn(); | ||
render( | ||
<AddNodesPanel | ||
featureOperations={featureOperations} | ||
onAddNode={handleAddNode} | ||
onAddOperation={handleAddOperation} | ||
onEditOperation={handleEditOperation} | ||
/>, | ||
); | ||
|
||
const addOperationButton = screen.getByText("Add Operation"); | ||
fireEvent.click(addOperationButton); | ||
expect(handleAddOperation).toHaveBeenCalledWith(); | ||
}); | ||
|
||
test("should trigger event when clicking edit icon button", () => { | ||
const featureOperations = getFeatureOperations(); | ||
const handleAddNode = jest.fn(); | ||
const handleAddOperation = jest.fn(); | ||
const handleEditOperation = jest.fn(); | ||
render( | ||
<AddNodesPanel | ||
featureOperations={featureOperations} | ||
onAddNode={handleAddNode} | ||
onAddOperation={handleAddOperation} | ||
onEditOperation={handleEditOperation} | ||
/>, | ||
); | ||
|
||
const editButton = screen.getByText("Edit"); | ||
fireEvent.click(editButton); | ||
|
||
const editAddButton = screen.getByLabelText("Edit Add"); | ||
fireEvent.click(editAddButton); | ||
|
||
const expectedNodeType: FeatureNodeType = { | ||
nodeType: "OPERATION", | ||
operationId: "add", | ||
}; | ||
expect(handleEditOperation).toHaveBeenCalledWith(expectedNodeType); | ||
}); | ||
|
||
const getFeatureOperations = (): FeatureOperation[] => { | ||
return [ | ||
{ | ||
id: "add", | ||
text: "Add", | ||
type: "SIMPLE", | ||
namePrefix: "a", | ||
operation: new Operation(ADD_F_CODE, ADD_DFDX_CODE), | ||
inputPorts: [new Port("a", false), new Port("b", false)], | ||
helpText: "Add two numbers $ a + b $", | ||
}, | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters