tests(ui): add missing tests for Graph class

This commit is contained in:
psychedelicious 2024-06-24 19:58:46 +10:00
parent 1b653278fc
commit c3acc15e8b

View File

@ -3,6 +3,7 @@ import type { AnyInvocation, Invocation } from 'services/api/types';
import { assert, AssertionError, is } from 'tsafe';
import { validate } from 'uuid';
import { describe, expect, it } from 'vitest';
import { z } from 'zod';
describe('Graph', () => {
describe('constructor', () => {
@ -591,4 +592,31 @@ describe('Graph', () => {
});
});
});
describe('other utils', () => {
describe('edgeToString', () => {
it('should return a string representation of the edge given the edge fields', () => {
expect(Graph.edgeToString('from-node', 'value', 'to-node', 'b')).toBe('from-node.value -> to-node.b');
});
it('should return a string representation of the edge given an edge object', () => {
expect(
Graph.edgeToString({
source: { node_id: 'from-node', field: 'value' },
destination: { node_id: 'to-node', field: 'b' },
})
).toBe('from-node.value -> to-node.b');
});
});
describe('getId', () => {
it('should create a new uuid v4 id', () => {
const id = Graph.getId();
expect(() => z.string().uuid().parse(id)).not.toThrow();
});
it('should prepend the prefix if provided', () => {
const id = Graph.getId('prefix');
expect(id.startsWith('prefix_')).toBe(true);
});
});
});
});