Skip to content

Commit

Permalink
922 Repair Client Test Cases...
Browse files Browse the repository at this point in the history
  • Loading branch information
1fifoto committed Aug 31, 2024
1 parent cad2cd6 commit 62c014d
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 33 deletions.
2 changes: 1 addition & 1 deletion client/src/__test__/Piston-Cylinder/dispatcher.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
114 changes: 114 additions & 0 deletions client/src/__test__/Piston-Cylinder/initialStateOld.js
Original file line number Diff line number Diff line change
@@ -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": ""
}
};
18 changes: 15 additions & 3 deletions client/src/__test__/Piston-Cylinder/initialStateWithFDCL.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CONSTRAINED } from '../../store/actionTypes';
export const initialStateWithFDCL = {
export const initialState = {
"symbol_table": [
{
"input": true,
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
45 changes: 16 additions & 29 deletions client/src/__test__/Piston-Cylinder/reducers.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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");
});

Expand Down Expand Up @@ -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"]);
Expand Down Expand Up @@ -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"]);
Expand Down Expand Up @@ -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());
Expand All @@ -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());

Expand Down

0 comments on commit 62c014d

Please sign in to comment.