|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { Graph } from '../Graph.js'; |
| 3 | +import { findNodes } from './findNodes.js'; |
| 4 | +import { getFirstNode } from './getFirstNode.js'; |
| 5 | +import { getNode } from './getNode.js'; |
| 6 | + |
| 7 | +describe('findNodes', () => { |
| 8 | + type Node = { id: string; type: string }; |
| 9 | + |
| 10 | + it('should retrieve a node successfully when it exists in the graph', ({ expect }) => { |
| 11 | + const graph = new Graph<Node>(); |
| 12 | + const node1 = { id: '1', type: 'foo' }; |
| 13 | + const node2 = { id: '2', type: 'foo' }; |
| 14 | + |
| 15 | + graph.addNode(node1); |
| 16 | + graph.addNode(node2); |
| 17 | + |
| 18 | + expect(findNodes(graph, (n) => n.id === '1')).toEqual([node1]); |
| 19 | + expect(findNodes(graph, (n) => n.id === '2')).toEqual([node2]); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should return an empty array when no matching node is found', ({ expect }) => { |
| 23 | + const graph = new Graph<Node>(); |
| 24 | + expect(findNodes(graph, (n) => n.id === 'nope')).toEqual([]); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should return all the nodes matching', ({ expect }) => { |
| 28 | + const graph = new Graph<Node>(); |
| 29 | + const node1 = { id: '1', type: 'foo' }; |
| 30 | + const node2 = { id: '2', type: 'foo' }; |
| 31 | + |
| 32 | + graph.addNode(node1); |
| 33 | + graph.addNode(node2); |
| 34 | + |
| 35 | + expect(findNodes(graph, (n) => n.type === 'foo')).toEqual([node1, node2]); |
| 36 | + }); |
| 37 | +}); |
0 commit comments