mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
tests(ui): coverage for getCollectItemType
This commit is contained in:
parent
b1e28c2f2c
commit
4bda174eb9
@ -1,21 +1,44 @@
|
|||||||
|
import { deepClone } from 'common/util/deepClone';
|
||||||
import { getCollectItemType } from 'features/nodes/store/util/getCollectItemType';
|
import { getCollectItemType } from 'features/nodes/store/util/getCollectItemType';
|
||||||
import { add, buildEdge, buildNode, collect, templates } from 'features/nodes/store/util/testUtils';
|
import { add, buildEdge, buildNode, collect, templates } from 'features/nodes/store/util/testUtils';
|
||||||
import type { FieldType } from 'features/nodes/types/field';
|
import type { FieldType } from 'features/nodes/types/field';
|
||||||
|
import { unset } from 'lodash-es';
|
||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
describe(getCollectItemType.name, () => {
|
describe(getCollectItemType.name, () => {
|
||||||
it('should return the type of the items the collect node collects', () => {
|
it('should return the type of the items the collect node collects', () => {
|
||||||
const n1 = buildNode(add);
|
const n1 = buildNode(add);
|
||||||
const n2 = buildNode(collect);
|
const n2 = buildNode(collect);
|
||||||
const nodes = [n1, n2];
|
const e1 = buildEdge(n1.id, 'value', n2.id, 'item');
|
||||||
const edges = [buildEdge(n1.id, 'value', n2.id, 'item')];
|
const result = getCollectItemType(templates, [n1, n2], [e1], n2.id);
|
||||||
const result = getCollectItemType(templates, nodes, edges, n2.id);
|
|
||||||
expect(result).toEqual<FieldType>({ name: 'IntegerField', isCollection: false, isCollectionOrScalar: false });
|
expect(result).toEqual<FieldType>({ name: 'IntegerField', isCollection: false, isCollectionOrScalar: false });
|
||||||
});
|
});
|
||||||
it('should return null if the collect node does not have any connections', () => {
|
it('should return null if the collect node does not have any connections', () => {
|
||||||
const n1 = buildNode(collect);
|
const n1 = buildNode(collect);
|
||||||
const nodes = [n1];
|
const result = getCollectItemType(templates, [n1], [], n1.id);
|
||||||
const result = getCollectItemType(templates, nodes, [], n1.id);
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
it("should return null if the first edge to collect's node doesn't exist", () => {
|
||||||
|
const n1 = buildNode(collect);
|
||||||
|
const n2 = buildNode(add);
|
||||||
|
const e1 = buildEdge(n2.id, 'value', n1.id, 'item');
|
||||||
|
const result = getCollectItemType(templates, [n1], [e1], n1.id);
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
it("should return null if the first edge to collect's node template doesn't exist", () => {
|
||||||
|
const n1 = buildNode(collect);
|
||||||
|
const n2 = buildNode(add);
|
||||||
|
const e1 = buildEdge(n2.id, 'value', n1.id, 'item');
|
||||||
|
const result = getCollectItemType({ collect }, [n1, n2], [e1], n1.id);
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
it("should return null if the first edge to the collect's field template doesn't exist", () => {
|
||||||
|
const n1 = buildNode(collect);
|
||||||
|
const n2 = buildNode(add);
|
||||||
|
const addWithoutOutputValue = deepClone(add);
|
||||||
|
unset(addWithoutOutputValue, 'outputs.value');
|
||||||
|
const e1 = buildEdge(n2.id, 'value', n1.id, 'item');
|
||||||
|
const result = getCollectItemType({ add: addWithoutOutputValue, collect }, [n2, n1], [e1], n1.id);
|
||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -30,6 +30,9 @@ export const getCollectItemType = (
|
|||||||
if (!template) {
|
if (!template) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const fieldType = template.outputs[firstEdgeToCollect.sourceHandle]?.type ?? null;
|
const fieldTemplate = template.outputs[firstEdgeToCollect.sourceHandle];
|
||||||
return fieldType;
|
if (!fieldTemplate) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return fieldTemplate.type;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user