Skip to content

Commit 795733b

Browse files
authored
Add tests for link type (#7213)
Quick followup adding tests to #7211 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7213-Add-tests-for-link-type-2c16d73d365081898707f94a40f2e866) by [Unito](https://www.unito.io)
1 parent 1b95cd2 commit 795733b

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

tests-ui/tests/litegraph/core/LGraphNode.test.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import { afterEach, beforeEach, describe, expect, vi } from 'vitest'
22

3-
import type { INodeInputSlot, Point } from '@/lib/litegraph/src/litegraph'
4-
import { LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph'
5-
import { LGraph } from '@/lib/litegraph/src/litegraph'
6-
import { NodeInputSlot } from '@/lib/litegraph/src/litegraph'
7-
import { NodeOutputSlot } from '@/lib/litegraph/src/litegraph'
8-
import type { ISerialisedNode } from '@/lib/litegraph/src/litegraph'
3+
import type {
4+
INodeInputSlot,
5+
Point,
6+
ISerialisedNode
7+
} from '@/lib/litegraph/src/litegraph'
8+
import {
9+
LGraphNode,
10+
LiteGraph,
11+
LGraph,
12+
NodeInputSlot,
13+
NodeOutputSlot
14+
} from '@/lib/litegraph/src/litegraph'
915

1016
import { test } from './fixtures/testExtensions'
1117

@@ -261,6 +267,34 @@ describe('LGraphNode', () => {
261267
})
262268
})
263269

270+
describe('Applies correct link type on connection', () => {
271+
it.for<[string, string, string]>([
272+
['IMAGE', 'IMAGE', 'IMAGE'],
273+
['*', 'IMAGE', 'IMAGE'],
274+
['IMAGE', '*', 'IMAGE'],
275+
['*', '*', '*'],
276+
['IMAGE,MASK', 'IMAGE,LATENT', 'IMAGE'],
277+
//An invalid connection should use input type
278+
['Mask', 'IMAGE', 'IMAGE']
279+
])(
280+
'Link from %s to %s should have type %s',
281+
([output, input, expected]) => {
282+
const target = new LGraphNode('target')
283+
const source = new LGraphNode('source')
284+
const graph = new LGraph()
285+
286+
target.addInput('input', input)
287+
source.addOutput('output', output)
288+
289+
graph.add(source)
290+
graph.add(target)
291+
292+
const link = source.connect(0, target, 0)
293+
expect(link?.type).toBe(expected)
294+
}
295+
)
296+
})
297+
264298
describe('getInputPos and getOutputPos', () => {
265299
test('should handle collapsed nodes correctly', () => {
266300
const node = new LGraphNode('TestNode') as unknown as Omit<

0 commit comments

Comments
 (0)