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

Commit c9925a1

Browse files
committed
Merge origin/asdsad
Conflicts: src/mods/text.js tests/landbuy.js
2 parents 33e3233 + 9a0715f commit c9925a1

8 files changed

Lines changed: 376 additions & 2 deletions

File tree

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Coverage directory used by tools like istanbul
2+
coverage
3+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
4+
.grunt
5+
# Dependency directories
6+
node_modules
7+
.npm
8+

karma.conf.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Karma configuration
2+
3+
module.exports = function ( config ) {
4+
config.set ( {
5+
6+
// base path that will be used to resolve all patterns (eg. files, exclude)
7+
basePath: '',
8+
9+
10+
// frameworks to use
11+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
12+
frameworks: [ 'jasmine' ],
13+
14+
15+
// list of files / patterns to load in the browser
16+
files: [
17+
//Starting point
18+
'src/stable.js',
19+
20+
'src/**/*.js',
21+
'tests/**/*.spec.js'
22+
],
23+
24+
25+
// list of files to exclude
26+
exclude: [
27+
'src/libs/*.js'
28+
],
29+
30+
31+
// preprocess matching files before serving them to the browser
32+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
33+
preprocessors: {
34+
'src/**/*.js': [ 'coverage' ]
35+
},
36+
37+
38+
// test results reporter to use
39+
// possible values: 'dots', 'progress'
40+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
41+
reporters: [ 'spec', 'coverage' ],
42+
43+
44+
// web server port
45+
port: 9876,
46+
47+
48+
// enable / disable colors in the output (reporters and logs)
49+
colors: true,
50+
51+
52+
// level of logging
53+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
54+
logLevel: config.LOG_INFO,
55+
56+
57+
// enable / disable watching file and executing tests whenever any file changes
58+
autoWatch: false,
59+
60+
61+
// start these browsers
62+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
63+
browsers: [ 'PhantomJS' ],
64+
65+
66+
// Continuous Integration mode
67+
// if true, Karma captures browsers, runs the tests and exits
68+
singleRun: true,
69+
70+
// Concurrency level
71+
// how many browser should be started simultaneous
72+
concurrency: Infinity
73+
} )
74+
};

package.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "idotd",
3+
"version": "10.0.0",
4+
"description": "A script for dawn of the dragons, that works based on data provided to https://dotd.idrinth.de via UgUp",
5+
"main": "src/stable.js",
6+
"directories": {
7+
"test": "test"
8+
},
9+
"scripts": {
10+
"test": "./node_modules/karma/bin/karma start karma.conf.js",
11+
"test-watch": "./node_modules/karma/bin/karma start karma.conf.js --auto-watch"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/Idrinth/IDotD.git"
16+
},
17+
"keywords": [
18+
"dotd",
19+
"idrinth",
20+
"script",
21+
"userscript",
22+
"dotd"
23+
],
24+
"author": "Björn Büttner",
25+
"license": "MIT",
26+
"bugs": {
27+
"url": "https://github.com/Idrinth/IDotD/issues"
28+
},
29+
"homepage": "https://github.com/Idrinth/IDotD#idotd",
30+
"devDependencies": {
31+
"jasmine": "^2.5.3",
32+
"jasmine-core": "^2.5.2",
33+
"karma": "^1.3.0",
34+
"karma-coverage": "^1.1.1",
35+
"karma-jasmine": "^1.1.0",
36+
"karma-phantomjs-launcher": "^1.0.2",
37+
"karma-spec-reporter": "0.0.26"
38+
}
39+
}

src/mods/text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ idrinth.text = {
7070
/**
7171
* returns the translation of a provided key or an error-message if no
7272
* matching translation is found
73-
* @param string key
73+
* @param {string} key
7474
* @returns {string}
7575
*/
7676
get: function(key) {

tests/landbuy.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/mods/land.spec.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
describe ( 'Land.js tests', function () {
2+
3+
it ( 'should have a idrinth variable in scope', function () {
4+
expect ( idrinth ).toBeDefined ();
5+
} );
6+
7+
8+
it ( 'should check default data is valid', function () {
9+
var defData = {
10+
cornfield: {
11+
perHour: 100,
12+
base: 4000
13+
},
14+
stable: {
15+
perHour: 300,
16+
base: 15000
17+
},
18+
barn: {
19+
perHour: 400,
20+
base: 25000
21+
},
22+
store: {
23+
perHour: 700,
24+
base: 50000
25+
},
26+
pub: {
27+
perHour: 900,
28+
base: 75000
29+
},
30+
inn: {
31+
perHour: 1200,
32+
base: 110000
33+
},
34+
tower: {
35+
perHour: 2700,
36+
base: 300000
37+
},
38+
fort: {
39+
perHour: 4500,
40+
base: 600000
41+
},
42+
castle: {
43+
perHour: 8000,
44+
base: 1200000
45+
}
46+
};
47+
48+
expect ( idrinth.land.data ).toEqual ( defData );
49+
} );
50+
51+
describe ( "Land calculate method", function () {
52+
53+
beforeEach ( function () {
54+
var mock = {},
55+
defaultStructure = '{ "value": "", "parentNode": { "nextSibling": { "innerHTML": "" } } }',
56+
document_getElementById;
57+
document_getElementById = jasmine.createSpyObj ( "input", [ 'value', 'parentNode', 'nextSibling', 'innerHTML' ] );
58+
59+
for ( var i in idrinth.land.data ) {
60+
if ( idrinth.land.data.hasOwnProperty ( i ) ) {
61+
mock[ 'idrinth-land-' + i ] = JSON.parse ( defaultStructure );
62+
}
63+
}
64+
mock[ 'idrinth-land-gold' ] = { value: '' };
65+
66+
spyOn ( document, "getElementById" ).and.callFake ( function ( id ) {
67+
if ( mock.hasOwnProperty ( id ) ) {
68+
return mock[ id ];
69+
}
70+
71+
return document_getElementById ( id );
72+
} );
73+
74+
spyOn(idrinth.core, 'alert');
75+
} );
76+
77+
78+
it ( "Should properly calculate land values", function () {
79+
idrinth.land.calculate ();
80+
} );
81+
82+
} );
83+
84+
} );

tests/mods/names.spec.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
describe ( 'Names.js tests', function () {
2+
3+
it ( 'should have a idrinth variable in scope', function () {
4+
expect ( idrinth ).toBeDefined ();
5+
} );
6+
7+
8+
it ( 'should check default data is valid, and empty', function () {
9+
expect ( idrinth.names.users ).toEqual ( {} );
10+
expect ( idrinth.names.classes ).toEqual ( {} );
11+
expect ( idrinth.names.guilds ).toEqual ( {} );
12+
expect ( idrinth.names.counter ).toEqual ( 0 );
13+
} );
14+
15+
describe ( "Names parse method", function () {
16+
//<span class="username chat_message_window_username ign dotdm_1484406507967"
17+
// username="arkamat" dotdxname="arkamat" oncontextmenu="return false;">K2 mat</span>
18+
19+
it ( "Should get attribute with name dotdxname", function () {
20+
var span = document.createElement ( "span" );
21+
span.className = 'username chat_message_window_username ign';
22+
span.setAttribute ( "dotdxname", "testcharacterDTX" );
23+
span.innerHTML = "K2 TestCharacter";
24+
25+
expect ( idrinth.names.parse ( span ) ).toEqual ( "testcharacterDTX" );
26+
} );
27+
28+
it ( "Should get attribute with name username", function () {
29+
30+
var span = document.createElement ( "span" );
31+
span.className = 'username';
32+
span.setAttribute ( "username", "testcharacterUSN" );
33+
span.innerHTML = "K2 TestCharacter";
34+
35+
expect ( idrinth.names.parse ( span ) ).toEqual ( "testcharacterUSN" );
36+
} );
37+
38+
it ( "Should get default attribute", function () {
39+
var span = document.createElement ( "span" );
40+
span.innerHTML = "K2 TestCharacter";
41+
42+
expect ( idrinth.names.parse ( span ) ).toEqual ( "K2 TestCharacter" );
43+
} );
44+
45+
} );
46+
47+
describe ( "Names run method", function () {
48+
49+
beforeAll(function(){
50+
51+
var SPANUsername = {};
52+
document.getElementsByClassName = jasmine.createSpy('HTML Class Elements').andCallFake(function(className) {
53+
if(!SPANUsername[className]) {
54+
SPANUsername[className] = document.createElement('span');
55+
}
56+
return SPANUsername[className];
57+
});
58+
});
59+
60+
it ( "Should run for new names and add them", function () {
61+
62+
var testUser = {
63+
kongregate: { name : 'test'},
64+
world: { name : 'test'}
65+
};
66+
67+
idrinth.names.counter = 300;
68+
idrinth.names.names['testUser'] = testUser;
69+
70+
idrinth.names.run ();
71+
72+
expect ( idrinth.names.users ).toEqual ( 2 );
73+
expect ( idrinth.names.counter ).toEqual ( 121312 );
74+
} );
75+
76+
it ( "Should get attribute with name dotdxname", function () {
77+
78+
idrinth.names.run ();
79+
80+
expect ( idrinth.names.users ).toEqual ( 2 );
81+
expect ( idrinth.names.counter ).toEqual ( 300 );
82+
} );
83+
84+
} );
85+
86+
describe ( "Names start method for kongregate", function () {
87+
88+
it ( "Should start names for kongregate", function () {
89+
// idrinth.ui.tooltip
90+
// idrinth.ui.base
91+
// idrinth.ui.updateClassesList
92+
// idrinth.settings.get
93+
// idrinth.ui.setTooltipTimeout
94+
// idrinth.ui.getElementPositioning
95+
96+
spyOn(idrinth.core.multibind, 'add');
97+
spyOn(idrinth.core.timeouts, 'add');
98+
99+
idrinth.names.run ();
100+
101+
expect(idrinth.core.multibind.add).toHaveBeenCalled();
102+
expect(idrinth.core.multibind.add).toHaveBeenCalledTimes(1);
103+
104+
expect(idrinth.core.timeouts.add).toHaveBeenCalled();
105+
expect(idrinth.core.timeouts.add).toHaveBeenCalledTimes(1);
106+
});
107+
108+
} );
109+
} );

tests/mods/settingsSpec.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
describe ( 'Settings.js tests', function () {
2+
3+
it ( 'should have a idrinth variable in scope', function () {
4+
expect ( idrinth ).toBeDefined ();
5+
} );
6+
7+
it ( 'should have default values defined', function () {
8+
var defaults = {
9+
raids: false,
10+
favs: '',
11+
factor: true,
12+
moveLeft: false,
13+
minimalist: false,
14+
chatHiddenOnStart: true,
15+
names: true,
16+
timeout: 5000,
17+
loadtime: 5000,
18+
windows: 3,
19+
warBottom: false,
20+
landMax: true,
21+
chatting: true,
22+
chatuser: '',
23+
newgroundLoad: 30,
24+
chatpass: '',
25+
isWorldServer: false,
26+
alarmTime: '8:0',
27+
alarmActive: false,
28+
bannedRaids: {},
29+
language: 'en',
30+
notification: {
31+
mention: true,
32+
message: true,
33+
raid: true
34+
},
35+
land: {
36+
cornfield: 0,
37+
stable: 0,
38+
barn: 0,
39+
store: 0,
40+
pub: 0,
41+
inn: 0,
42+
tower: 0,
43+
fort: 0,
44+
castle: 0,
45+
gold: 0
46+
}
47+
};
48+
49+
var copySettings = JSON.parse ( JSON.stringify ( idrinth.settings ) );
50+
51+
//CleanUP functions -> not part of the test
52+
for ( var i in copySettings ) {
53+
if ( copySettings.hasOwnProperty ( i ) && typeof copySettings[ i ] === 'function' ) {
54+
delete copySettings[ i ];
55+
}
56+
}
57+
58+
expect ( copySettings ).toEqual ( defaults );
59+
} );
60+
61+
} );

0 commit comments

Comments
 (0)