Skip to content

Commit

Permalink
Merge pull request #2 from matthojo/tests
Browse files Browse the repository at this point in the history
Added Log, Loop and Mediator tests and other test foundations
  • Loading branch information
robhawkes committed Feb 7, 2014
2 parents 17e8b3c + f4989ca commit 8e43888
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 2 deletions.
22 changes: 20 additions & 2 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<body>
<div id="mocha"></div>

<!-- Dependencies -->
<!-- Testing Dependencies -->
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script src="../node_modules/sinon/pkg/sinon.js"></script>
Expand All @@ -17,13 +17,31 @@
mocha.ui('bdd');
mocha.reporter('html');
expect = chai.expect;
assert = chai.assert;
</script>

<!-- Vizicities Dependencies -->
<script src="../src/shared/vendor/underscore.js"></script>
<script src="../src/shared/vendor/moment.js"></script>
<script src="../src/shared/vendor/three/three.js"></script>

<!-- Source files -->
<script src="../src/client/Vizi.js"></script>

<script src="../src/client/Mediator.js"></script>
<script src="../src/client/Log.js"></script>
<script src="../src/client/DOMEvents.js"></script>
<script src="../src/client/Loop.js"></script>
<script src="../src/client/Geo.js"></script>
<script src="../src/client/City.js"></script>

<!-- Tests -->
<script src="spec/Vizi.js"></script>
<script src="spec/Mediator.js"></script>
<script src="spec/Log.js"></script>
<script src="spec/DOMEvents.js"></script>
<script src="spec/Loop.js"></script>
<script src="spec/Geo.js"></script>
<script src="spec/City.js"></script>

<!-- Run Mocha -->
<script>
Expand Down
7 changes: 7 additions & 0 deletions test/spec/City.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe("City", function() {

it("exists in `VIZI`", function() {
expect(VIZI.City).to.exist;
});

});
7 changes: 7 additions & 0 deletions test/spec/DOMEvents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe("DOMEvents", function() {

it("exists in `VIZI`", function() {
expect(VIZI.DOMEvents).to.exist;
});

});
7 changes: 7 additions & 0 deletions test/spec/Geo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe("Geo", function() {

it("exists in `VIZI`", function() {
expect(VIZI.Geo).to.exist;
});

});
30 changes: 30 additions & 0 deletions test/spec/Log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe("Log", function() {

var spy;

before(function(){
spy = sinon.spy(VIZI, "Log");
});

afterEach(function(){
spy.reset(); // reset spy on every test, otherwise call information gets stacked.
});

it("exists in `VIZI`", function() {
expect(VIZI.Log).to.exist;
});

it("runs `Log` function", function() {

VIZI.Log("arg1", "arg2", "arg3");

assert.equal(spy.called, true);
});

it("accepts and sets arguments correctly", function() {

VIZI.Log("arg1", 2, {"arg": 3});

assert.deepEqual(spy.args[0], ["arg1", 2, {"arg": 3}]);
});
});
51 changes: 51 additions & 0 deletions test/spec/Loop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
describe("Loop", function() {
var loop;

before(function () {
loop = new VIZI.Loop();
});

it("exists in `VIZI`", function() {
expect(VIZI.Loop).to.exist;
});

it("has a 'start' function", function() {
expect(loop).to.have.property("start");
});

it("has a 'stop' function", function() {
expect(loop).to.have.property("stop");
});

it("has a 'tick' function", function() {
expect(loop).to.have.property("tick");
});

it("starts loop", function() {
var spy = new sinon.spy(loop, "start");
loop.stop(); // Stop default loop
loop.start();

assert.equal(spy.called, true);
assert.equal(loop.stopLoop, false);

loop.stop();
});

it("calls `tick()` on start", function() {
var spy = new sinon.spy(loop, "tick");
loop.start();
loop.stop();

assert.equal(spy.called, true);
});

it("stops loop", function() {
var spy = new sinon.spy(loop, "stop");
loop.start();
loop.stop();

assert.equal(spy.called, true);
assert.equal(loop.stopLoop, true);
});
});
24 changes: 24 additions & 0 deletions test/spec/Mediator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
describe("Mediator", function() {

it("exists in `VIZI`", function() {
expect(VIZI.Mediator).to.exist;
});

it("has a 'publish' function", function() {
expect(VIZI.Mediator).to.have.property("publish");
});

it("has a 'subscribe' function", function() {
expect(VIZI.Mediator).to.have.property("subscribe");
});

it("subscribes and publishes to a topic", function() {
var spy = sinon.spy();
var message = "this is a message";

VIZI.Mediator.subscribe("test_topic", spy);
VIZI.Mediator.publish("test_topic", message);

assert.equal(message, spy.args[0][0]);
});
});

0 comments on commit 8e43888

Please sign in to comment.