From a00e8f79cbcf2a717ad78f31b9ded8ebaefd9d47 Mon Sep 17 00:00:00 2001 From: Wim Rijnders Date: Sat, 15 Jul 2017 10:54:25 +0200 Subject: [PATCH] Add unit tests for Graph3D issue This adds a unit test for PR #3255 which fixes #3251. The unit test will fail without the PR merged. **NOTE:** This also adds module `canvas`, required for the unit test. This module proved to be quite fickly to install properly. During reviewing, please pay special attention to the proper installation of this modul. I.e. do following to test: ``` > npm install # If no errors, continue > npm test /tests/Graph3D.test.js # Run unit test isolated ``` --- package.json | 1 + test/Graph3d.test.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/Graph3d.test.js diff --git a/package.json b/package.json index e1d285ee7..11f6e74c1 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "gulp-util": "^3.0.8", "jsdom": "9.9.1", "jsdom-global": "^2.1.1", + "canvas": "^1.6.5", "mocha": "^3.2.0", "mocha-jsdom": "^1.1.0", "rimraf": "^2.5.4", diff --git a/test/Graph3d.test.js b/test/Graph3d.test.js new file mode 100644 index 000000000..0864572d1 --- /dev/null +++ b/test/Graph3d.test.js @@ -0,0 +1,33 @@ +var assert = require('assert'); +var jsdom_global = require('jsdom-global'); +var vis = require('../dist/vis'); +var Graph3d = vis.Graph3d; + + +describe('Graph3d', function () { + var jsdom = jsdom_global("
"); + var container = document.getElementById('mynetwork'); + assert(container !== null, 'Container div not found'); + + it('accepts new option values on defined instance', function () { + var BAR_STYLE = 0; // from var STYLE in Settings.js + var DOT_STYLE = 3; // idem + + var data = [ + {x:0, y:0, z: 10}, + {x:0, y:1, z: 20}, + {x:1, y:0, z: 30}, + {x:1, y:1, z: 40}, + ]; + + var options = { + style: 'dot' + }; + + var graph = new vis.Graph3d(container, data, options); + assert.equal(graph.style, DOT_STYLE, "Style not set to expected 'dot'"); + + graph.setOptions({ style: 'bar'}); // Call fails without PR #3255 + assert.equal(graph.style, BAR_STYLE, "Style not set to expected 'bar'"); + }); +});