123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- const graph_state_1 = require("./graph_state");
- const test_helpers_1 = require("./util/test_helpers");
- const delta_registry_1 = require("./delta_registry");
- const delta_1 = require("./delta");
- const assert_1 = require("./util/assert");
- class MyGraphStateListener {
- createNode(ns) {
- console.log("created node", ns);
- }
- createValue(vs) {
- console.log("created value", vs);
- }
- deleteNode(id) {
- console.log("deleted node", id);
- }
- deleteValue(value) {
- console.log("deleted value", value);
- }
- createLinkToNode(sourceId, label, targetId) {
- console.log("created link to node", sourceId, label, targetId);
- }
- createLinkToValue(sourceId, label, targetValue) {
- console.log("created link to value", sourceId, label, targetValue);
- }
- deleteLink(sourceId, label) {
- console.log("deleted link", sourceId, label);
- }
- }
- describe("GraphState", () => {
- // need to test more scenarios!
- // taken from primitive delta test:
- it("Delete node with self-edge", () => {
- const graphState = new graph_state_1.GraphState();
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- function newTransaction(deltas, description) {
- return registry.newTransaction(deltas, description, (0, delta_1.findTxDependencies)(deltas, graphState.deltas));
- }
- const myListener = new MyGraphStateListener();
- // Better not to create these primitive deltas by hand (is hard!). Instead, use 'getDeltasForSetEdge' and 'getDeltasForDelete' (see below).
- // const edgeCreation = registry.newEdgeUpdate(nodeCreation.createOutgoingEdge("label"), nodeCreation);
- // const edgeUpdate = registry.newEdgeUpdate(edgeCreation, null);
- // const nodeDeletion = registry.newNodeDeletion(nodeCreation, [edgeUpdate], [edgeUpdate]);
- (0, assert_1.assert)(graphState.nodes.size === 0, "Expected no nodes initially");
- const nodeId = getId();
- const nodeCreation = registry.newNodeCreation(nodeId);
- const comp0 = newTransaction([nodeCreation], "node creation");
- graphState.exec(comp0, myListener);
- (0, assert_1.assert)(graphState.nodes.size === 1, "Expected one node after NodeCreation");
- const nodeState = graphState.nodes.get(nodeId);
- const deltaForSetEdge = nodeState.getDeltaForSetEdge(registry, "x", 42);
- const comp1 = newTransaction([deltaForSetEdge], "set edge x == 42");
- graphState.exec(comp1, myListener);
- (0, assert_1.assert)(graphState.nodes.get(nodeId).outgoingDeltas.get("x") !== undefined, "Expected outgoing edge 'x' for node " + nodeId);
- (0, assert_1.assert)(graphState.nodes.get(nodeId).outgoing.get("x").value === 42, "Expected value of outgoing edge 'x' to be 42");
- const deltasForDelete = nodeState.getDeltasForDelete(registry);
- console.log({ deltasForDelete });
- const comp2 = newTransaction(deltasForDelete, "delete node (and edge)");
- graphState.exec(comp2, myListener);
- console.log(nodeState.outgoing.get("x"));
- // assert(nodeState!.outgoing.get("x") === null, "Exepected no outgoing edge 'x'");
- graphState.unexec(comp2, myListener);
- // assert((graphState.nodes.get(nodeId)!.outgoing.get("x") as IValueState).value === 42, "Expected value of outgoing edge 'x' to be 42");
- // assert(graphState.nodes.size === 0, "Expected no more nodes in graphState");
- // // graphState.exec(edgeCreation);
- // assert(graphState.nodes.size === 1, "Expected one node after EdgeCreation");
- // // assert(graphState.edges.length === 1, "Expected one edge after EdgeCreation");
- // graphState.exec(edgeUpdate);
- // assert(graphState.nodes.size === 1, "Expected one node after EdgeUpdate");
- // // assert(graphState.edges.length === 0, "Expected no edges after EdgeUpdate");
- // graphState.exec(nodeDeletion);
- // assert(graphState.nodes.size === 0, "Expected no nodes after NodeDeletion");
- // // assert(graphState.edges.length === 0, "Expected no edges after NodeDeletion");
- });
- });
- //# sourceMappingURL=graph_state.test.js.map
|