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.

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