Skip to content

Commit

Permalink
Getting code coverage over app router.
Browse files Browse the repository at this point in the history
  • Loading branch information
cebartling committed Mar 7, 2014
1 parent 88b5212 commit e44622f
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 4 deletions.
3 changes: 0 additions & 3 deletions web-client/app/scripts/app-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
'round7': 'showRound7'
},

initialize: function() {
},

showRound1: function() {
var model = new BasketballTournament.Models.TournamentRoundModel(BasketballTournament.DataBuilders.TournamentRoundDataBuilder.round1, {round: 1});
var view = new BasketballTournament.Views.TournamentFirstRoundView({model: model});
Expand Down
1 change: 1 addition & 0 deletions web-client/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = function (config) {
'app/bower_components/backbone/backbone.js',
'app/bower_components/handlebars/handlebars.js',
'app/bower_components/bootstrap/dist/js/bootstrap.js',
'test/bower_components/jasmine-fixture/dist/jasmine-fixture.js',
'app/scripts/namespaces.js',
'.tmp/scripts/templates.js',
'app/scripts/**/*.js',
Expand Down
3 changes: 2 additions & 1 deletion web-client/test/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "web-client",
"version": "0.0.0",
"dependencies": {
"jasmine": "1.3.1"
"jasmine": "1.3.1",
"jasmine-fixture": "1.2.0"
},
"devDependencies": {}
}
140 changes: 140 additions & 0 deletions web-client/test/spec/app-router-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,145 @@
expect(appRouter.routes['round7']).toBe('showRound7');
});
});

describe('.showRound1 function', function () {
var modelSpy, viewSpy;
var stubModel = {

};
var stubView = {
render: function () {
return this;
},

el: '<div id="round-one-jasmine-test-div"></div>'
};

beforeEach(function () {
modelSpy = spyOn(BasketballTournament.Models, 'TournamentRoundModel').andReturn(stubModel);
viewSpy = spyOn(BasketballTournament.Views, 'TournamentFirstRoundView').andReturn(stubView);
// Use jasmine-fixture to add DOM fixture for testing
affix('div.main-content');
});

it('creates a new model.', function () {
appRouter.showRound1();
expect(modelSpy).toHaveBeenCalledWith(BasketballTournament.DataBuilders.TournamentRoundDataBuilder.round1, {round: 1});
});

it('creates a new view.', function () {
appRouter.showRound1();
expect(viewSpy).toHaveBeenCalledWith({model: stubModel});
});

it('sets the inner HTML of main-content div.', function () {
appRouter.showRound1();
expect($('div.main-content div#round-one-jasmine-test-div').length).toBe(1);
});
});

describe('.showRound2 function', function () {
var modelSpy, viewSpy;
var stubModel = {

};
var stubView = {
render: function () {
return this;
},

el: '<div id="round-two-jasmine-test-div"></div>'
};

beforeEach(function () {
modelSpy = spyOn(BasketballTournament.Models, 'TournamentRoundModel').andReturn(stubModel);
viewSpy = spyOn(BasketballTournament.Views, 'TournamentRegionalRoundView').andReturn(stubView);
// Use jasmine-fixture to add DOM fixture for testing
affix('div.main-content');
});

it('creates a new model.', function () {
appRouter.showRound2();
expect(modelSpy).toHaveBeenCalledWith(BasketballTournament.DataBuilders.TournamentRoundDataBuilder.round2, {round: 2});
});

it('creates a new view.', function () {
appRouter.showRound2();
expect(viewSpy).toHaveBeenCalledWith({model: stubModel});
});

it('sets the inner HTML of main-content div.', function () {
appRouter.showRound2();
expect($('div.main-content div#round-two-jasmine-test-div').length).toBe(1);
});
});

describe('.showRound3 function', function () {
var modelSpy, viewSpy;
var stubModel = { };
var stubView = {
render: function () {
return this;
},

el: '<div id="round-three-jasmine-test-div"></div>'
};

beforeEach(function () {
modelSpy = spyOn(BasketballTournament.Models, 'TournamentRoundModel').andReturn(stubModel);
viewSpy = spyOn(BasketballTournament.Views, 'TournamentRegionalRoundView').andReturn(stubView);
// Use jasmine-fixture to add DOM fixture for testing
affix('div.main-content');
});

it('creates a new model.', function () {
appRouter.showRound3();
expect(modelSpy).toHaveBeenCalledWith(BasketballTournament.DataBuilders.TournamentRoundDataBuilder.round3, {round: 3});
});

it('creates a new view.', function () {
appRouter.showRound3();
expect(viewSpy).toHaveBeenCalledWith({model: stubModel});
});

it('sets the inner HTML of main-content div.', function () {
appRouter.showRound3();
expect($('div.main-content div#round-three-jasmine-test-div').length).toBe(1);
});
});

describe('.showRound4 function', function () {
var modelSpy, viewSpy;
var stubModel = { };
var stubView = {
render: function () {
return this;
},

el: '<div id="round-four-jasmine-test-div"></div>'
};

beforeEach(function () {
modelSpy = spyOn(BasketballTournament.Models, 'TournamentRoundModel').andReturn(stubModel);
viewSpy = spyOn(BasketballTournament.Views, 'TournamentRegionalRoundView').andReturn(stubView);
// Use jasmine-fixture to add DOM fixture for testing
affix('div.main-content');
});

it('creates a new model.', function () {
appRouter.showRound4();
expect(modelSpy).toHaveBeenCalledWith(BasketballTournament.DataBuilders.TournamentRoundDataBuilder.round4, {round: 4});
});

it('creates a new view.', function () {
appRouter.showRound4();
expect(viewSpy).toHaveBeenCalledWith({model: stubModel});
});

it('sets the inner HTML of main-content div.', function () {
appRouter.showRound4();
expect($('div.main-content div#round-four-jasmine-test-div').length).toBe(1);
});
});
});
})();

0 comments on commit e44622f

Please sign in to comment.