Skip to content

Commit

Permalink
Now with working tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thebestnom committed May 17, 2023
1 parent 4d1b34b commit 93ec784
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 19 deletions.
61 changes: 48 additions & 13 deletions __tests__/neovis.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Neovis', () => {
const label1 = 'label1';
const label2 = 'label2';
const relationshipType = 'TEST';
let neovis: NeoVis;
let neovis: NeoVis;

beforeEach(() => Neo4jMock.clearAllMocks());
beforeEach(() => {
Expand Down Expand Up @@ -543,35 +543,70 @@ describe('Neovis', () => {
});
});
const retData = [new Neo4j.types.Record(
["a", "b", "c", "d"]
, [

], {"a": 0, "b": 1, "c": 2, "d": 3})].map(rec => rec.toObject());
describe.each([['Sync Iterable', {
['a', 'b', 'c', 'd'], [
new Neo4j.types.Node(new Neo4j.types.Integer(0, 0), ['Test'], { test: 1, test2: new Neo4j.types.Integer(1, 0) }),
new Neo4j.types.Node(new Neo4j.types.Integer(1, 0), ['Test'], {}),
new Neo4j.types.Relationship(new Neo4j.types.Integer(0, 0), new Neo4j.types.Integer(0, 0), new Neo4j.types.Integer(1, 0), 'TEST', {}),
new Neo4j.types.Path(
new Neo4j.types.Node(new Neo4j.types.Integer(2, 0), ['Test'], {}),
new Neo4j.types.Node(new Neo4j.types.Integer(3, 0), ['Test'], {}), [
new Neo4j.types.PathSegment(
new Neo4j.types.Node(new Neo4j.types.Integer(2, 0), ['Test'], {}),
new Neo4j.types.Relationship(new Neo4j.types.Integer(1, 0), new Neo4j.types.Integer(3, 0), new Neo4j.types.Integer(1, 0), 'TEST', {}),
new Neo4j.types.Node(new Neo4j.types.Integer(3, 0), ['Test'], {})
)]
)
], { 'a': 0, 'b': 1, 'c': 2, 'd': 3 })
].map(rec => JSON.parse(JSON.stringify(rec)));
const dataFunctionSharedConfig: Partial<NeovisConfig> = {
containerId,
labels: {
Test: {
value: 'test',
label: 'test2'
}
}
};
describe.each([['Sync Iterable', {
...dataFunctionSharedConfig,
dataFunction() {
return retData
return retData;
},
} as Partial<NeovisConfig>], ['Sync Generator', {
containerId,
...dataFunctionSharedConfig,
*dataFunction() {
for(const record of retData) {
yield record
for (const record of retData) {
yield record;
}
},
} as Partial<NonFlatNeovisConfig>], ['Async Iterable', {
containerId,
...dataFunctionSharedConfig,
async dataFunction() {
return retData;
},
} as Partial<NonFlatNeovisConfig>], ['ASync Generator', {
containerId,
...dataFunctionSharedConfig,
async *dataFunction() {
for(const record of retData) {
for (const record of retData) {
yield record;
}
},
} as Partial<NonFlatNeovisConfig>]])('neovis dataFunction %s test', (configName: string, config) => {
beforeEach(() => {
neovis = new Neovis(config as NonFlatNeovisConfig | NeovisConfig);
});
// TODO TESTS
it('should create all nodes and relationship same if it was normal', async () => {
neovis.render();
await testUtils.neovisRenderDonePromise(neovis);
expect(neovis.nodes.length).toBe(4);
expect(neovis.edges.length).toBe(2);
expect(neovis.nodes.get(0)?.value).toBe(1);
});
it('should desriallize int correctly in properties', async () => {
neovis.render();
await testUtils.neovisRenderDonePromise(neovis);
expect(neovis.nodes.get(0)?.label).toBe(1);
});
});
});
15 changes: 9 additions & 6 deletions __tests__/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ export function clearIdCounter(): void {
counter = 1;
}

export function makeNode(labels: string[], properties: unknown = {}): Neo4jCore.Node<number> {
export function makeNode(labels: string[], properties: Record<string, unknown> = {}): Neo4jCore.Node<number> {
return new Neo4jCore.Node(counter++, labels, properties);
}

export function makeRelationship(type: string, startNode: Neo4jCore.Node<number>, endNode: Neo4jCore.Node<number>, properties: unknown = {}): Neo4jCore.Relationship<number> {
export function makeRelationship(type: string, startNode: Neo4jCore.Node<number>, endNode: Neo4jCore.Node<number>, properties: Record<string, unknown> = {}): Neo4jCore.Relationship<number> {
return new Neo4jCore.Relationship(counter++, startNode.identity, endNode.identity, type, properties);
}

export function makePathFromNodes(nodes: Neo4jType.Node<number>[], relationshipType: string): Neo4jCore.Path<number> {
const pathSegments = [];
const pathSegments: Neo4jCore.PathSegment<number>[] = [];
for (let i = 0; i < nodes.length - 1; i++) {
pathSegments.push(new Neo4jCore.PathSegment(
nodes[i],
Expand Down Expand Up @@ -64,7 +64,7 @@ export function mockNormalRunSubscribe(records: Neo4jType.Record<{ [key: string]
records.forEach(onNext);
onCompleted();
};
return observablePromise as ObservablePromise<{ records: Neo4jType.Record<unknown>[] }>;
return observablePromise as ObservablePromise<{ records: Neo4jType.Record<Record<string, unknown>>[] }>;
});
}

Expand All @@ -82,11 +82,14 @@ export function mockFullRunSubscribe(cypherIdsAndAnswers: Record<string, { defau
records.forEach(onNext);
onCompleted();
};
return observablePromise as ObservablePromise<{ records: Neo4jType.Record<unknown>[] }>;
return observablePromise as ObservablePromise<{ records: Neo4jType.Record<Record<string, unknown>>[] }>;
});
}


export function neovisRenderDonePromise(neovis: NeoVis): Promise<Parameters<EventFunctionTypes[NeoVisEvents.CompletionEvent]>[0]> {
return new Promise(res => neovis.registerOnEvent(NeoVisEvents.CompletionEvent, res));
return new Promise((res, rej) => {
neovis.registerOnEvent(NeoVisEvents.CompletionEvent, res);
neovis.registerOnEvent(NeoVisEvents.ErrorEvent, rej);
});
}

0 comments on commit 93ec784

Please sign in to comment.