Files
noodl/packages/noodl-editor/tests/nodegraph/hierarchy.js
Michael Cartner b9c60b07dc Initial commit
Co-Authored-By: Eric Tuvesson <eric.tuvesson@gmail.com>
Co-Authored-By: mikaeltellhed <2311083+mikaeltellhed@users.noreply.github.com>
Co-Authored-By: kotte <14197736+mrtamagotchi@users.noreply.github.com>
Co-Authored-By: Anders Larsson <64838990+anders-topp@users.noreply.github.com>
Co-Authored-By: Johan  <4934465+joolsus@users.noreply.github.com>
Co-Authored-By: Tore Knudsen <18231882+torekndsn@users.noreply.github.com>
Co-Authored-By: victoratndl <99176179+victoratndl@users.noreply.github.com>
2024-01-26 11:52:55 +01:00

118 lines
2.8 KiB
JavaScript

const NodeLibrary = require('@noodl-models/nodelibrary').NodeLibrary;
const NodeGraphNode = require('@noodl-models/nodegraphmodel').NodeGraphNode;
const { ComponentModel } = require('@noodl-models/componentmodel');
describe('Component instances', function () {
var c;
beforeEach(() => {
window.NodeLibraryData = require('../nodegraph/nodelibrary');
NodeLibrary.instance.loadLibrary();
c = ComponentModel.fromJSON({
name: 'test',
graph: {
roots: [
{
type: 'group',
id: 'Group-1'
}
]
}
});
});
it('can load component', function () {
expect(c).not.toBe(undefined);
});
it('can detect children that can be attached', function () {
const n1 = NodeGraphNode.fromJSON({
type: 'image'
});
const n2 = NodeGraphNode.fromJSON({
type: 'animation'
});
const n3 = NodeGraphNode.fromJSON({
type: 'scaleModifier'
});
const n4 = NodeGraphNode.fromJSON({
type: 'image'
});
// Can accept an image
expect(c.graph.findNodeWithId('Group-1').canAcceptChildren([n1])).toBe(true);
// Not all nodes can be children
expect(c.graph.findNodeWithId('Group-1').canAcceptChildren([n1, n2])).toBe(false);
// Not all nodes have accepted categories
expect(c.graph.findNodeWithId('Group-1').canAcceptChildren([n1, n3])).toBe(false);
// Multiple nodes with same category should be OK
expect(c.graph.findNodeWithId('Group-1').canAcceptChildren([n1, n4])).toBe(true);
});
it('can report allow as child for components', function () {
var c2 = ComponentModel.fromJSON({
name: 'test',
graph: {}
});
// No root nodes that can be children
expect(c2.allowAsChild).toBe(false);
c2.graph.addRoot(
NodeGraphNode.fromJSON({
type: 'group'
})
);
// Group can be child
expect(c2.allowAsChild).toBe(true);
// Report correct category
expect(c2.category).toBe('visuals');
});
it('can report accepted children for components', function () {
expect(c.allowChildrenWithCategory).toBe(undefined);
c.graph.addRoot(
NodeGraphNode.fromJSON({
type: 'Component Children'
})
);
expect(c.allowChildrenWithCategory).toEqual(['visuals']);
c.graph.addRoot(
NodeGraphNode.fromJSON({
type: 'Component Modifier Children'
})
);
expect(c.allowChildrenWithCategory).toEqual(['modifiers', 'visuals']);
});
it('can detect allow export root', function () {
var c2 = ComponentModel.fromJSON({
name: 'test',
graph: {}
});
expect(c2.allowAsExportRoot).toBe(false);
c2.graph.addRoot(
NodeGraphNode.fromJSON({
type: 'group'
})
);
expect(c2.allowAsExportRoot).toBe(true);
});
});