Files
noodl/packages/noodl-editor/tests/project/projectvalidator.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

48 lines
1.3 KiB
JavaScript

var ProjectValidator = require('@noodl-utils/projectvalidator');
// Project settings
describe('Project validator', function () {
it('can validate missing components', function () {
const proj = {};
const validator = new ProjectValidator();
validator.validate(proj);
expect(validator.hasErrors()).toBe(true);
expect(validator.errors[0].msg).toBe('Project is missing name');
expect(validator.errors[1].msg).toBe('Project is missing components');
});
it('can validate dangling connections and fix', function () {
const proj = {
name: 'C',
components: [
{
name: 'A',
graph: {
roots: [],
connections: [
{
fromId: 'a',
fromProperty: 'hej',
toId: 'b',
toProperty: 'hej'
}
]
}
}
]
};
const validator = new ProjectValidator();
validator.validate(proj);
expect(validator.hasErrors()).toBe(true);
expect(validator.errors[0].msg).toBe('Dangling connection at A missing source missing target ');
validator.fix();
validator.clearErrors();
validator.validate(proj);
expect(validator.hasErrors()).toBe(false);
expect(proj.components[0].graph.connections.length).toBe(0);
});
});