Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Commit

Permalink
Enable unit testing for module Network (#3313)
Browse files Browse the repository at this point in the history
* Enable unit testing for module Network

Adds mocks for certain components, in order to let module `Network` be run in unit tests.

Changes:

- Create a mock object for `hammer.js` when running browserless. The inspiration is taken from [here](visgl/deck.gl#658)
- Create a mock function for `window.requestAnimationFrame()` when running browserless in `network/modules/CanvasRenderer.js`
- Added unit test for `Network` to show that unit testing for it now works
- Fixed naming of container in `test/Graph3d.test.js`

Since `hammer.js` is also used in other modules, this fix is potentially an enabler for full-module unit tests for those as well.

* Cleanup unit test Network

* Fix for unit test

* Added example networks to unit test

* Fix error in loading disassemblerExample

* Network unit test final fixes

* Adjusted comments
  • Loading branch information
wimrijnders authored and yotamberk committed Aug 16, 2017
1 parent 8c8f21d commit 046fb27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/network/modules/CanvasRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
* * During unit testing, it happens that the window object is reset during execution, causing
* a runtime error due to missing `requestAnimationFrame()`. This needs to be compensated for,
* see `_requestNextFrame()`.
* * Since this is a global object, it may affect other modules besides `Network`! This has not
* caused any problems yet. The method is only used within `Network`.
* * Since this is a global object, it may affect other modules besides `Network`. With normal
* usage, this does not cause any problems. During unit testing, errors may occur. These have
* been compensated for, see comment block in _requestNextFrame().
*
* @private
*/
Expand Down Expand Up @@ -127,6 +128,9 @@ class CanvasRenderer {
// 'requestAnimationFrame()' is not present because it is not defined on the
// mock window object.
//
// As a consequence, unrelated unit tests may appear to fail, even if the problem
// described happens in the current unit test.
//
// This is not something that will happen in normal operation, but we still need
// to take it into account.
if (window === undefined) return;
Expand Down
2 changes: 2 additions & 0 deletions test/Network.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ describe('Network', function () {
},
clusterNodeProperties: {id:"c1", label:'c1'}
}

network.cluster(clusterOptionsByData);
numNodes += 1; // new cluster node
assertNumNodes(network, numNodes, numNodes - 3); // 3 clustered nodes
Expand Down Expand Up @@ -273,6 +274,7 @@ describe('on node.js', function () {


describe('runs example ', function () {

function loadExample(path, noPhysics) {
include(path, this);
var container = document.getElementById('mynetwork');
Expand Down

0 comments on commit 046fb27

Please sign in to comment.