forked from allegro/ralph
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Motivation: Code without tests is bad code. Added way to test code written in JS by QUnit and PhantomJS.
- Loading branch information
Showing
6 changed files
with
97 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>QUnit Example</title> | ||
<link rel="stylesheet" href="../../../bower_components/qunit/qunit/qunit.css"> | ||
</head> | ||
<body> | ||
<div id="qunit"></div> | ||
<div id="qunit-fixture"></div> | ||
|
||
<script src="../../../bower_components/qunit/qunit/qunit.js"></script> | ||
|
||
<script src="../../../bower_components/sinon/index.js"></script> | ||
<script src="../../../bower_components/sinon-qunit/lib/sinon-qunit.js"></script> | ||
|
||
<script src="../../../bower_components/angular/angular.js"></script> | ||
<script src="../../../bower_components/angular-resource/angular-resource.js"></script> | ||
<script src="../../../bower_components/angular-ui-router/release/angular-ui-router.js"></script> | ||
<script src="../../../bower_components/angular-breadcrumb/release/angular-breadcrumb.js"></script> | ||
<script src="../../../bower_components/angular-loading-bar/build/loading-bar.js"></script> | ||
|
||
<script type="text/javascript" src="../dc_view/static/js/app/apps.js"></script> | ||
|
||
<script type="text/javascript" src="../dc_view/static/js/app/common/filters.js"></script> | ||
|
||
<script type="text/javascript" src="../dc_view/static/js/app/data_center/controllers.js"></script> | ||
<script type="text/javascript" src="../dc_view/static/js/app/data_center/directives.js"></script> | ||
<script type="text/javascript" src="../dc_view/static/js/app/data_center/services.js"></script> | ||
|
||
<script type="text/javascript" src="../dc_view/static/js/app/rack/controllers.js"></script> | ||
<script type="text/javascript" src="../dc_view/static/js/app/rack/directives.js"></script> | ||
<script type="text/javascript" src="../dc_view/static/js/app/rack/services.js"></script> | ||
|
||
<script src="./dc_view/data_center/controllers.test.js"></script> | ||
</body> |
52 changes: 52 additions & 0 deletions
52
src/ralph/js_tests/dc_view/data_center/controllers.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
var serviceLocator = angular.injector(['ng', 'dataCenterVisualizationApp']); | ||
var $controllers = serviceLocator.get('$controller'); | ||
var scope = {}; | ||
var dataCenterMock = { | ||
rack_set: [] | ||
}; | ||
var rackModel; | ||
|
||
QUnit.module('Data Center controllers', { | ||
setup: function () { | ||
scope = serviceLocator.get('$rootScope').$new(); | ||
rackModel = serviceLocator.get('RackModel'); | ||
$controllers('DataCenterController', {$scope: scope, data_center: dataCenterMock, RackModel: rackModel}); | ||
} | ||
}); | ||
|
||
test('newRack should add rack to rack_set', function(){ | ||
ok(scope.data_center.rack_set.length === 0); | ||
scope.newRack(1, 1); | ||
ok(scope.data_center.rack_set.length === 1); | ||
}); | ||
|
||
test('updatePosition should not update variables actualX and actualY when target is not equal currentTarget', function() { | ||
var mockedPos = 1; | ||
scope.actualX = mockedPos; | ||
scope.actualY = mockedPos; | ||
var mockedEvent = { | ||
target: {element: 'rack'}, | ||
currentTarget: {element: 'grid'}, | ||
offsetX: 800, | ||
offsetY: 400, | ||
}; | ||
scope.updatePosition(mockedEvent); | ||
ok(scope.actualX == mockedPos); | ||
ok(scope.actualY == mockedPos); | ||
}); | ||
|
||
test('updatePosition should update variables actualX and actualY', function() { | ||
var mockedTarget = { | ||
offsetLeft: 0, | ||
offsetTop: 0 | ||
}; | ||
var mockedEvent = { | ||
target: mockedTarget, | ||
currentTarget: mockedTarget, | ||
offsetX: 80, // 2 times grid size | ||
offsetY: 40 | ||
}; | ||
scope.updatePosition(mockedEvent); | ||
ok(scope.actualX === 2); | ||
ok(scope.actualY === 1); | ||
}); |