Files
noodl/packages/noodl-editor/tests/nodegraph/propertyeditor.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

93 lines
2.3 KiB
JavaScript

const { PropertyEditor } = require('@noodl-views/panels/propertyeditor/propertyeditor');
const { NodeGraphNodeRename } = require('@noodl-views/panels/propertyeditor');
const { ProjectModel } = require('@noodl-models/projectmodel');
const NodeLibrary = require('@noodl-models/nodelibrary').NodeLibrary;
const { UndoQueue } = require('@noodl-models/undo-queue-model');
describe('Property editor panel unit tests', function () {
var pe, n, c;
beforeEach(() => {
ProjectModel.instance = ProjectModel.fromJSON(project);
NodeLibrary.instance.registerModule(ProjectModel.instance);
c = ProjectModel.instance.getComponentWithName('Root');
n = c.graph.findNodeWithId('A');
pe = new PropertyEditor({
model: n
});
pe.render();
});
afterEach((done) => {
//some tests schedule renders with a setTimeout
//so schedule one ourselves before we clean up so the console
//isn't filled with errors
setTimeout(() => {
ProjectModel.instance = undefined;
done();
}, 1);
});
it('can delete node and undo', function () {
pe.performDelete();
expect(c.graph.findNodeWithId('A')).toBe(undefined);
expect(c.graph.connections.length).toBe(0);
UndoQueue.instance.undo();
expect(c.graph.findNodeWithId('A')).not.toBe(undefined);
expect(c.graph.connections.length).toBe(1);
});
it('can rename and undo', function () {
NodeGraphNodeRename(n, 'test');
expect(c.graph.findNodeWithId('A').label).toBe('test');
UndoQueue.instance.undo();
expect(c.graph.findNodeWithId('A').label).toBe('group');
});
it('can edit parameter and undo', function () {
pe.portsView.setParameter('alpha', 0.5);
expect(c.graph.findNodeWithId('A').parameters['alpha']).toBe(0.5);
UndoQueue.instance.undo();
expect(c.graph.findNodeWithId('A').parameters['alpha']).toBe(undefined);
});
var project = {
components: [
{
name: 'Root',
graph: {
roots: [
{
id: 'A',
type: 'group'
},
{
id: 'B',
type: 'group'
}
],
connections: [
{
fromId: 'A',
toId: 'B',
fromProperty: 'x',
toProperty: 'y'
}
]
}
}
]
};
});