vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.9 KiB

  1. var assert = require('assert');
  2. var vis = require('../dist/vis');
  3. var Graph3d = vis.Graph3d;
  4. var jsdom_global = require('jsdom-global');
  5. var stdout = require('test-console').stdout;
  6. var Validator = require("./../lib/shared/Validator").default;
  7. //var {printStyle} = require('./../lib/shared/Validator');
  8. var {allOptions, configureOptions} = require('./../lib/graph3d/options.js');
  9. var now = new Date();
  10. describe('Graph3d', function () {
  11. before(function() {
  12. //console.log('before!');
  13. this.jsdom_global = jsdom_global(
  14. "<div id='mynetwork'></div>",
  15. { skipWindowCheck: true}
  16. );
  17. this.container = document.getElementById('mynetwork');
  18. });
  19. it('should pass validation for the default options', function () {
  20. assert(Graph3d.DEFAULTS !== undefined);
  21. let errorFound;
  22. let output;
  23. output = stdout.inspectSync(function() {
  24. errorFound = Validator.validate(Graph3d.DEFAULTS, allOptions);
  25. });
  26. // Useful during debugging:
  27. //if (errorFound === true) {
  28. // console.log(JSON.stringify(output, null, 2));
  29. //}
  30. assert(!errorFound, 'DEFAULTS options object does not pass validation');
  31. });
  32. it('accepts new option values on defined instance', function () {
  33. assert(this.container !== null, 'Container div not found');
  34. var BAR_STYLE = 0; // from var STYLE in Settings.js
  35. var DOT_STYLE = 3; // idem
  36. var data = [
  37. {x:0, y:0, z: 10},
  38. {x:0, y:1, z: 20},
  39. {x:1, y:0, z: 30},
  40. {x:1, y:1, z: 40},
  41. ];
  42. var options = {
  43. style: 'dot'
  44. };
  45. var graph = new vis.Graph3d(this.container, data, options);
  46. assert.equal(graph.style, DOT_STYLE, "Style not set to expected 'dot'");
  47. graph.setOptions({ style: 'bar'}); // Call should just work, no exception thrown
  48. assert.equal(graph.style, BAR_STYLE, "Style not set to expected 'bar'");
  49. });
  50. after(function() {
  51. //console.log('after!');
  52. this.jsdom_global();
  53. });
  54. });