Merge remote-tracking branch 'origin/temp_screenshot_manual' into feat/experiment-logs
# Conflicts: # src/pages/MonitoringPage/MonitoringPage.tsx
This commit is contained in:
@@ -115,6 +115,89 @@ describe('useProgramStore', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getGoalsWithDepth', () => {
|
||||
const complexProgram: ReducedProgram = {
|
||||
phases: [
|
||||
{
|
||||
id: 'phase-nested',
|
||||
goals: [
|
||||
// Level 0: Root Goal 1
|
||||
{
|
||||
id: 'root-1',
|
||||
name: 'Root Goal 1',
|
||||
plan: {
|
||||
steps: [
|
||||
// This is an ACTION (no plan), should be ignored
|
||||
{ id: 'action-1', type: 'speech' },
|
||||
|
||||
// Level 1: Child Goal
|
||||
{
|
||||
id: 'child-1',
|
||||
name: 'Child Goal',
|
||||
plan: {
|
||||
steps: [
|
||||
// Level 2: Grandchild Goal
|
||||
{
|
||||
id: 'grandchild-1',
|
||||
name: 'Grandchild',
|
||||
plan: { steps: [] } // Empty plan is still a plan
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
// Level 0: Root Goal 2 (Sibling)
|
||||
{
|
||||
id: 'root-2',
|
||||
name: 'Root Goal 2',
|
||||
plan: { steps: [] }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
it('should flatten nested goals and assign correct depth levels', () => {
|
||||
useProgramStore.getState().setProgramState(complexProgram);
|
||||
|
||||
const goals = useProgramStore.getState().getGoalsWithDepth('phase-nested');
|
||||
|
||||
// logic: Root 1 -> Child 1 -> Grandchild 1 -> Root 2
|
||||
expect(goals).toHaveLength(4);
|
||||
|
||||
// Check Root 1
|
||||
expect(goals[0]).toEqual(expect.objectContaining({ id: 'root-1', level: 0 }));
|
||||
|
||||
// Check Child 1
|
||||
expect(goals[1]).toEqual(expect.objectContaining({ id: 'child-1', level: 1 }));
|
||||
|
||||
// Check Grandchild 1
|
||||
expect(goals[2]).toEqual(expect.objectContaining({ id: 'grandchild-1', level: 2 }));
|
||||
|
||||
// Check Root 2
|
||||
expect(goals[3]).toEqual(expect.objectContaining({ id: 'root-2', level: 0 }));
|
||||
});
|
||||
|
||||
it('should ignore steps that are not goals (missing "plan" property)', () => {
|
||||
useProgramStore.getState().setProgramState(complexProgram);
|
||||
const goals = useProgramStore.getState().getGoalsWithDepth('phase-nested');
|
||||
|
||||
// The 'action-1' object should NOT be in the list
|
||||
const action = goals.find(g => g.id === 'action-1');
|
||||
expect(action).toBeUndefined();
|
||||
});
|
||||
|
||||
it('throws if phase does not exist', () => {
|
||||
useProgramStore.getState().setProgramState(complexProgram);
|
||||
|
||||
expect(() =>
|
||||
useProgramStore.getState().getGoalsWithDepth('missing-phase')
|
||||
).toThrow('phase with id:"missing-phase" not found');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the names of all phases in the program', () => {
|
||||
// Define a program specifically with names for this test
|
||||
const programWithNames: ReducedProgram = {
|
||||
|
||||
Reference in New Issue
Block a user