Skip to content
This repository was archived by the owner on Mar 29, 2021. It is now read-only.

Commit

Permalink
#125: added two additional tests with verification and number of calls;
Browse files Browse the repository at this point in the history
  • Loading branch information
w20k committed Oct 13, 2016
1 parent c0ec231 commit a32961d
Showing 1 changed file with 61 additions and 4 deletions.
65 changes: 61 additions & 4 deletions tests/mods/landSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,11 @@ describe ( 'Land.js tests', function () {
spyOn(idrinth.settings, 'save');
spyOn(idrinth.settings, 'change');
spyOn(idrinth.text, 'get');
spyOn(idrinth.text, 'start');
} );


it ( "Should properly calculate without errors", function () {
//Prepare values
it ( "Should properly calculate when gold is 8000000000", function () {
idrinth.settings.land.gold = 8000000000;

idrinth.land.calculate ();

expect(mockDOM['idrinth-land-cornfield'].value).toEqual(840);
Expand All @@ -105,8 +102,68 @@ describe ( 'Land.js tests', function () {
expect(mockDOM['idrinth-land-fort'].parentNode.nextSibling.innerHTML).toEqual("+230");
expect(mockDOM['idrinth-land-castle'].parentNode.nextSibling.innerHTML).toEqual("+200");

expect(idrinth.settings.change.calls.count()).toEqual(10);
expect(idrinth.settings.save.calls.count()).toEqual(1);

expect(idrinth.core.alert.calls.count()).toEqual(0);
expect(idrinth.text.get.calls.count()).toEqual(0);
} );


it ( "Should show alert when gold is 0", function () {
idrinth.settings.land.gold = 0;
idrinth.land.calculate ();

expect(idrinth.settings.save.calls.count()).toEqual(1);

expect(idrinth.core.alert.calls.count()).toEqual(1);
expect(idrinth.text.get.calls.count()).toEqual(1);
} );

it ( "Should properly calculate when gold is 8000000000 and 10 for each land type", function () {
idrinth.settings.land.gold = 8000000000;

idrinth.settings.land.cornfield = 100;
idrinth.settings.land.stable = 100;
idrinth.settings.land.barn = 100;
idrinth.settings.land.store = 100;
idrinth.settings.land.pub = 100;
idrinth.settings.land.inn = 100;
idrinth.settings.land.tower = 100;
idrinth.settings.land.fort = 100;
idrinth.settings.land.castle = 100;

idrinth.land.calculate ();

expect(mockDOM['idrinth-land-cornfield'].value).toEqual(790);
expect(mockDOM['idrinth-land-stable'].value).toEqual(600);
expect(mockDOM['idrinth-land-barn'].value).toEqual(450);
expect(mockDOM['idrinth-land-store'].value).toEqual(380);
expect(mockDOM['idrinth-land-pub'].value).toEqual(310);
expect(mockDOM['idrinth-land-inn'].value).toEqual(270);
expect(mockDOM['idrinth-land-tower'].value).toEqual(200);
expect(mockDOM['idrinth-land-fort'].value).toEqual(150);
expect(mockDOM['idrinth-land-castle'].value).toEqual(120);
expect(mockDOM['idrinth-land-gold'].value).toEqual(2450000);

expect(mockDOM['idrinth-land-cornfield'].parentNode.nextSibling.innerHTML).toEqual("+790");
expect(mockDOM['idrinth-land-stable'].parentNode.nextSibling.innerHTML).toEqual("+600");
expect(mockDOM['idrinth-land-barn'].parentNode.nextSibling.innerHTML).toEqual("+450");
expect(mockDOM['idrinth-land-store'].parentNode.nextSibling.innerHTML).toEqual("+380");
expect(mockDOM['idrinth-land-pub'].parentNode.nextSibling.innerHTML).toEqual("+310");
expect(mockDOM['idrinth-land-inn'].parentNode.nextSibling.innerHTML).toEqual("+270");
expect(mockDOM['idrinth-land-tower'].parentNode.nextSibling.innerHTML).toEqual("+200");
expect(mockDOM['idrinth-land-fort'].parentNode.nextSibling.innerHTML).toEqual("+150");
expect(mockDOM['idrinth-land-castle'].parentNode.nextSibling.innerHTML).toEqual("+120");

expect(idrinth.settings.change.calls.count()).toEqual(10);
expect(idrinth.settings.save.calls.count()).toEqual(1);

expect(idrinth.core.alert.calls.count()).toEqual(0);
expect(idrinth.text.get.calls.count()).toEqual(0);
} );


} );

} );

0 comments on commit a32961d

Please sign in to comment.