Skip to content

Commit

Permalink
fix handling of screens query parameter, phetsims/ph-scale#171
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jul 21, 2020
1 parent 3cd429c commit c29f824
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions js/selectScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,27 @@ const selectScreens = ( allSimScreens,
// phet.chipper.queryParameters.screens in initialize-globals.js.
if ( screensQueryParameterProvided && screensQueryParameter ) {

let allScreensValid = true;
screensQueryParameter.forEach( userIndex => {
const screenIndex = userIndex - 1; // screens query parameter is 1-based
for ( let i = 0; i < screensQueryParameter.length; i++ ) {

const userIndex = screensQueryParameter[ i ];
const screenIndex = userIndex - 1; // screens query parameter uses 1-based indices, so convert to 0-based index

// add screen to selectedSimScreens if it's a valid index, otherwise error and revert to defaults
if ( screenIndex >= 0 && screenIndex < allSimScreens.length ) {

// index is valid, add screen
selectedSimScreens.push( allSimScreens[ screenIndex ] );
}
else {
const errorMessage = `invalid screen index: ${userIndex}`;

// handle gracefully when running without ?ea and set selectedSimScreens to default values, see https://github.com/phetsims/joist/issues/599
QueryStringMachine.addWarning( 'screens', userIndex, errorMessage );

// to support expected failures in selectScreensTests.js unit tests
// index is invalid, handle gracefully when running without ?ea and set selectedSimScreens to default values,
// see https://github.com/phetsims/joist/issues/599
const errorMessage = `invalid value in screens query parameter: ${userIndex}`;
QueryStringMachine.addWarning( 'screens', screensQueryParameter, errorMessage );
assert && assert( false, errorMessage );
allScreensValid = false;
selectedSimScreens = allSimScreens;
break;
}
} );

if ( !allScreensValid ) {
selectedSimScreens = allSimScreens;
}
}
else {
Expand Down

1 comment on commit c29f824

@pixelzoom
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.