import { describe, expect, it } from 'vitest'; import { backTo, descend, follow } from '../../src/editor/graph/trail'; const alive = () => true; describe('breadcrumb trail', () => { it('starts at the graph the call was opened from', () => { expect(descend([], 'game', 'move')).toEqual(['game', 'move']); }); it('grows by one per call opened further down', () => { expect(descend(['game', 'move'], 'move', 'other')).toEqual(['game', 'move', 'other']); }); it('starts over when the call sits in a graph the trail does not end at', () => { expect(descend(['game', 'move'], 'jump', 'other')).toEqual(['jump', 'other']); }); it('steps back instead of repeating a behavior already on the trail', () => { expect(descend(['game', 'move', 'other'], 'other', 'move')).toEqual(['game', 'move']); expect(descend(['game', 'move'], 'move', 'game')).toEqual([]); }); it('leaves the trail alone when a behavior calls itself', () => { expect(descend(['game', 'move'], 'move', 'move')).toEqual(['game', 'move']); }); it('cuts back to the crumb clicked, and disappears at the root', () => { const trail = ['game', 'move', 'other']; expect(backTo(trail, 1)).toEqual(['game', 'move']); expect(backTo(trail, 0)).toEqual([]); }); it('survives only while it still leads to the graph shown', () => { const trail = ['game', 'move']; expect(follow(trail, 'move', alive)).toEqual(trail); expect(follow(trail, 'game', alive)).toEqual([]); expect(follow(trail, '', alive)).toEqual([]); }); it('is dropped when a behavior along it was deleted', () => { expect(follow(['game', 'move', 'other'], 'other', (id) => id !== 'move')).toEqual([]); }); });