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.

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