Compare commits

...

6 Commits

Author SHA1 Message Date
felixlinker
59b6945fee Allow testmode for ReactGA 2018-10-21 23:43:56 +01:00
felixlinker
4613e7ca7a Replace local storage variables with class in tests 2018-10-21 23:42:27 +01:00
felixlinker
3315570edf eslint fixes 2018-10-21 23:42:27 +01:00
felixlinker
1fd545ba1f Add new keys to test fixtures 2018-10-21 23:42:27 +01:00
felixlinker
25839de1fe Loop ships outside of test for meaningfull error messages 2018-10-21 23:42:27 +01:00
felixlinker
15feff9344 Don't test or describe fullTankRange because it is not used 2018-10-21 23:42:27 +01:00
12 changed files with 101 additions and 106 deletions

View File

@@ -275,11 +275,11 @@
"totalCost": 882362060,
"unladenMass": 1179.2,
"totalDps": 29,
"passengerCapacity": 0,
"powerAvailable": 36,
"powerRetracted": 23.33,
"powerDeployed": 34.76,
"unladenRange": 18.49,
"fullTankRange": 18.12,
"ladenRange": 16.39,
"unladenFastestRange": 73.21,
"ladenFastestRange": 66.15,

View File

@@ -287,6 +287,7 @@
"totalThermSDps": 58.64,
"baseShieldStrength": 350,
"baseArmour": 945,
"hullCausRes": 0,
"hullExplRes": 0.22,
"hullKinRes": 0.27,
"hullMass": 400,
@@ -303,13 +304,13 @@
"armour": 2227.5,
"baseArmour": 525,
"unladenMass": 1163.2,
"passengerCapacity": 0,
"powerAvailable": 39.6,
"powerRetracted": 23.33,
"powerDeployed": 34.13,
"roll": 60,
"unladenRange": 18.74,
"yaw": 10,
"fullTankRange": 18.36,
"hardness": 65,
"ladenRange": 16.59,
"unladenFastestRange": 74.2,

View File

@@ -237,14 +237,15 @@
"shieldExplRes": 0.5,
"shieldKinRes": 0.6,
"shieldThermRes": 1.2,
"hullCausRes": 0,
"hullExplRes": 1.4,
"hullKinRes": 1.2,
"hullThermRes": 1,
"passengerCapacity": 0,
"powerAvailable": 20.41,
"powerRetracted": 11.91,
"powerDeployed": 11.91,
"unladenRange": 50.45,
"fullTankRange": 47.03,
"ladenRange": 42.71,
"unladenFastestRange": 317.24,
"ladenFastestRange": 287.02,

View File

@@ -309,14 +309,15 @@
"shieldExplRes": 0.48,
"shieldKinRes": 0.55,
"shieldThermRes": 1.09,
"hullCausRes": 0,
"hullExplRes": 1.4,
"hullKinRes": 1.2,
"hullThermRes": 1,
"passengerCapacity": 0,
"powerAvailable": 17.24,
"powerRetracted": 11.3,
"powerDeployed": 16.41,
"unladenRange": 25.57,
"fullTankRange": 23.92,
"ladenRange": 22.09,
"unladenFastestRange": 116.23,
"ladenFastestRange": 107,

View File

@@ -115,7 +115,6 @@
"powerRetracted": 7.21,
"powerDeployed": 7.21,
"unladenRange": 32.48,
"fullTankRange": 30.27,
"ladenRange": 19.61,
"unladenFastestRange": 176.71,
"ladenFastestRange": 112.92,
@@ -249,7 +248,6 @@
"powerRetracted": 9.33,
"powerDeployed": 10.33,
"unladenRange": 30.24,
"fullTankRange": 28.32,
"ladenRange": 19.8,
"unladenFastestRange": 164.89,
"ladenFastestRange": 114.03,
@@ -379,7 +377,6 @@
"powerRetracted": 7.28,
"powerDeployed": 8.06,
"unladenRange": 31.71,
"fullTankRange": 29.61,
"ladenRange": 23.58,
"unladenFastestRange": 172.68,
"ladenFastestRange": 136.46,
@@ -511,7 +508,6 @@
"powerRetracted": 8.81,
"powerDeployed": 8.81,
"unladenRange": 26.41,
"fullTankRange": 24.97,
"ladenRange": 17.36,
"unladenFastestRange": 172.04,
"ladenFastestRange": 118.55,
@@ -653,7 +649,6 @@
"powerRetracted": 10.66,
"powerDeployed": 11.66,
"unladenRange": 25.77,
"fullTankRange": 24.39,
"ladenRange": 17.98,
"unladenFastestRange": 167.93,
"ladenFastestRange": 122.84,
@@ -791,7 +786,6 @@
"powerRetracted": 8.95,
"powerDeployed": 9.73,
"unladenRange": 19.27,
"fullTankRange": 18.95,
"ladenRange": 15.43,
"unladenFastestRange": 67.34,
"ladenFastestRange": 54.75,
@@ -954,7 +948,6 @@
"powerRetracted": 15.49,
"powerDeployed": 19.43,
"unladenRange": 27.1,
"fullTankRange": 25.58,
"ladenRange": 21.94,
"unladenFastestRange": 176.39,
"ladenFastestRange": 150.58,
@@ -1096,7 +1089,6 @@
"powerRetracted": 10.38,
"powerDeployed": 12.58,
"unladenRange": 26.01,
"fullTankRange": 25.42,
"ladenRange": 17.19,
"unladenFastestRange": 90.67,
"ladenFastestRange": 61.04,
@@ -1260,7 +1252,6 @@
"powerRetracted": 19.35,
"powerDeployed": 25.31,
"unladenRange": 15.19,
"fullTankRange": 14.99,
"ladenRange": 14.99,
"unladenFastestRange": 53.15,
"ladenFastestRange": 53.15,
@@ -1360,7 +1351,6 @@
"powerRetracted": 10.7,
"powerDeployed": 10.7,
"unladenRange": 24.25,
"fullTankRange": 23.73,
"ladenRange": 23.73,
"unladenFastestRange": 84.56,
"ladenFastestRange": 84.56,
@@ -1499,7 +1489,6 @@
"powerRetracted": 13.13,
"powerDeployed": 13.13,
"unladenRange": 19.51,
"fullTankRange": 18.58,
"ladenRange": 13.09,
"unladenFastestRange": 152.32,
"ladenFastestRange": 106.49,
@@ -1637,7 +1626,6 @@
"powerRetracted": 10.25,
"powerDeployed": 10.25,
"unladenRange": 28.25,
"fullTankRange": 26.6,
"ladenRange": 16.67,
"unladenFastestRange": 183.67,
"ladenFastestRange": 113.69,
@@ -1808,7 +1796,6 @@
"powerRetracted": 19.34,
"powerDeployed": 26.18,
"unladenRange": 20.32,
"fullTankRange": 19.46,
"ladenRange": 14.65,
"unladenFastestRange": 133.17,
"ladenFastestRange": 99.65,
@@ -1987,7 +1974,6 @@
"powerRetracted": 22.61,
"powerDeployed": 29.63,
"unladenRange": 14.32,
"fullTankRange": 13.89,
"ladenRange": 13.46,
"unladenFastestRange": 94.42,
"ladenFastestRange": 91.49,
@@ -2217,7 +2203,6 @@
"powerRetracted": 25.88,
"powerDeployed": 37.51,
"unladenRange": 16.99,
"fullTankRange": 16.68,
"ladenRange": 15.91,
"unladenFastestRange": 67.35,
"ladenFastestRange": 64.2,
@@ -2372,7 +2357,6 @@
"powerRetracted": 11.92,
"powerDeployed": 11.92,
"unladenRange": 39.26,
"fullTankRange": 37.65,
"ladenRange": 21.21,
"unladenFastestRange": 153.79,
"ladenFastestRange": 85.82,
@@ -2528,7 +2512,6 @@
"powerRetracted": 12.49,
"powerDeployed": 12.49,
"unladenRange": 38.44,
"fullTankRange": 36.89,
"ladenRange": 21.04,
"unladenFastestRange": 150.62,
"ladenFastestRange": 85.16,
@@ -2696,7 +2679,6 @@
"powerRetracted": 13,
"powerDeployed": 12.4,
"unladenRange": 38.04,
"fullTankRange": 30.11,
"ladenRange": 23.03,
"unladenFastestRange": 675.7,
"ladenFastestRange": 501.97,
@@ -2914,7 +2896,6 @@
"powerRetracted": 23.93,
"powerDeployed": 35.56,
"unladenRange": 18.49,
"fullTankRange": 18.12,
"ladenRange": 16.39,
"unladenFastestRange": 73.21,
"ladenFastestRange": 66.15,
@@ -3042,7 +3023,6 @@
"powerRetracted": 8.48,
"powerDeployed": 7.88,
"unladenRange": 35.99,
"fullTankRange": 33.36,
"ladenRange": 33.36,
"unladenFastestRange": 232.28,
"ladenFastestRange": 232.28,
@@ -3179,7 +3159,6 @@
"powerRetracted": 14.87,
"powerDeployed": 17.51,
"unladenRange": 15.06,
"fullTankRange": 14.86,
"ladenRange": 14.86,
"unladenFastestRange": 42.5,
"ladenFastestRange": 42.5,
@@ -3333,7 +3312,6 @@
"powerRetracted": 17.71,
"powerDeployed": 23.14,
"unladenRange": 12.51,
"fullTankRange": 12.38,
"ladenRange": 12.38,
"unladenFastestRange": 35.35,
"ladenFastestRange": 35.35,
@@ -3452,7 +3430,6 @@
"powerRetracted": 9.46,
"powerDeployed": 11.17,
"unladenRange": 17.12,
"fullTankRange": 16.71,
"ladenRange": 16.71,
"unladenFastestRange": 42.4,
"ladenFastestRange": 42.4,
@@ -3610,7 +3587,6 @@
"powerRetracted": 9.31,
"powerDeployed": 13.91,
"unladenRange": 8.43,
"fullTankRange": 8.09,
"ladenRange": 7.25,
"unladenFastestRange": 81.5,
"ladenFastestRange": 72.9,

View File

@@ -6,41 +6,70 @@ import TU from 'react-testutils-additions';
let origAddEventListener = window.addEventListener;
let storageListener;
let ls = {};
// Implment mock localStorage
let localStorage = {
getItem: function(key) {
return ls[key];
},
setItem: function(key, value) {
ls[key] = value;
},
removeItem: function(key) {
delete ls[key];
},
clear: function() {
ls = {};
/**
* Mock local storage
*/
class LocalStorage {
/**
* Sets up storage variable
*/
constructor() {
this.ls = {};
}
/**
* Retrieves a value from local storage
* @param {String} key Storage key
* @return {*} Storage value
*/
getItem(key) {
return this.ls[key];
}
/**
* Writes a value to local storage
* @param {String} key Storage key
* @param {*} value Storage value
*/
setItem(key, value) {
this.ls[key] = value;
}
/**
* Clears a value from local storage
* @param {String} key Storage key
*/
removeItem(key) {
delete this.ls[key];
}
/**
* Clears local storage
*/
clear() {
this.ls = {};
}
}
window.addEventListener = function(eventName, listener) {
const LOCAL_STORAGE = new LocalStorage();
window.addEventListener = function(eventName, listener) {
if(eventName == 'storage') {
storageListener = listener; // Keep track of latest storage listener
} else {
origAddEventListener.apply(arguments);
}
}
};
describe('Persist', function() {
const Persist = require('../src/app/stores/Persist').Persist;
describe('Multi tab/window', function() {
it("syncs builds", function() {
window.localStorage = localStorage;
ls = {};
localStorage.clear();
let p = new Persist();
let newBuilds = {
anaconda: { test: '1234' }
@@ -54,7 +83,8 @@ describe('Persist', function() {
describe('General and Settings', function() {
it("has defaults", function() {
window.localStorage = localStorage;
ls = {};
localStorage.clear();
let p = new Persist();
expect(p.getLangCode()).toBe('en');
expect(p.showTooltips()).toBe(true);
@@ -65,14 +95,14 @@ describe('Persist', function() {
});
it("loads from localStorage correctly", function() {
window.localStorage = localStorage;
window.localStorage = LOCAL_STORAGE;
let savedData = require('./fixtures/valid-backup');
ls = {};
ls.builds = JSON.stringify(savedData.builds);
ls.NG_TRANSLATE_LANG_KEY = 'de';
ls.insurance = 'Standard';
ls.shipDiscount = 0.25;
ls.moduleDiscount = 0.15;
LOCAL_STORAGE.clear();
LOCAL_STORAGE.setItem('builds', JSON.stringify(savedData.builds));
LOCAL_STORAGE.setItem('NG_TRANSLATE_LANG_KEY', 'de');
LOCAL_STORAGE.setItem('insurance', 'Standard');
LOCAL_STORAGE.setItem('shipDiscount', 0.25);
LOCAL_STORAGE.setItem('moduleDiscount', 0.15);
let p = new Persist();
expect(p.getInsurance()).toBe('standard');
@@ -86,13 +116,13 @@ describe('Persist', function() {
});
it("uses defaults from a corrupted localStorage", function() {
window.localStorage = localStorage;
ls = {};
ls.builds = "not valid json";
ls.comparisons = "1, 3, 4";
ls.insurance = 'this insurance does not exist';
ls.shipDiscount = 'this is not a number';
ls.moduleDiscount = 10; // Way to big
window.localStorage = LOCAL_STORAGE;
LOCAL_STORAGE.clear();
LOCAL_STORAGE.setItem('builds', 'not valid json');
LOCAL_STORAGE.setItem('comparisons', '1, 3, 4');
LOCAL_STORAGE.setItem('insurance', 'this insurance does not exist');
LOCAL_STORAGE.setItem('shipDiscount', 'this is not a number');
LOCAL_STORAGE.setItem('moduleDiscount', 10); // Way to big
let p = new Persist();
expect(p.getLangCode()).toBe('en');
@@ -122,13 +152,13 @@ describe('Persist', function() {
});
it("generates the backup", function() {
window.localStorage = localStorage;
window.localStorage = LOCAL_STORAGE;
let savedData = require('./fixtures/valid-backup');
ls = {};
ls.builds = JSON.stringify(savedData.builds);
ls.insurance = 'Beta';
ls.shipDiscount = 0.25;
ls.moduleDiscount = 0.15;
LOCAL_STORAGE.clear();
LOCAL_STORAGE.setItem('builds', JSON.stringify(savedData.builds));
LOCAL_STORAGE.setItem('insurance', 'Beta');
LOCAL_STORAGE.setItem('shipDiscount', 0.25);
LOCAL_STORAGE.setItem('moduleDiscount', 0.15);
let p = new Persist();
let backup = p.getAll();
@@ -140,4 +170,4 @@ describe('Persist', function() {
expect(backup.comparisons).toEqual({});
});
});
})
});

View File

@@ -3,32 +3,31 @@ import { Ships } from 'coriolis-data/dist';
import * as ModuleUtils from '../src/app/shipyard/ModuleUtils';
describe("Ship", function() {
it("can build all ships", function() {
for (let s in Ships) {
for (let s in Ships) {
it("can build " + s, function() {
let shipData = Ships[s];
let ship = new Ship(s, shipData.properties, shipData.slots);
for (let p in shipData.properties) {
expect(ship[p]).toEqual(shipData.properties[p], s + ' property [' + p + '] does not match when built');
expect(ship[p]).toEqual(shipData.properties[p]);
}
ship.buildWith(shipData.defaults);
expect(ship.totalCost).toEqual(shipData.retailCost, s + ' retail cost does not match default build cost');
expect(ship.totalCost).toEqual(shipData.retailCost);
expect(ship.cargoCapacity).toBeDefined();
expect(ship.priorityBands[0].retracted).toBeGreaterThan(0, s + ' priorityBands');
expect(ship.powerAvailable).toBeGreaterThan(0, s + ' powerAvailable');
expect(ship.unladenRange).toBeGreaterThan(0, s + ' unladenRange');
expect(ship.ladenRange).toBeGreaterThan(0, s + ' ladenRange');
expect(ship.fuelCapacity).toBeGreaterThan(0, s + ' fuelCapacity');
expect(ship.unladenFastestRange).toBeGreaterThan(0, s + ' unladenFastestRange');
expect(ship.ladenFastestRange).toBeGreaterThan(0, s + ' ladenFastestRange');
expect(ship.shield).toBeGreaterThan(0, s + ' shield');
expect(ship.armour).toBeGreaterThan(0, s + ' armour');
expect(ship.topSpeed).toBeGreaterThan(0, s + ' topSpeed');
}
});
expect(ship.priorityBands[0].retracted).toBeGreaterThan(0);
expect(ship.powerAvailable).toBeGreaterThan(0);
expect(ship.unladenRange).toBeGreaterThan(0);
expect(ship.ladenRange).toBeGreaterThan(0);
expect(ship.fuelCapacity).toBeGreaterThan(0);
expect(ship.unladenFastestRange).toBeGreaterThan(0);
expect(ship.ladenFastestRange).toBeGreaterThan(0);
expect(ship.shield).toBeGreaterThan(0);
expect(ship.armour).toBeGreaterThan(0);
expect(ship.topSpeed).toBeGreaterThan(0);
});
}
it("resets and rebuilds properly", function() {
var id = 'cobra_mk_iii';

View File

@@ -1,6 +1,13 @@
// Check whether a test is run because then we need to
// initialize ReactGA in test mode
let isTest = false;
try {
isTest = process.env.node_env === 'test';
} catch (e) {}
import Persist from './stores/Persist';
import ReactGA from 'react-ga';
ReactGA.initialize('UA-55840909-18');
ReactGA.initialize('UA-55840909-18', { testMode: isTest });
let standalone = undefined;
/**

View File

@@ -227,11 +227,6 @@
"type": "integer",
"minimum": 1
},
"fullTankRange": {
"description": "Single Jump range with a full tank (unladenMass + fuel)",
"type": "number",
"minimum": 0
},
"ladenMass": {
"description": "Mass of the Ship + fuel + cargo (hull + all components + fuel tank + cargo capacity)",
"type": "number",

View File

@@ -254,11 +254,6 @@
"type": "integer",
"minimum": 1
},
"fullTankRange": {
"description": "Single Jump range with a full tank (unladenMass + fuel)",
"type": "number",
"minimum": 0
},
"ladenMass": {
"description": "Mass of the Ship + fuel + cargo (hull + all components + fuel tank + cargo capacity)",
"type": "number",

View File

@@ -258,11 +258,6 @@
"type": "integer",
"minimum": 1
},
"fullTankRange": {
"description": "Single Jump range with a full tank (unladenMass + fuel)",
"type": "number",
"minimum": 0
},
"ladenMass": {
"description": "Mass of the Ship + fuel + cargo (hull + all components + fuel tank + cargo capacity)",
"type": "number",

View File

@@ -300,11 +300,6 @@
"type": "integer",
"minimum": 1
},
"fullTankRange": {
"description": "Single Jump range with a full tank (unladenMass + fuel)",
"type": "number",
"minimum": 0
},
"ladenMass": {
"description": "Mass of the Ship + fuel + cargo (hull + all components + fuel tank + cargo capacity)",
"type": "number",