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.

64 lines
1.8 KiB

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