diff --git a/src/pages/VisProgPage/visualProgrammingUI/components/Plan.tsx b/src/pages/VisProgPage/visualProgrammingUI/components/Plan.tsx index 197ca51..3bc2825 100644 --- a/src/pages/VisProgPage/visualProgrammingUI/components/Plan.tsx +++ b/src/pages/VisProgPage/visualProgrammingUI/components/Plan.tsx @@ -1,5 +1,6 @@ -import { GoalReduce } from "../nodes/GoalNode" import { type Node } from "@xyflow/react" +import { GoalReduce } from "../nodes/GoalNode" + export type Plan = { name: string, diff --git a/src/pages/VisProgPage/visualProgrammingUI/components/PlanEditingFunctions.tsx b/src/pages/VisProgPage/visualProgrammingUI/components/PlanEditingFunctions.tsx index 19bf62a..9e7e446 100644 --- a/src/pages/VisProgPage/visualProgrammingUI/components/PlanEditingFunctions.tsx +++ b/src/pages/VisProgPage/visualProgrammingUI/components/PlanEditingFunctions.tsx @@ -27,8 +27,9 @@ export function insertGoalInPlan(plan: Plan, goalNode: GoalNode): Plan { * @param goalID: the goal node to delete. * @returns: a new plan with the goal removed. */ -export function deleteGoalInPlanByID(plan: Plan, goalID: string): Plan { - return {...plan, +export function deleteGoalInPlanByID(plan: Plan, goalID: string) { + const updatedPlan = {...plan, steps: plan.steps.filter((x) => x.id !== goalID) } + return updatedPlan.steps.length == 0 ? undefined : updatedPlan } \ No newline at end of file diff --git a/src/pages/VisProgPage/visualProgrammingUI/nodes/BasicBeliefNode.tsx b/src/pages/VisProgPage/visualProgrammingUI/nodes/BasicBeliefNode.tsx index 0b09b4b..8496d0b 100644 --- a/src/pages/VisProgPage/visualProgrammingUI/nodes/BasicBeliefNode.tsx +++ b/src/pages/VisProgPage/visualProgrammingUI/nodes/BasicBeliefNode.tsx @@ -6,7 +6,7 @@ import { import { Toolbar } from '../components/NodeComponents'; import styles from '../../VisProg.module.css'; import {MultiConnectionHandle} from "../components/RuleBasedHandle.tsx"; -import {allowOnlyConnectionsFromType} from "../HandleRules.ts"; +import {allowOnlyConnectionsFromHandle} from "../HandleRules.ts"; import useFlowStore from '../VisProgStores'; import { TextField } from '../../../../components/TextField'; import { MultilineTextField } from '../../../../components/MultilineTextField'; @@ -185,7 +185,7 @@ export default function BasicBeliefNode(props: NodeProps) { )} diff --git a/src/pages/VisProgPage/visualProgrammingUI/nodes/NormNode.tsx b/src/pages/VisProgPage/visualProgrammingUI/nodes/NormNode.tsx index e216b18..3f9a93c 100644 --- a/src/pages/VisProgPage/visualProgrammingUI/nodes/NormNode.tsx +++ b/src/pages/VisProgPage/visualProgrammingUI/nodes/NormNode.tsx @@ -80,7 +80,7 @@ export default function NormNode(props: NodeProps) { - diff --git a/src/pages/VisProgPage/visualProgrammingUI/nodes/TriggerNode.tsx b/src/pages/VisProgPage/visualProgrammingUI/nodes/TriggerNode.tsx index 0cd5d6d..3ab57cc 100644 --- a/src/pages/VisProgPage/visualProgrammingUI/nodes/TriggerNode.tsx +++ b/src/pages/VisProgPage/visualProgrammingUI/nodes/TriggerNode.tsx @@ -69,7 +69,7 @@ export default function TriggerNode(props: NodeProps) { JSON.parse(JSON.stringify(val))); @@ -468,38 +472,50 @@ describe('PlanEditorDialog', () => { describe('Plan reducing', () => { it('should correctly reduce the plan given the elements of the plan', () => { - const testplan = extendedPlan - const expectedResult = { - id: "extended-plan-1", - steps: [ - { - id: "firststep", - gesture: { - type: "tag", - name: "hello" - } - }, - { - id: "secondstep", - gesture: { - type: "single", - name: "somefolder/somegesture" - } - }, - { - id: "thirdstep", - goal: "ask the user something or whatever" - }, - { - id: "fourthstep", - text: "I'm a cyborg ninja :>" + // Create a plan for testing + const testplan = extendedPlan + const mockGoalNode: Node = { + id: 'goal-1', + type: 'goal', + position: { x: 0, y: 0 }, + data: { ...JSON.parse(JSON.stringify(GoalNodeDefaults)), name: 'mock goal', plan: defaultPlan }, + }; + + // Insert the goal and retrieve its expected data + const newTestPlan = insertGoalInPlan(testplan, mockGoalNode) + const goalReduced = GoalReduce(mockGoalNode, [mockGoalNode]) + const expectedResult = { + id: "extended-plan-1", + steps: [ + { + id: "firststep", + gesture: { + type: "tag", + name: "hello" } - ] - } - - const actualResult = PlanReduce([], testplan) // TODO: FIX THIS TEST :))) - - expect(actualResult).toEqual(expectedResult) + }, + { + id: "secondstep", + gesture: { + type: "single", + name: "somefolder/somegesture" + } + }, + { + id: "thirdstep", + goal: "ask the user something or whatever" + }, + { + id: "fourthstep", + text: "I'm a cyborg ninja :>" + }, + goalReduced, + ] + } + + // Check to see it the goal got added, and its reduced data was added to the goals' + const actualResult = PlanReduce([mockGoalNode], newTestPlan) + expect(actualResult).toEqual(expectedResult) }); }) }); \ No newline at end of file