Skip to content
Permalink
Browse files

tests starts looking good

  • Loading branch information...
thebestnom committed Jun 6, 2019
1 parent 969cffa commit 172aeb15e2688c9698ce8aa861f1be9223e62325
Showing with 28 additions and 9 deletions.
  1. +0 −2 .eslintrc.yml
  2. +26 −5 __tests__/neovis.tests.js
  3. +2 −2 src/neovis.js
@@ -28,5 +28,3 @@ rules:
- error
jest/no-mocks-import:
- error
jest/lowercase-name:
- error
@@ -1,12 +1,24 @@
import * as Neo4jMock from 'neo4j-driver';
import Neo4j, * as Neo4jMock from 'neo4j-driver';
import Neovis from '../src/neovis';
import { CompletionEvent } from '../src/events';

jest.mock('neo4j-driver');

describe('test', () => {
function makeNode(id, labels, properties) {
return new Neo4j.types.Record(Neo4j.int(id), labels, properties);
}

function mockNormalRunSubscribe(records = []) {
Neo4jMock.mockRunSubscribe.mockImplementationOnce(({onNext, onCompleted}) => {
records.forEach(onNext);
onCompleted();
});
}

describe('Neovis', () => {
const container_id = 'randomId';
let initial_cypher, neovis;
const label1 = 'label1';

beforeEach(() => Neo4jMock.clearAllMocks());
beforeEach(() => {
@@ -15,18 +27,27 @@ describe('test', () => {
neovis = new Neovis({initial_cypher, container_id});
});

describe('test', () => {
describe('Neovis default behavior', () => {
it('should call run with query', () => {
neovis.render();
expect(Neo4jMock.mockSessionRun).toHaveBeenCalledWith(initial_cypher, {limit: 30});
});

it('should call completed when complete', (done) => {
Neo4jMock.mockRunSubscribe.mockImplementationOnce(({onCompleted}) => {
onCompleted();
mockNormalRunSubscribe();
neovis.render();
neovis.registerOnEvent(CompletionEvent, () => {
done();
});
});

it('should save records to dataset', (done) => {
mockNormalRunSubscribe([
new Neo4j.types.Record(['common'], [makeNode(1, [label1], {random: 1})]),
]);
neovis.render();
neovis.registerOnEvent(CompletionEvent, () => {
expect(neovis._data.nodes.get(1)).toBeDefined();
done();
});
});
@@ -325,8 +325,8 @@ export default class NeoVis {

const container = this._container;
this._data = {
'nodes': new vis.DataSet(Object.values(this._nodes)),
'edges': new vis.DataSet(Object.values(this._edges))
nodes: new vis.DataSet(Object.values(this._nodes)),
edges: new vis.DataSet(Object.values(this._edges))
};

this._consoleLog(this._data.nodes);

0 comments on commit 172aeb1

Please sign in to comment.
You can’t perform that action at this time.