From c3acc15e8b231edaa444c02fa7673b645000826f Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Mon, 24 Jun 2024 19:58:46 +1000 Subject: [PATCH] tests(ui): add missing tests for Graph class --- .../nodes/util/graph/generation/Graph.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.test.ts b/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.test.ts index e5a97bb50b..67fabbc158 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.test.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.test.ts @@ -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); + }); + }); + }); });