Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add karma / mocha tests #392

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ The node.js, browser-sync and Docker methods options will serve the website on p

Note that if you're using Docker on Windows or OS X via VirtualBox, you'll have to use the IP address of the Linux VM (usually 192.168.99.100) that is hosting Docker, instead of `localhost`. The Dockerfile.dev method will mount the app source as a volume so changes will be reflected when the browser is refreshed.

### Running test cases

Install [node.js](https://nodejs.org/) and run:
* `npm install`
* `npm test`

You can use Google Chrome to debug test cases using DevTools:
* `npm test:watch:chrome`

### Translations

Localization files can be found in `app/locale`. The `app/locale/en.json` file is purposefully missing because the English strings are used as the translation keys. Strings which require interpolation are defined in app.js so that they can be displayed immediately as a fallback until the actual locale json file finishes loading.
38 changes: 37 additions & 1 deletion app/data/recipedb/Armorer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16437,5 +16437,41 @@
"stars": 3,
"suggestedControl": 2195,
"suggestedCraftsmanship": 2480
},
{
"baseLevel": 80,
"difficulty": 3943,
"durability": 80,
"id": "7357b87dbbd",
"level": 430,
"maxQuality": 18262,
"name": {
"cn": "Oddly Specific Wire",
"de": "Oddly Specific Wire",
"en": "Oddly Specific Wire",
"fr": "Oddly Specific Wire",
"ja": "Oddly Specific Wire",
"ko": "Oddly Specific Wire"
},
"stars": 0,
"suggestedCraftsmanship": 1866
},
{
"baseLevel": 80,
"difficulty": 4343,
"durability": 70,
"id": "af91eefbcf4",
"level": 450,
"maxQuality": 23395,
"name": {
"cn": "Oddly Specific Chainmail Sheet",
"de": "Oddly Specific Chainmail Sheet",
"en": "Oddly Specific Chainmail Sheet",
"fr": "Oddly Specific Chainmail Sheet",
"ja": "Oddly Specific Chainmail Sheet",
"ko": "Oddly Specific Chainmail Sheet"
},
"stars": 2,
"suggestedCraftsmanship": 2140
}
]
]
41 changes: 41 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = function( config ) {
config.set( {
browsers: [ 'jsdom' ],
frameworks: [ 'mocha' ],

plugins: [
'karma-chrome-launcher',
'karma-jsdom-launcher',
'karma-mocha',
'karma-mocha-reporter',
'karma-sourcemap-loader',
'karma-webpack',
],

files: [
// since it's not a module, we include it directly
'app/lib/string/String.js',
'app/js/actions.js',
'app/js/ffxivcraftmodel.js',
'test/**/*Test.js',
],

preprocessors: {
'app/**/*.js': [ 'sourcemap' ],
'test/**/*.js': [ 'webpack', 'sourcemap' ],
},

reporters: [
'mocha',
],

mochaReporter: {
output: 'autowatch',
},

webpack: {
mode: 'development',
},

});
};
18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@
"serve-static": "^1.10.0"
},
"devDependencies": {
"browser-sync": "^2.23.6"
"assert": "^2.0.0",
"browser-sync": "^2.23.6",
"jsdom": "^16.2.2",
"karma": "^5.0.1",
"karma-chrome-launcher": "^3.1.0",
"karma-jsdom-launcher": "^8.0.2",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^4.0.2",
"mocha": "^7.1.1",
"webpack": "^4.42.1"
},
"scripts": {
"test": "karma start karma.conf.js --single-run",
"test:watch": "karma start karma.conf.js --no-single-run",
"test:watch:chrome": "karma start karma.conf.js --no-single-run --browsers Chrome"
}
}
28 changes: 28 additions & 0 deletions test/OddlySpecificChainmailSheetTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import assert from "assert";
import ArmorerRecipes from "../app/data/recipedb/Armorer";
import simFinalState from "./simFinalState";

const CRAFTER = new Crafter('Armorer', 80, 2535, 2163, 486, false, AllActions);

const RECIPE = {
startQuality: 0,
...ArmorerRecipes.find( ({id}) => id === 'af91eefbcf4' ),
};
RECIPE.suggestedCraftsmanship = RECIPE.suggestedCraftsmanship || SuggestedCraftsmanship[RECIPE.level];
RECIPE.suggestedControl = RECIPE.suggestedControl || SuggestedControl[RECIPE.level];

describe("Oddly Specific Chainmail Sheet", () => {
it("First Reflect: Quality increases by 482", () => {
var finalState = simFinalState( CRAFTER, RECIPE, [
AllActions.reflect
] );
assert.equal(482, finalState.qualityState);
});
it("Reflect, Groundwork increases progress by 1323", () => {
var finalState = simFinalState( CRAFTER, RECIPE, [
AllActions.reflect,
AllActions.groundwork
] );
assert.equal(1323, finalState.progressState);
});
});
33 changes: 33 additions & 0 deletions test/ffxivcraftmodelTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import assert from "assert";
import simFinalState from "./simFinalState";

const INIT_CP = 180;

describe("FFXIV Crafting Model", () => {

it("Can craft Zelkova Fishing Rod with 3 basic synth", () => {
var crafter = new Crafter('Carpenter', 80, 2000, 0, INIT_CP, false, AllActions);
// Zelkova Fishing Rod
var recipe = new Recipe(70, 290, 2214, 80, 0, 11736, 1076, undefined);
var sequence = [ AllActions.basicSynth2, AllActions.basicSynth2, AllActions.basicSynth2 ];
var finalState = simFinalState( crafter, recipe, sequence );

assert.equal(finalState.cpState, INIT_CP);
assert.equal(finalState.lastStep, 3);
assert.equal(finalState.progressState, 2466);
assert.equal(finalState.step, 3);
});

it("Will not craft Zelkova Fishing Rod with only 2 basic synth", () => {
var crafter = new Crafter('Carpenter', 80, 2000, 0, INIT_CP, false, AllActions);
// Zelkova Fishing Rod
var recipe = new Recipe(70, 290, 2214, 80, 0, 11736, 1076, undefined);
var sequence = [ AllActions.basicSynth2, AllActions.basicSynth2 ];
var finalState = simFinalState( crafter, recipe, sequence );

assert.equal(finalState.cpState, INIT_CP);
assert.equal(finalState.lastStep, 2);
assert.equal(finalState.progressState, 1644);
assert.equal(finalState.step, 2);
});
});
16 changes: 16 additions & 0 deletions test/simFinalState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default function simFinalState( crafter, recipe, sequence ) {
var synth = new Synth(crafter, recipe, 0, 1.0, false, 0);
var startState = NewStateFromSynth(synth);

var synth = new Synth(crafter, recipe, 0, 1.0, true, 0);
var synthNoConditions = new Synth(crafter, recipe, 0, 1.0, false, 0);

var init = {
seed: Math.seed,
synth: synth,
startState: NewStateFromSynth(synth),
startStateNoConditions: NewStateFromSynth(synthNoConditions),
sequence: sequence
};
return simSynth(sequence, startState, false, true, true, undefined);
}