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

Commit

Permalink
#125: added two minor changes to tests, added Settings core tests;
Browse files Browse the repository at this point in the history
  • Loading branch information
w20k committed Oct 18, 2016
1 parent a32961d commit 6953752
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 59 deletions.
129 changes: 70 additions & 59 deletions tests/mods/landSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,54 +70,65 @@ describe ( 'Land.js tests', function () {
return document_getElementById ( id );
} );

spyOn(idrinth.core, 'alert');
spyOn(idrinth.settings, 'save');
spyOn(idrinth.settings, 'change');
spyOn(idrinth.text, 'get');
spyOn ( idrinth.core, 'alert' );
spyOn ( idrinth.settings, 'save' );
spyOn ( idrinth.settings, 'change' );
spyOn ( idrinth.text, 'get' );
} );

afterEach ( function () {
//cleanup all defined values settings
if ( idrinth && idrinth.settings ) {
for ( var i in idrinth.settings.land ) {
if ( idrinth.settings.land.hasOwnProperty ( i ) ) {
idrinth.settings.land[ i ] = 0;
}
}
}
} );


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);
expect(mockDOM['idrinth-land-stable'].value).toEqual(650);
expect(mockDOM['idrinth-land-barn'].value).toEqual(520);
expect(mockDOM['idrinth-land-store'].value).toEqual(450);
expect(mockDOM['idrinth-land-pub'].value).toEqual(390);
expect(mockDOM['idrinth-land-inn'].value).toEqual(350);
expect(mockDOM['idrinth-land-tower'].value).toEqual(280);
expect(mockDOM['idrinth-land-fort'].value).toEqual(230);
expect(mockDOM['idrinth-land-castle'].value).toEqual(200);
expect(mockDOM['idrinth-land-gold'].value).toEqual(1450000);

expect(mockDOM['idrinth-land-cornfield'].parentNode.nextSibling.innerHTML).toEqual("+840");
expect(mockDOM['idrinth-land-stable'].parentNode.nextSibling.innerHTML).toEqual("+650");
expect(mockDOM['idrinth-land-barn'].parentNode.nextSibling.innerHTML).toEqual("+520");
expect(mockDOM['idrinth-land-store'].parentNode.nextSibling.innerHTML).toEqual("+450");
expect(mockDOM['idrinth-land-pub'].parentNode.nextSibling.innerHTML).toEqual("+390");
expect(mockDOM['idrinth-land-inn'].parentNode.nextSibling.innerHTML).toEqual("+350");
expect(mockDOM['idrinth-land-tower'].parentNode.nextSibling.innerHTML).toEqual("+280");
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);
expect ( mockDOM[ 'idrinth-land-cornfield' ].value ).toEqual ( 840 );
expect ( mockDOM[ 'idrinth-land-stable' ].value ).toEqual ( 650 );
expect ( mockDOM[ 'idrinth-land-barn' ].value ).toEqual ( 520 );
expect ( mockDOM[ 'idrinth-land-store' ].value ).toEqual ( 450 );
expect ( mockDOM[ 'idrinth-land-pub' ].value ).toEqual ( 390 );
expect ( mockDOM[ 'idrinth-land-inn' ].value ).toEqual ( 350 );
expect ( mockDOM[ 'idrinth-land-tower' ].value ).toEqual ( 280 );
expect ( mockDOM[ 'idrinth-land-fort' ].value ).toEqual ( 230 );
expect ( mockDOM[ 'idrinth-land-castle' ].value ).toEqual ( 200 );
expect ( mockDOM[ 'idrinth-land-gold' ].value ).toEqual ( 1450000 );

expect ( mockDOM[ 'idrinth-land-cornfield' ].parentNode.nextSibling.innerHTML ).toEqual ( "+840" );
expect ( mockDOM[ 'idrinth-land-stable' ].parentNode.nextSibling.innerHTML ).toEqual ( "+650" );
expect ( mockDOM[ 'idrinth-land-barn' ].parentNode.nextSibling.innerHTML ).toEqual ( "+520" );
expect ( mockDOM[ 'idrinth-land-store' ].parentNode.nextSibling.innerHTML ).toEqual ( "+450" );
expect ( mockDOM[ 'idrinth-land-pub' ].parentNode.nextSibling.innerHTML ).toEqual ( "+390" );
expect ( mockDOM[ 'idrinth-land-inn' ].parentNode.nextSibling.innerHTML ).toEqual ( "+350" );
expect ( mockDOM[ 'idrinth-land-tower' ].parentNode.nextSibling.innerHTML ).toEqual ( "+280" );
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.settings.save.calls.count () ).toEqual ( 1 );

expect(idrinth.core.alert.calls.count()).toEqual(1);
expect(idrinth.text.get.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 () {
Expand All @@ -135,32 +146,32 @@ describe ( 'Land.js tests', function () {

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);
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 );
} );


Expand Down
61 changes: 61 additions & 0 deletions tests/mods/settingsSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
describe ( 'Settings.js tests', function () {

it ( 'should have a idrinth variable in scope', function () {
expect ( idrinth ).toBeDefined ();
} );

it ( 'should have default values defined', function () {
var defaults = {
raids: false,
favs: '',
factor: true,
moveLeft: false,
minimalist: false,
chatHiddenOnStart: true,
names: true,
timeout: 5000,
loadtime: 5000,
windows: 3,
warBottom: false,
landMax: true,
chatting: true,
chatuser: '',
newgroundLoad: 30,
chatpass: '',
isWorldServer: false,
alarmTime: '8:0',
alarmActive: false,
bannedRaids: {},
language: 'en',
notification: {
mention: true,
message: true,
raid: true
},
land: {
cornfield: 0,
stable: 0,
barn: 0,
store: 0,
pub: 0,
inn: 0,
tower: 0,
fort: 0,
castle: 0,
gold: 0
}
};

var copySettings = JSON.parse ( JSON.stringify ( idrinth.settings ) );

//CleanUP functions -> not part of the test
for ( var i in copySettings ) {
if ( copySettings.hasOwnProperty ( i ) && typeof copySettings[ i ] === 'function' ) {
delete copySettings[ i ];
}
}

expect ( copySettings ).toEqual ( defaults );
} );

} );

0 comments on commit 6953752

Please sign in to comment.