Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Commit

Permalink
Continued porting to react, approaching beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin McLeod committed Jan 22, 2016
1 parent 653cb30 commit 8227a4e
Show file tree
Hide file tree
Showing 86 changed files with 3,799 additions and 2,019 deletions.
21 changes: 2 additions & 19 deletions .babelrc
@@ -1,20 +1,3 @@
{
"stage": 0,
"env": {
"development": {
"plugins": ["react-transform"],
"extra": {
"react-transform": {
"transforms": [{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
}, {
"transform": "react-transform-catch-errors",
"imports": ["react", "redbox-react"]
}]
}
}
}
}
}
"presets": ["es2015", "react", "stage-0"]
}
@@ -1,12 +1,12 @@
{
"$schema": "http://cdn.coriolis.io/schemas/ship-loadout/2.json#",
"$schema": "http://cdn.coriolis.io/schemas/ship-loadout/3.json#",
"name": "Test",
"ship": "Anaconda",
"references": [
{
"name": "Coriolis.io",
"url": "http://localhost:3300/outfit/anaconda/48A6A6A5A8A8A5C2c0o0o0o1m1m0q0q0404-0l0b0100034k5n052d04--0303326b.Iw18QDBNA%3D%3D%3D.AwhMJBGaei%2BJCyyiA%3D%3D%3D?bn=Test",
"code": "48A6A6A5A8A8A5C2c0o0o0o1m1m0q0q0404-0l0b0100034k5n052d04--0303326b.Iw18QDBNA===.AwhMJBGaei+JCyyiA===",
"url": "http://localhost:3300/outfit/anaconda/48A6A6A5A8A8A5C2c0o0o0o1m1m0q0q0404-0l0b0100034k5n052d04--0303326b.AwRj4zNKqA==.CwBhCYzBGW9qCTSqs5xA?bn=Test?bn=Test",
"code": "48A6A6A5A8A8A5C2c0o0o0o1m1m0q0q0404-0l0b0100034k5n052d04--0303326b.AwRj4zNKqA==.CwBhCYzBGW9qCTSqs5xA",
"shipId": "anaconda"
}
],
Expand Down Expand Up @@ -264,12 +264,12 @@
"masslock": 23,
"pipSpeed": 0.14,
"shipCostMultiplier": 1,
"componentCostMultiplier": 1,
"moduleCostMultiplier": 1,
"fuelCapacity": 32,
"cargoCapacity": 128,
"ladenMass": 1339.2,
"armour": 2078,
"armourAdded": 240,
"armour": 2228,
"armourAdded": 390,
"armourMultiplier": 1.95,
"shieldMultiplier": 1.4,
"totalCost": 882362060,
Expand Down
File renamed without changes.
@@ -1,4 +1,4 @@
describe('Import Controller', function() {
xdescribe('Import Controller', function() {
beforeEach(module('app'));

var importController, $rootScope, $stateParams, scope;
Expand Down
54 changes: 54 additions & 0 deletions __tests__/test-service-serializer.js
@@ -0,0 +1,54 @@
import Ship from '../src/app/shipyard/Ship';
import { Ships } from 'coriolis-data';
import * as Serializer from '../src/app/shipyard/Serializer';

describe("Serializer Service", function() {

const anacondaTestExport = require.requireActual('./fixtures/anaconda-test-detailed-export-v3');
const code = anacondaTestExport.references[0].code;
const anaconda = Ships.anaconda;

describe("To Detailed Build", function() {

let testBuild, exportData;

beforeEach(function() {
testBuild = new Ship('anaconda', anaconda.properties, anaconda.slots);
testBuild.buildFrom(code);
exportData = Serializer.toDetailedBuild('Test', testBuild);
});

xit("conforms to the v2 ship-loadout schema", function() {
// var validate = jsen(require('../schemas/ship-loadout/3'));
// var valid = validate(exportData);
expect(valid).toBeTruthy();
});

it("contains the correct components and stats", function() {
expect(exportData.components).toEqual(anacondaTestExport.components);
expect(exportData.stats).toEqual(anacondaTestExport.stats);
expect(exportData.ship).toEqual(anacondaTestExport.ship);
expect(exportData.name).toEqual(anacondaTestExport.name);
});

});

describe("From Detailed Build", function() {

it("builds the ship correctly", function() {
let testBuildA = new Ship('anaconda', anaconda.properties, anaconda.slots);
testBuildA.buildFrom(code);
let testBuildB = Serializer.fromDetailedBuild(anacondaTestExport);

for(var p in testBuildB) {
if (p == 'availCS') {
continue;
}
expect(testBuildB[p]).toEqual(testBuildA[p], p + ' does not match');
}

});

});

});
75 changes: 35 additions & 40 deletions test/tests/test-factory-ship.js → __tests__/test-ship.js
@@ -1,20 +1,15 @@
describe("Ship Factory", function() {

var Ship;
var Components;
import Ship from '../src/app/shipyard/Ship';
import { Ships } from 'coriolis-data';
import * as ModuleUtils from '../src/app/shipyard/ModuleUtils';

beforeEach(module('shipyard'));
beforeEach(inject(['Ship', 'Components', function (_Ship_, _Components_) {
Ship = _Ship_;
Components = _Components_;
}]));
describe("Ship Factory", function() {

it("can build all ships", function() {
for (var s in DB.ships) {
var shipData = DB.ships[s];
var ship = new Ship(s, shipData.properties, shipData.slots);
for (let s in Ships) {
let shipData = Ships[s];
let ship = new Ship(s, shipData.properties, shipData.slots);

for (p in shipData.properties) {
for (let p in shipData.properties) {
expect(ship[p]).toEqual(shipData.properties[p], s + ' property [' + p + '] does not match when built');
}

Expand All @@ -37,7 +32,7 @@ describe("Ship Factory", function() {

it("resets and rebuilds properly", function() {
var id = 'cobra_mk_iii';
var cobra = DB.ships[id];
var cobra = Ships[id];
var shipA = new Ship(id, cobra.properties, cobra.slots);
var shipB = new Ship(id, cobra.properties, cobra.slots);
var testShip = new Ship(id, cobra.properties, cobra.slots);
Expand Down Expand Up @@ -81,84 +76,84 @@ describe("Ship Factory", function() {

it("discounts hull and components properly", function() {
var id = 'cobra_mk_iii';
var cobra = DB.ships[id];
var cobra = Ships[id];
var testShip = new Ship(id, cobra.properties, cobra.slots);
testShip.buildWith(cobra.defaults);

var originalHullCost = testShip.hullCost;
var originalTotalCost = testShip.totalCost;
var discount = 0.9;

expect(testShip.c.discountedCost).toEqual(originalHullCost, 'Hull cost does not match');
expect(testShip.m.discountedCost).toEqual(originalHullCost, 'Hull cost does not match');

testShip.applyDiscounts(discount, discount);

// Floating point errors cause miniscule decimal places which are handled in the app by rounding/formatting

expect(Math.floor(testShip.c.discountedCost)).toEqual(Math.floor(originalHullCost * discount), 'Discounted Hull cost does not match');
expect(Math.floor(testShip.m.discountedCost)).toEqual(Math.floor(originalHullCost * discount), 'Discounted Hull cost does not match');
expect(Math.floor(testShip.totalCost)).toEqual(Math.floor(originalTotalCost * discount), 'Discounted Total cost does not match');

testShip.applyDiscounts(1, 1); // No discount, 100% of cost

expect(testShip.c.discountedCost).toEqual(originalHullCost, 'Hull cost does not match');
expect(testShip.m.discountedCost).toEqual(originalHullCost, 'Hull cost does not match');
expect(testShip.totalCost).toEqual(originalTotalCost, 'Total cost does not match');

testShip.applyDiscounts(discount, 1); // Only discount hull

expect(Math.floor(testShip.c.discountedCost)).toEqual(Math.round(originalHullCost * discount), 'Discounted Hull cost does not match');
expect(testShip.totalCost).toEqual(originalTotalCost - originalHullCost + testShip.c.discountedCost, 'Total cost does not match');
expect(Math.floor(testShip.m.discountedCost)).toEqual(Math.round(originalHullCost * discount), 'Discounted Hull cost does not match');
expect(testShip.totalCost).toEqual(originalTotalCost - originalHullCost + testShip.m.discountedCost, 'Total cost does not match');

});

it("enforces a single shield generator", function() {
var id = 'anaconda';
var anacondaData = DB.ships[id];
var anacondaData = Ships[id];
var anaconda = new Ship(id, anacondaData.properties, anacondaData.slots);
anaconda.buildWith(anacondaData.defaults);

expect(anaconda.internal[2].c.grp).toEqual('sg', 'Anaconda default shield generator slot');
expect(anaconda.internal[2].m.grp).toEqual('sg', 'Anaconda default shield generator slot');

anaconda.use(anaconda.internal[1], '4j', Components.internal('4j')); // 6E Shield Generator
anaconda.use(anaconda.internal[1], ModuleUtils.internal('4j')); // 6E Shield Generator

expect(anaconda.internal[2].c).toEqual(null, 'Anaconda default shield generator slot is empty');
expect(anaconda.internal[2].id).toEqual(null, 'Anaconda default shield generator slot id is null');
expect(anaconda.internal[1].id).toEqual('4j', 'Slot 1 should have SG 4j in it');
expect(anaconda.internal[1].c.grp).toEqual('sg','Slot 1 should have SG 4j in it');
expect(anaconda.internal[2].m).toEqual(null, 'Anaconda default shield generator slot id is null');
expect(anaconda.internal[1].m.id).toEqual('4j', 'Slot 1 should have SG 4j in it');
expect(anaconda.internal[1].m.grp).toEqual('sg','Slot 1 should have SG 4j in it');

});

it("enforces a single shield fuel scoop", function() {
var id = 'anaconda';
var anacondaData = DB.ships[id];
var anacondaData = Ships[id];
var anaconda = new Ship(id, anacondaData.properties, anacondaData.slots);
anaconda.buildWith(anacondaData.defaults);

anaconda.use(anaconda.internal[4], '32', Components.internal('32')); // 4A Fuel Scoop
expect(anaconda.internal[4].c.grp).toEqual('fs', 'Anaconda fuel scoop slot');
anaconda.use(anaconda.internal[4], ModuleUtils.internal('32')); // 4A Fuel Scoop
expect(anaconda.internal[4].m.grp).toEqual('fs', 'Anaconda fuel scoop slot');

anaconda.use(anaconda.internal[3], '32', Components.internal('32'));
anaconda.use(anaconda.internal[3], ModuleUtils.internal('32'));

expect(anaconda.internal[4].c).toEqual(null, 'Anaconda original fuel scoop slot is empty');
expect(anaconda.internal[4].id).toEqual(null, 'Anaconda original fuel scoop slot id is null');
expect(anaconda.internal[3].id).toEqual('32', 'Slot 1 should have FS 32 in it');
expect(anaconda.internal[3].c.grp).toEqual('fs','Slot 1 should have FS 32 in it');
expect(anaconda.internal[4].m).toEqual(null, 'Anaconda original fuel scoop slot id is null');
expect(anaconda.internal[3].m.id).toEqual('32', 'Slot 1 should have FS 32 in it');
expect(anaconda.internal[3].m.grp).toEqual('fs','Slot 1 should have FS 32 in it');
});

it("enforces a single refinery", function() {
var id = 'anaconda';
var anacondaData = DB.ships[id];
var anacondaData = Ships[id];
var anaconda = new Ship(id, anacondaData.properties, anacondaData.slots);
anaconda.buildWith(anacondaData.defaults);

anaconda.use(anaconda.internal[4], '23', Components.internal('23')); // 4E Refinery
expect(anaconda.internal[4].c.grp).toEqual('rf', 'Anaconda refinery slot');
anaconda.use(anaconda.internal[4], ModuleUtils.internal('23')); // 4E Refinery
expect(anaconda.internal[4].m.grp).toEqual('rf', 'Anaconda refinery slot');

anaconda.use(anaconda.internal[3], '23', Components.internal('23'));
anaconda.use(anaconda.internal[3], ModuleUtils.internal('23'));

expect(anaconda.internal[4].c).toEqual(null, 'Anaconda original refinery slot is empty');
expect(anaconda.internal[4].id).toEqual(null, 'Anaconda original refinery slot id is null');
expect(anaconda.internal[3].id).toEqual('23', 'Slot 1 should have RF 23 in it');
expect(anaconda.internal[3].c.grp).toEqual('rf','Slot 1 should have RF 23 in it');
expect(anaconda.internal[4].m).toEqual(null, 'Anaconda original refinery slot id is null');
expect(anaconda.internal[3].m.id).toEqual('23', 'Slot 1 should have RF 23 in it');
expect(anaconda.internal[3].m.grp).toEqual('rf','Slot 1 should have RF 23 in it');
});

});
56 changes: 42 additions & 14 deletions package.json
Expand Up @@ -8,39 +8,67 @@
"homepage": "http://coriolis.io",
"bugs": "https://github.com/cmmcleod/coriolis/issues",
"private": true,
"engine": "node >= 0.12.2",
"engine": "node >= 4.0.0",
"license": "MIT",
"scripts": {
"clean": "rimraf build",
"start": "node devServer.js",
"lint": "eslint --ext .js,.jsx src",
"test": "jest",
"prod-serve": "nginx -p $(pwd) -c nginx.conf",
"prod-stop": "kill -QUIT $(cat nginx.pid)",
"build:prod": "npm run clean && NODE_ENV=production CDN='//cdn.coriolis.io' webpack -d -p --config webpack.config.prod.js",
"build": "npm run clean && NODE_ENV=production webpack -d -p --config webpack.config.prod.js",
"rsync": "rsync -e 'ssh -i $CORIOLIS_PEM' -a --delete build/ $CORIOLIS_USER@$CORIOLIS_HOST:~/www",
"deploy": "npm run lint && npm run build && npm run rsync"
"deploy": "npm run lint && npm test && npm run build:prod && npm run rsync"
},
"jest": {
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"testFileExtensions": [
"js"
],
"moduleFileExtensions": [
"js",
"json",
"jsx"
],
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react",
"<rootDir>/node_modules/react-dom",
"<rootDir>/node_modules/react-addons-test-utils",
"<rootDir>/node_modules/fbjs",
"<rootDir>/node_modules/fbemitter",
"<rootDir>/node_modules/classnames",
"<rootDir>/node_modules/d3",
"<rootDir>/node_modules/lz-string",
"<rootDir>/node_modules/coriolis-data",
"<rootDir>/src/app/shipyard",
"<rootDir>/src/app/i18n",
"<rootDir>/src/app/utils"
]
},
"devDependencies": {
"appcache-webpack-plugin": "^1.2.1",
"babel-core": "^5.4.7",
"babel-eslint": "^4.1.6",
"babel-loader": "^5.1.2",
"babel-plugin-react-transform": "^1.1.1",
"css-loader": "^0.23.0",
"eslint": "^1.10.1",
"eslint-plugin-react": "^2.3.0",
"babel-core": "*",
"babel-eslint": "*",
"babel-jest": "*",
"babel-loader": "*",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"css-loader": "^0.23.0",
"eslint": "2.0.0-beta.1",
"eslint-plugin-react": "^3.15.0",
"expose-loader": "^0.7.1",
"express": "^4.13.3",
"extract-text-webpack-plugin": "^0.9.1",
"file-loader": "^0.8.4",
"html-webpack-plugin": "^1.7.0",
"jest-cli": "*",
"json-loader": "^0.5.3",
"less": "^2.5.3",
"less-loader": "^2.2.1",
"react-transform-catch-errors": "^1.0.0",
"react-transform-hmr": "^1.0.0",
"redbox-react": "^1.0.1",
"react-addons-test-utils": "^0.14.6",
"rimraf": "^2.4.3",
"style-loader": "^0.13.0",
"url-loader": "^0.5.6",
Expand All @@ -52,8 +80,8 @@
"d3": "^3.5.9",
"fbemitter": "^2.0.0",
"lz-string": "^1.4.4",
"react": "^0.14.2",
"react-dom": "^0.14.2",
"react": "^0.14.6",
"react-dom": "^0.14.6",
"superagent": "^1.4.0"
}
}

0 comments on commit 8227a4e

Please sign in to comment.