lincd
Version:
LINCD is a JavaScript library for building user interfaces with linked data (also known as 'structured data', or RDF)
48 lines • 2.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const globals_1 = require("@jest/globals");
const models_1 = require("../models");
const Shape_1 = require("../shapes/Shape");
class Person extends Shape_1.Shape {
get knows() {
return this.getAllAs(knows, Person);
}
}
let personNode1 = models_1.NamedNode.create();
let personNode2 = models_1.NamedNode.create();
let personNode3 = models_1.NamedNode.create();
let person1 = new Person(personNode1);
let person2 = new Person(personNode2);
let person3 = new Person(personNode3);
let knows = models_1.NamedNode.create();
personNode1.set(knows, personNode2);
(0, globals_1.describe)('shape value set', () => {
(0, globals_1.test)('reflects current amount of properties', () => {
(0, globals_1.expect)(person1.knows.size).toBe(1);
});
(0, globals_1.test)('matches shapes of the same node', () => {
//ShapeValueSets make their own instances of shapes which may not be the same instance
// as another instance of the same shape for the same node
//in this case, person2 will not exist in the set by true identity, but an equivalent shape DOES exist in the set
//so this should return true. See ShapeSet.has tests and implementation
(0, globals_1.expect)(person1.knows.has(person2)).toBe(true);
});
(0, globals_1.test)('adds nodes to the graph when you add a new shape to them', () => {
//first we add and get the size of THAT set
(0, globals_1.expect)(person1.knows.add(person3).size).toBe(2);
//then we get the set again (will be a new one with new shapes) and check the size
(0, globals_1.expect)(person1.knows.size).toBe(2);
//then we check the actual graph
(0, globals_1.expect)(personNode1.getAll(knows).size).toBe(2);
//the same instance can be expected to be there if you directly added it
(0, globals_1.expect)(person1.knows.has(person3)).toBe(true);
});
(0, globals_1.test)('remove nodes to the graph when you delete a shape from them', () => {
person1.knows.delete(person3);
(0, globals_1.expect)(person1.knows.size).toBe(1);
(0, globals_1.expect)(personNode1.getAll(knows).size).toBe(1);
//should not occur in the set anymore
(0, globals_1.expect)(person1.knows.has(person3)).toBe(false);
});
});
//# sourceMappingURL=shapevaluesset.test.js.map