Skip to content

Commit

Permalink
Finish tests and deserialize all types
Browse files Browse the repository at this point in the history
  • Loading branch information
thebestnom committed May 17, 2023
1 parent 0075505 commit 0e202b1
Show file tree
Hide file tree
Showing 44 changed files with 297 additions and 195 deletions.
46 changes: 43 additions & 3 deletions __tests__/neovis.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ describe('Neovis', () => {
expect(neovis.edges.length).toBe(1);
});

it('should work with big int', async () => {
testUtils.mockNormalRunSubscribe([
testUtils.makeRecord([testUtils.makePathFromNodes([
testUtils.makeNode([label1], {}, new Neo4j.types.Integer(0, 1)),
testUtils.makeNode([label1], {}, new Neo4j.types.Integer(1, 1))
], relationshipType)]),
]);
neovis.render();
await testUtils.neovisRenderDonePromise(neovis);
expect(neovis.nodes.length).toBe(2);
expect(neovis.edges.length).toBe(1);
expect(neovis.nodes.getIds()).toEqual(['4294967296', '4294967297']);
});

it('should save record with multiple parameters', async () => {
const firstNode = testUtils.makeNode([label1]);
const secondNode = testUtils.makeNode([label1]);
Expand Down Expand Up @@ -238,7 +252,7 @@ describe('Neovis', () => {
default: [testUtils.makeRecord([node])]
},
[sizeCypher]: {
[node.identity]: [testUtils.makeRecord([Neo4j.int(1)])]
[typeof node.identity === 'object' ? node.identity.toInt(): node.identity]: [testUtils.makeRecord([Neo4j.int(1)])]
}
});

Expand Down Expand Up @@ -500,7 +514,7 @@ describe('Neovis', () => {
default: [testUtils.makeRecord([node1])]
},
[sizeCypher]: {
[node1.identity]: [testUtils.makeRecord([intPropertyValue])]
[typeof node1.identity === 'object' ? node1.identity.toInt(): node1.identity]: [testUtils.makeRecord([intPropertyValue])]
}
});
neovis.render();
Expand Down Expand Up @@ -545,7 +559,17 @@ describe('Neovis', () => {
const retData = [new Neo4j.types.Record(
['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.Node(new Neo4j.types.Integer(1, 0), ['Test'], {
test1: new Neo4j.types.Date(new Neo4j.types.Integer(1, 0), new Neo4j.types.Integer(1, 0), new Neo4j.types.Integer(1, 0)),
test2: new Neo4j.types.DateTime(1, 2, 3, 4, 5, 6, 7, 8),
test3: new Neo4j.types.DateTime(1, 2, 3, 4, 5, 6, 7, 8, 'US/Pacific'),
test4: new Neo4j.types.Duration(1, 2, 3, 5),
test5: new Neo4j.types.LocalDateTime(1, 2, 3, 4, 5, 6, 7),
test6: new Neo4j.types.LocalTime(1, 2, 3, 4),
test7: new Neo4j.types.Point(1, 2, 3, 4),
test8: new Neo4j.types.Point(1, 2, 3),
test9: new Neo4j.types.Time(1, 2, 3, 4, 5)
}),
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'], {}),
Expand Down Expand Up @@ -608,5 +632,21 @@ describe('Neovis', () => {
await testUtils.neovisRenderDonePromise(neovis);
expect(neovis.nodes.get(0)?.label).toBe(1);
});
it('should desriallize all neo4j types', async () => {
neovis.render();
await testUtils.neovisRenderDonePromise(neovis);
expect(neovis.nodes.get(1)?.raw.properties.test1).toBeInstanceOf(Neo4j.types.Date);
expect((neovis.nodes.get(1)?.raw.properties.test1 as any).year).toBeInstanceOf(Neo4j.types.Integer);
expect((neovis.nodes.get(1)?.raw.properties.test1 as any).month).toBeInstanceOf(Neo4j.types.Integer);
expect((neovis.nodes.get(1)?.raw.properties.test1 as any).day).toBeInstanceOf(Neo4j.types.Integer);
expect(neovis.nodes.get(1)?.raw.properties.test2).toBeInstanceOf(Neo4j.types.DateTime);
expect(neovis.nodes.get(1)?.raw.properties.test3).toBeInstanceOf(Neo4j.types.DateTime);
expect(neovis.nodes.get(1)?.raw.properties.test4).toBeInstanceOf(Neo4j.types.Duration);
expect(neovis.nodes.get(1)?.raw.properties.test5).toBeInstanceOf(Neo4j.types.LocalDateTime);
expect(neovis.nodes.get(1)?.raw.properties.test6).toBeInstanceOf(Neo4j.types.LocalTime);
expect(neovis.nodes.get(1)?.raw.properties.test7).toBeInstanceOf(Neo4j.types.Point);
expect(neovis.nodes.get(1)?.raw.properties.test8).toBeInstanceOf(Neo4j.types.Point);
expect(neovis.nodes.get(1)?.raw.properties.test9).toBeInstanceOf(Neo4j.types.Time);
});
});
});
10 changes: 5 additions & 5 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: Record<string, unknown> = {}): Neo4jCore.Node<number> {
return new Neo4jCore.Node(counter++, labels, properties);
export function makeNode(labels: string[], properties: Record<string, unknown> = {}, id?: Neo4jCore.Integer | number): Neo4jCore.Node<Neo4jCore.Integer | number> {
return new Neo4jCore.Node(id ?? new Neo4jCore.Integer(counter++, 0), labels, properties);
}

export function makeRelationship(type: string, startNode: Neo4jCore.Node<number>, endNode: Neo4jCore.Node<number>, properties: Record<string, unknown> = {}): Neo4jCore.Relationship<number> {
export function makeRelationship(type: string, startNode: Neo4jCore.Node<number | Neo4jCore.Integer>, endNode: Neo4jCore.Node<number | Neo4jCore.Integer>, properties: Record<string, unknown> = {}): Neo4jCore.Relationship<number | Neo4jCore.Integer> {
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: Neo4jCore.PathSegment<number>[] = [];
export function makePathFromNodes(nodes: Neo4jType.Node<number | Neo4jCore.Integer>[], relationshipType: string): Neo4jCore.Path<number | Neo4jCore.Integer> {
const pathSegments: Neo4jCore.PathSegment<number | Neo4jCore.Integer>[] = [];
for (let i = 0; i < nodes.length - 1; i++) {
pathSegments.push(new Neo4jCore.PathSegment(
nodes[i],
Expand Down
1 change: 0 additions & 1 deletion dist/main.map2489d4e85c450ccb9a89

This file was deleted.

1 change: 1 addition & 0 deletions dist/main.map3b1a796034f11ac32d28

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/neovis-without-dependencies.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/neovis.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export declare class NeoVis {
/**
* Renders the network
*/
render(query?: Cypher, parameters?: any): void;
render(query?: Cypher, parameters?: unknown): void;
/**
* Clear the data for the visualization
*/
Expand Down
4 changes: 2 additions & 2 deletions dist/neovis.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions dist/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export interface BaseNeovisConfig {
* function to get the data instead of neo4j driver
* @returns list of neo4j data
*/
dataFunction?: (any?: any) => AsyncIterable<Neo4jTypes.Record> | Promise<Iterable<Neo4jTypes.Record>>;
dataFunction?: (any?: unknown) => AsyncIterable<Neo4jTypes.Record> | Promise<Iterable<Neo4jTypes.Record>> | Iterable<Neo4jTypes.Record>;
/**
* The Cypher query that will get the data
*/
Expand Down Expand Up @@ -321,7 +321,6 @@ export interface Node extends VisNetwork.Node {
/**
* @link https://neo4j.com/docs/api/javascript-driver/current/class/src/graph-types.js~Node.html
*/
id: number;
raw: Neo4jTypes.Node<NumberOrInteger>;
}
/**
Expand All @@ -331,6 +330,6 @@ export interface Edge extends VisNetwork.Edge {
/**
* https://neo4j.com/docs/api/javascript-driver/current/class/src/graph-types.js~Relationship.html
*/
id: number;
id: number | string;
raw: Neo4jTypes.Relationship<NumberOrInteger>;
}
2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/classes/EventController.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h4>Hierarchy</h4>
<ul class="tsd-hierarchy">
<li><span class="target">EventController</span></li></ul></section><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/neo4j-contrib/neovis.js/blob/902ea8d/src/events.ts#L17">src/events.ts:17</a></li></ul></aside>
<li>Defined in <a href="https://github.com/neo4j-contrib/neovis.js/blob/28524f3/src/events.ts#L17">src/events.ts:17</a></li></ul></aside>
<section class="tsd-panel-group tsd-index-group">
<section class="tsd-panel tsd-index-panel">
<details class="tsd-index-content tsd-index-accordion" open><summary class="tsd-accordion-summary tsd-index-summary">
Expand All @@ -44,7 +44,7 @@ <h3 class="tsd-anchor-link"><span>constructor</span><a href="#constructor" aria-
<li class="tsd-description">
<h4 class="tsd-returns-title">Returns <a href="EventController.html" class="tsd-signature-type tsd-kind-class">EventController</a></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/neo4j-contrib/neovis.js/blob/902ea8d/src/events.ts#L20">src/events.ts:20</a></li></ul></aside></li></ul></section></section>
<li>Defined in <a href="https://github.com/neo4j-contrib/neovis.js/blob/28524f3/src/events.ts#L20">src/events.ts:20</a></li></ul></aside></li></ul></section></section>
<section class="tsd-panel-group tsd-member-group">
<h2>Methods</h2>
<section class="tsd-panel tsd-member"><a id="generateEvent" class="tsd-anchor"></a>
Expand All @@ -70,7 +70,7 @@ <h5><span class="tsd-kind-parameter">values</span>: <span class="tsd-signature-t
</div></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/neo4j-contrib/neovis.js/blob/902ea8d/src/events.ts#L47">src/events.ts:47</a></li></ul></aside></li></ul></section>
<li>Defined in <a href="https://github.com/neo4j-contrib/neovis.js/blob/28524f3/src/events.ts#L47">src/events.ts:47</a></li></ul></aside></li></ul></section>
<section class="tsd-panel tsd-member"><a id="register" class="tsd-anchor"></a>
<h3 class="tsd-anchor-link"><span>register</span><a href="#register" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
<ul class="tsd-signatures">
Expand All @@ -94,7 +94,7 @@ <h5><span class="tsd-kind-parameter">handler</span>: <a href="../interfaces/Even
</div></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/neo4j-contrib/neovis.js/blob/902ea8d/src/events.ts#L34">src/events.ts:34</a></li></ul></aside></li></ul></section></section></div>
<li>Defined in <a href="https://github.com/neo4j-contrib/neovis.js/blob/28524f3/src/events.ts#L34">src/events.ts:34</a></li></ul></aside></li></ul></section></section></div>
<div class="col-sidebar">
<div class="page-menu">
<div class="tsd-navigation settings">
Expand Down
Loading

0 comments on commit 0e202b1

Please sign in to comment.