Merge branch 'gt38-add-version-schema'
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
99
src/lib/store/__snapshots__/ship.test.ts.snap
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||||
|
|
||||||
|
exports[`state has the expected shape 1`] = `
|
||||||
|
{
|
||||||
|
"carrier": {
|
||||||
|
"nbrBays": 0,
|
||||||
|
"reqs": {
|
||||||
|
"cost": 0,
|
||||||
|
"mass": 0,
|
||||||
|
},
|
||||||
|
"squadrons": [],
|
||||||
|
},
|
||||||
|
"identification": {
|
||||||
|
"isCarrier": false,
|
||||||
|
"reqs": {
|
||||||
|
"cost": 0,
|
||||||
|
"mass": 10,
|
||||||
|
"usedMass": 0,
|
||||||
|
},
|
||||||
|
"shipClass": "",
|
||||||
|
"shipType": "",
|
||||||
|
},
|
||||||
|
"propulsion": {
|
||||||
|
"drive": {
|
||||||
|
"advanced": false,
|
||||||
|
"rating": 0,
|
||||||
|
"reqs": {
|
||||||
|
"cost": 0,
|
||||||
|
"mass": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"ftl": {
|
||||||
|
"reqs": {
|
||||||
|
"cost": 0,
|
||||||
|
"mass": 0,
|
||||||
|
},
|
||||||
|
"type": "none",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"schemaVersion": "1",
|
||||||
|
"structure": {
|
||||||
|
"armor": {
|
||||||
|
"layers": [],
|
||||||
|
"reqs": {
|
||||||
|
"cost": 0,
|
||||||
|
"mass": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"cargo": {
|
||||||
|
"reqs": {
|
||||||
|
"cost": 0,
|
||||||
|
"mass": 0,
|
||||||
|
},
|
||||||
|
"space": 0,
|
||||||
|
},
|
||||||
|
"hull": {
|
||||||
|
"max": 0,
|
||||||
|
"min": 0,
|
||||||
|
"rating": 0,
|
||||||
|
"reqs": {
|
||||||
|
"cost": 0,
|
||||||
|
"mass": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"screens": {
|
||||||
|
"advanced": 0,
|
||||||
|
"reqs": {
|
||||||
|
"cost": 0,
|
||||||
|
"mass": 0,
|
||||||
|
},
|
||||||
|
"standard": 0,
|
||||||
|
},
|
||||||
|
"streamlining": {
|
||||||
|
"reqs": {
|
||||||
|
"cost": 0,
|
||||||
|
"mass": 0,
|
||||||
|
},
|
||||||
|
"type": "none",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"weaponry": {
|
||||||
|
"adfc": {
|
||||||
|
"rating": 0,
|
||||||
|
"reqs": {
|
||||||
|
"cost": 0,
|
||||||
|
"mass": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"firecons": {
|
||||||
|
"reqs": {
|
||||||
|
"cost": 0,
|
||||||
|
"mass": 0,
|
||||||
|
},
|
||||||
|
"stations": 0,
|
||||||
|
},
|
||||||
|
"weapons": [],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`;
|
@ -2,60 +2,68 @@ import { test, expect } from "vitest";
|
|||||||
import ship from "./ship";
|
import ship from "./ship";
|
||||||
|
|
||||||
test("kicking the tires", () => {
|
test("kicking the tires", () => {
|
||||||
const store = ship.createStore();
|
const store = ship.createStore();
|
||||||
store.dispatch.setFtlType("standard");
|
store.dispatch.setFtlType("standard");
|
||||||
|
|
||||||
expect(store.getState().propulsion.ftl.reqs.mass).toEqual(1);
|
expect(store.getState().propulsion.ftl.reqs.mass).toEqual(1);
|
||||||
expect(store.getState().identification.reqs.usedMass).toEqual(1);
|
expect(store.getState().identification.reqs.usedMass).toEqual(1);
|
||||||
|
|
||||||
store.dispatch.setDrive({ rating: 3, advanced: true });
|
store.dispatch.setDrive({ rating: 3, advanced: true });
|
||||||
|
|
||||||
expect(store.getState().propulsion.drive.reqs).toEqual({ mass: 2, cost: 6 });
|
expect(store.getState().propulsion.drive.reqs).toEqual({ mass: 2, cost: 6 });
|
||||||
|
|
||||||
store.dispatch.setNbrCarrierBays(1);
|
store.dispatch.setNbrCarrierBays(1);
|
||||||
expect(store.getState().carrier.nbrBays).toEqual(1);
|
expect(store.getState().carrier.nbrBays).toEqual(1);
|
||||||
store.dispatch.setNbrCarrierBays(2);
|
store.dispatch.setNbrCarrierBays(2);
|
||||||
expect(store.getState().carrier.nbrBays).toEqual(2);
|
expect(store.getState().carrier.nbrBays).toEqual(2);
|
||||||
|
|
||||||
store.dispatch.setSquadronType(2, "fast");
|
store.dispatch.setSquadronType(2, "fast");
|
||||||
|
|
||||||
expect(store.getState().carrier.squadrons[1]).toHaveProperty("type", "fast");
|
expect(store.getState().carrier.squadrons[1]).toHaveProperty("type", "fast");
|
||||||
|
|
||||||
expect(store.getState.isCarrier()).toBe(true);
|
expect(store.getState.isCarrier()).toBe(true);
|
||||||
|
|
||||||
store.dispatch.setStreamlining("partial");
|
store.dispatch.setStreamlining("partial");
|
||||||
|
|
||||||
expect(store.getState.getStreamlining()).toBe("partial");
|
expect(store.getState.getStreamlining()).toBe("partial");
|
||||||
expect(store.selectors.getStreamlining(store.getState())).toBe("partial");
|
expect(store.selectors.getStreamlining(store.getState())).toBe("partial");
|
||||||
|
|
||||||
store.dispatch.setCargo(3);
|
store.dispatch.setCargo(3);
|
||||||
expect(store.getState().structure.cargo).toEqual({
|
expect(store.getState().structure.cargo).toEqual({
|
||||||
space: 3,
|
space: 3,
|
||||||
reqs: {
|
reqs: {
|
||||||
mass: 3,
|
mass: 3,
|
||||||
cost: 0,
|
cost: 0,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
store.dispatch.setNbrArmorLayers(1);
|
store.dispatch.setNbrArmorLayers(1);
|
||||||
store.dispatch.setArmorRating(1, 3);
|
store.dispatch.setArmorRating(1, 3);
|
||||||
|
|
||||||
expect(store.getState().structure.armor).toEqual({
|
expect(store.getState().structure.armor).toEqual({
|
||||||
layers: [3],
|
layers: [3],
|
||||||
reqs: {
|
reqs: {
|
||||||
cost: 6,
|
cost: 6,
|
||||||
mass: 6,
|
mass: 6,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
store.dispatch.addWeapon("beam");
|
store.dispatch.addWeapon("beam");
|
||||||
expect(store.getState().weaponry.weapons[0]).toEqual({
|
expect(store.getState().weaponry.weapons[0]).toEqual({
|
||||||
id: 1,
|
id: 1,
|
||||||
reqs: { cost: 3, mass: 1 },
|
reqs: { cost: 3, mass: 1 },
|
||||||
specs: {
|
specs: {
|
||||||
arcs: ["FS", "F", "FP", "AP", "A", "AS"],
|
arcs: ["FS", "F", "FP", "AP", "A", "AS"],
|
||||||
type: "beam",
|
type: "beam",
|
||||||
weaponClass: 1,
|
weaponClass: 1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("state has a schema version", () => {
|
||||||
|
expect(ship.initialState).toHaveProperty("schemaVersion");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("state has the expected shape", () => {
|
||||||
|
expect(ship.initialState).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
@ -51,6 +51,9 @@ const weaponry = new Updux({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const shipDux = new Updux({
|
const shipDux = new Updux({
|
||||||
|
initialState: {
|
||||||
|
schemaVersion: "1",
|
||||||
|
},
|
||||||
subduxes: {
|
subduxes: {
|
||||||
identification,
|
identification,
|
||||||
structure,
|
structure,
|
||||||
|