Changing the environment if it sees the incorrect environment in the setting
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());
    }
}