Changing the environment if it sees the incorrect environment in the setting I am using the function below to change the environment. If it sees the wrong environment values, it clicks on it and it changes the environment.
In this function, I am just using if and else statement. Is this a good code practice? This does the job however it does not seem clean.
class SettingsPage extends Page {

changeEnvironment(appName) {
        if (appName.$(PreferenceScreen.environmentProduction).isDisplayed()) {
            appName.$(PreferenceScreen.environmentProduction).click();
        }
        else if
            (appName.$(PreferenceScreen.environmentDevelopment).isDisplayed()) {
             appName.$(PreferenceScreen.environmentDevelopment).click();
        }
    }
}
The built in JS array transformation functions could help you reduce duplicated code.
const environments = ['environmentProduction','environmentDevelopment'];

class SettingsPage extends Page {
    
    changeEnvironment(appName) {
        const all_buttons = environments.map(
            env=&gt;appName.$(PreferenceScreen[env])
        );
        const displayed_buttons = all_buttons.filter(button=&gt;button.isDisplayed());
        displayed_buttons.forEach(button=&gt;button.click());
    }
}