diff --git a/client/src/__test__/Piston-Cylinder/dispatcher.test.js b/client/src/__test__/Piston-Cylinder/dispatcher.test.js index caf7b782..5b50f7c3 100644 --- a/client/src/__test__/Piston-Cylinder/dispatcher.test.js +++ b/client/src/__test__/Piston-Cylinder/dispatcher.test.js @@ -1,5 +1,5 @@ import { initialState } from '../../designtypes/Piston-Cylinder/initialState'; -import { initialStateWithFDCL } from './initialStateWithFDCL'; +import { initialState as initialStateWithFDCL } from './initialStateWithFDCL'; import * as sto from '../../designtypes/Piston-Cylinder/symbol_table_offsets'; import { initialSystemControls } from '../../initialSystemControls'; import { MIN, MAX, CONSTRAINED, FIXED, FDCL } from '../../store/actionTypes'; diff --git a/client/src/__test__/Piston-Cylinder/initialStateOld.js b/client/src/__test__/Piston-Cylinder/initialStateOld.js new file mode 100644 index 00000000..830ae825 --- /dev/null +++ b/client/src/__test__/Piston-Cylinder/initialStateOld.js @@ -0,0 +1,114 @@ +import { CONSTRAINED } from '../../store/actionTypes'; +export const initialState = { + "name": "initialState", + "symbol_table": [ + { + "input": true, + "name": "PRESSURE", + "value": 500, + "units": "LB/SQ-IN", + "lmin": 0, + "lmax": CONSTRAINED, + "cmin": 0, + "cmax": 1500, + "validmin": -Number.MAX_VALUE, + "validmax": Number.MAX_VALUE, + "sdlim": 1.0, + "tooltip": "Gas PRESSURE applied to piston AREA", + "type": "equationset", + "hidden": false + }, + { + "input": true, + "name": "RADIUS", + "value": 0.4, + "units": "INCH", + "lmin": CONSTRAINED, + "lmax": CONSTRAINED, + "cmin": 0.04, + "cmax": 0.5, + "validmin": Number.MIN_VALUE, + "validmax": Number.MAX_VALUE, + "sdlim": 0.01, + "tooltip": "Piston dimension; creates AREA where PRESSURE is applied", + "type": "equationset", + "hidden": false + }, + { + "input": true, + "name": "THICKNESS", + "value": 0.04, + "units": "INCH", + "lmin": CONSTRAINED, + "lmax": CONSTRAINED, + "cmin": 0.002, + "cmax": 0.05, + "validmin": Number.MIN_VALUE, + "validmax": Number.MAX_VALUE, + "sdlim": 0.001, + "tooltip": "Dimension of cylinder wall providing containment for PRESSURE", + "type": "equationset", + "hidden": false + }, + { + "input": false, + "name": "FORCE", + "value": 0, + "units": "LBS.", + "lmin": CONSTRAINED, + "lmax": 0, + "cmin": 1000, + "cmax": 10000, + "validmin": -Number.MAX_VALUE, + "validmax": Number.MAX_VALUE, + "sdlim": 1, + "tooltip": "Push generated by PRESSURE acting on piston AREA", + "type": "equationset", + "hidden": false + }, + { + "input": false, + "name": "AREA", + "value": 0, + "units": "SQ.-IN.", + "lmin": 0, + "lmax": 0, + "cmin": 0, + "cmax": 10, + "validmin": 0.0, + "validmax": Number.MAX_VALUE, + "sdlim": 0.1, + "tooltip": "Effective amount of piston surface exposed to PRESSURE", + "type": "equationset", + "hidden": false + }, + { + "input": false, + "name": "STRESS", + "value": 0, + "units": "PSI", + "lmin": 0, + "lmax": CONSTRAINED, + "cmin": 0, + "cmax": 3000, + "validmin": -Number.MAX_VALUE, + "validmax": Number.MAX_VALUE, + "sdlim": 10, + "tooltip": "Force per unit area within cylinder wall; created by PRESSURE", + "type": "equationset", + "hidden": false + } + ], + "labels": [ + { + "name": "COMMENT", + "value": "PCYL default start point - US units ..." + } + ], + "type": "Piston-Cylinder", + "version": "7", + "result": { + "objective_value": 0, + "termination_condition": "" + } +}; diff --git a/client/src/__test__/Piston-Cylinder/initialStateWithFDCL.js b/client/src/__test__/Piston-Cylinder/initialStateWithFDCL.js index 84a478f3..ccee40b5 100644 --- a/client/src/__test__/Piston-Cylinder/initialStateWithFDCL.js +++ b/client/src/__test__/Piston-Cylinder/initialStateWithFDCL.js @@ -1,5 +1,5 @@ import { CONSTRAINED } from '../../store/actionTypes'; -export const initialStateWithFDCL = { +export const initialState = { "symbol_table": [ { "input": true, @@ -10,6 +10,8 @@ export const initialStateWithFDCL = { "lmax": CONSTRAINED, "cmin": 0, "cmax": 1500, + "validmin": -Number.MAX_VALUE, + "validmax": Number.MAX_VALUE, "sdlim": 1.0, "tooltip": "Gas PRESSURE applied to piston AREA", "type": "equationset", @@ -22,8 +24,10 @@ export const initialStateWithFDCL = { "units": "INCH", "lmin": CONSTRAINED, "lmax": CONSTRAINED, - "cmin": 0, + "cmin": 0.04, "cmax": 0.5, + "validmin": Number.MIN_VALUE, + "validmax": Number.MAX_VALUE, "sdlim": 0.01, "tooltip": "Piston dimension; creates AREA where PRESSURE is applied", "type": "equationset", @@ -38,8 +42,10 @@ export const initialStateWithFDCL = { "units": "INCH", "lmin": CONSTRAINED, "lmax": CONSTRAINED, - "cmin": 0, + "cmin": 0.002, "cmax": 0.05, + "validmin": Number.MIN_VALUE, + "validmax": Number.MAX_VALUE, "sdlim": 0.001, "tooltip": "Dimension of cylinder wall providing containment for PRESSURE", "type": "equationset", @@ -54,6 +60,8 @@ export const initialStateWithFDCL = { "lmax": 0, "cmin": 1000, "cmax": 10000, + "validmin": -Number.MAX_VALUE, + "validmax": Number.MAX_VALUE, "sdlim": 1, "tooltip": "Push generated by PRESSURE acting on piston AREA", "type": "equationset", @@ -68,6 +76,8 @@ export const initialStateWithFDCL = { "lmax": 0, "cmin": 0, "cmax": 10, + "validmin": 0.0, + "validmax": Number.MAX_VALUE, "sdlim": 0.1, "tooltip": "Effective amount of piston surface exposed to PRESSURE", "type": "equationset", @@ -82,6 +92,8 @@ export const initialStateWithFDCL = { "lmax": CONSTRAINED, "cmin": 0, "cmax": 3000, + "validmin": -Number.MAX_VALUE, + "validmax": Number.MAX_VALUE, "sdlim": 10, "tooltip": "Force per unit area within cylinder wall; created by PRESSURE", "type": "equationset", diff --git a/client/src/__test__/Piston-Cylinder/reducers.test.js b/client/src/__test__/Piston-Cylinder/reducers.test.js index 85a5054c..4d638cc0 100644 --- a/client/src/__test__/Piston-Cylinder/reducers.test.js +++ b/client/src/__test__/Piston-Cylinder/reducers.test.js @@ -1,4 +1,7 @@ import { initialState } from '../../designtypes/Piston-Cylinder/initialState'; +import { initialState as initialStateWithFDCL } from './initialStateWithFDCL'; +import { initialState as initialStateOld } from './initialStateOld'; +import { initialState as initialStateSpringCompression } from '../../designtypes/Spring/Compression/initialState'; import * as sto from '../../designtypes/Piston-Cylinder/symbol_table_offsets'; import { initialSystemControls } from '../../initialSystemControls'; import { MIN, MAX, CONSTRAINED, FIXED, FDCL } from '../../store/actionTypes'; @@ -61,14 +64,11 @@ it('reducers load', () => { expect(design.model.type).toEqual("Piston-Cylinder"); store.dispatch(load({ - "name": "test", - "model": { - "type": "Test-Design" - } + "type": "Test-Design" })); var design = store.getState().modelSlice; // after -// expect(design.name).toEqual("test"); + expect(design.name).toEqual("initialState"); expect(design.model.type).toEqual("Test-Design"); }); @@ -224,11 +224,11 @@ it('reducers reset symbol flag min CONSTRAINED', () => { }); it('reducers set symbol flag min FDCL', () => { - var state = Object.assign({}, initialState, { system_controls: initialSystemControls }); // Merge initialState and initialSystemControls + + var state = Object.assign({}, initialStateWithFDCL, { system_controls: initialSystemControls }); // Merge initialState and initialSystemControls store.dispatch(inject({name: "initialState", model: state})); var design = store.getState().modelSlice; // before - design.model.symbol_table[sto.RADIUS].cminchoices = ["THICKNESS"]; // Prepare for FDCL expect(design.model.symbol_table[sto.RADIUS].name).toEqual("RADIUS"); expect(design.model.symbol_table[sto.RADIUS].lmin).toEqual(CONSTRAINED); expect(design.model.symbol_table[sto.RADIUS].cminchoices).toEqual(["THICKNESS"]); @@ -273,11 +273,10 @@ it('reducers reset symbol flag max CONSTRAINED', () => { }); it('reducers set symbol flag max FDCL', () => { - var state = Object.assign({}, initialState, { system_controls: initialSystemControls }); // Merge initialState and initialSystemControls + var state = Object.assign({}, initialStateWithFDCL, { system_controls: initialSystemControls }); // Merge initialState and initialSystemControls store.dispatch(inject({name: "initialState", model: state})); var design = store.getState().modelSlice; // before - design.model.symbol_table[sto.RADIUS].cmaxchoices = ["THICKNESS"]; // Prepare for FDCL expect(design.model.symbol_table[sto.RADIUS].name).toEqual("RADIUS"); expect(design.model.symbol_table[sto.RADIUS].lmax).toEqual(CONSTRAINED); expect(design.model.symbol_table[sto.RADIUS].cmaxchoices).toEqual(["THICKNESS"]); @@ -658,15 +657,11 @@ it('reducers restore auto save', () => { // Load with an entirely different state before restore and verify it store.dispatch(load({ - "user": "USERID0123456789", - "name": "test", - "model": { - "type": "Test-Design" - } + "type": "Test-Design" })); var design = store.getState().modelSlice; // after expect(design.user).toEqual("USERID0123456789"); - expect(design.name).toEqual("test"); + expect(design.name).toEqual("initialState"); expect(design.model.type).toEqual("Test-Design"); store.dispatch(restoreAutoSave()); @@ -681,31 +676,23 @@ it('reducers restore auto save', () => { }); it('reducers restore old auto save', () => { - var state = Object.assign({}, initialState, { system_controls: initialSystemControls }); // Merge initialState and initialSystemControls + // initialStateOld has no state.jsontype, has no state.units, and has state.name + var state = Object.assign({}, initialStateOld, { system_controls: initialSystemControls }); // Merge initialState and initialSystemControls store.dispatch(inject({"user": "USERID0123456789", name: "initialState", model: state})); // Create an old format autosave file and verify it was created - delete state.jsontype; // Mark it as old by deleting jsontype - delete state.units; // Mark it as old by deleting units var design = store.getState().modelSlice; // before - state.name = design.name; // move name into model to save it ***FUDGE*** for compatibility with existing autosave files expect(typeof(Storage)).not.toEqual("undefined"); localStorage.setItem('autosave', JSON.stringify(state), null, 2); // create or replace auto save file with current state contents expect(localStorage.getItem('autosave')).not.toBeNull(); - delete state.name; // after saving it delete name from model ***FUDGE*** for compatibility with existing autosave files // Load with an entirely different state before restore and verify it - store.dispatch(load({ - "user": "USERID0123456789", - "name": "test", - "model": { - "type": "Test-Design" - } - })); // load with an entirely different state before restore + var state = Object.assign({}, initialStateSpringCompression, { system_controls: initialSystemControls }); // Merge initialState and initialSystemControls + store.dispatch(inject({"user": "USERIDABCDEFGHIK", name: "test", model: state})); // load with an entirely different state before restore var design = store.getState().modelSlice; // before - expect(design.user).toEqual("USERID0123456789"); + expect(design.user).toEqual("USERIDABCDEFGHIK"); expect(design.name).toEqual("test"); - expect(design.model.type).toEqual("Test-Design"); + expect(design.model.type).toEqual("Spring/Compression"); store.dispatch(restoreAutoSave());