Skip to content

Commit

Permalink
Auto-run now depends on upload results settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sdsantos committed Oct 28, 2024
1 parent c8fb7e6 commit b7fb259
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SettingsTest {
runTest {
preferences.setValuesByKey(
listOf(
SettingsKey.UPLOAD_RESULTS to false,
SettingsKey.AUTOMATED_TESTING_ENABLED to false,
SettingsKey.AUTOMATED_TESTING_WIFIONLY to false,
SettingsKey.AUTOMATED_TESTING_CHARGING to false,
Expand All @@ -64,15 +65,20 @@ class SettingsTest {
clickOnText("Settings")
clickOnText("Test options")

clickOnText("Automatically Publish Results")
wait { preferences.getValueByKey(SettingsKey.UPLOAD_RESULTS).first() == true }

clickOnText("Run tests automatically")
wait {
preferences.getValueByKey(SettingsKey.AUTOMATED_TESTING_ENABLED).first() == true
}

clickOnText("Only on WiFi")
clickOnText("Only while charging")

wait {
preferences.getValueByKey(SettingsKey.AUTOMATED_TESTING_ENABLED)
preferences.getValueByKey(SettingsKey.AUTOMATED_TESTING_WIFIONLY)
.first() == true &&
preferences.getValueByKey(SettingsKey.AUTOMATED_TESTING_WIFIONLY)
.first() == true &&
preferences.getValueByKey(SettingsKey.AUTOMATED_TESTING_CHARGING)
.first() == true
}
Expand Down Expand Up @@ -112,20 +118,17 @@ class SettingsTest {
runTest {
preferences.setValuesByKey(
listOf(
SettingsKey.UPLOAD_RESULTS to false,
SettingsKey.SEND_CRASH to false,
),
)

with(compose) {
clickOnText("Settings")
clickOnText("Privacy")
clickOnText("Automatically Publish Results")
clickOnText("Send crash reports")

wait {
preferences.getValueByKey(SettingsKey.UPLOAD_RESULTS).first() == true &&
preferences.getValueByKey(SettingsKey.SEND_CRASH).first() == true
preferences.getValueByKey(SettingsKey.SEND_CRASH).first() == true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ class GetAutoRunSettings(
observeSettings(
listOf(
SettingsKey.FIRST_RUN,
SettingsKey.UPLOAD_RESULTS,
SettingsKey.AUTOMATED_TESTING_ENABLED,
SettingsKey.AUTOMATED_TESTING_WIFIONLY,
SettingsKey.AUTOMATED_TESTING_CHARGING,
),
).map { preferences ->
val firstRunDone = preferences[SettingsKey.FIRST_RUN] == false
val enabled = preferences[SettingsKey.AUTOMATED_TESTING_ENABLED] == true
if (firstRunDone && enabled) {
val uploadEnabled = preferences[SettingsKey.UPLOAD_RESULTS] == true
val autoRunEnabled = preferences[SettingsKey.AUTOMATED_TESTING_ENABLED] == true
if (firstRunDone && uploadEnabled && autoRunEnabled) {
AutoRunParameters.Enabled(
wifiOnly = preferences[SettingsKey.AUTOMATED_TESTING_WIFIONLY] == true,
onlyWhileCharging = preferences[SettingsKey.AUTOMATED_TESTING_CHARGING] == true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class GetSettings(
return combine(
preferencesRepository.allSettings(
WebConnectivityCategory.entries.mapNotNull { it.settingsKey } + listOf(
SettingsKey.UPLOAD_RESULTS,
SettingsKey.AUTOMATED_TESTING_ENABLED,
SettingsKey.MAX_RUNTIME_ENABLED,
SettingsKey.MAX_RUNTIME,
Expand All @@ -81,6 +82,7 @@ class GetSettings(
val enabledCategoriesCount =
WebConnectivityCategory.entries.count { preferences[it.settingsKey] == true }
buildSettings(
uploadResultsEnabled = preferences[SettingsKey.UPLOAD_RESULTS] == true,
autoRunEnabled = preferences[SettingsKey.AUTOMATED_TESTING_ENABLED] == true,
enabledCategoriesCount = enabledCategoriesCount,
maxRuntimeEnabled = preferences[SettingsKey.MAX_RUNTIME_ENABLED] == true,
Expand All @@ -91,6 +93,7 @@ class GetSettings(
}

private fun buildSettings(
uploadResultsEnabled: Boolean,
autoRunEnabled: Boolean,
enabledCategoriesCount: Int,
maxRuntimeEnabled: Boolean,
Expand Down Expand Up @@ -120,10 +123,16 @@ class GetSettings(
title = Res.string.Settings_TestOptions_Label,
route = PreferenceCategoryKey.TEST_OPTIONS,
settings = listOf(
SettingsItem(
title = Res.string.Settings_Sharing_UploadResults,
key = SettingsKey.UPLOAD_RESULTS,
type = PreferenceItemType.SWITCH,
),
SettingsItem(
title = Res.string.Settings_AutomatedTesting_RunAutomatically,
key = SettingsKey.AUTOMATED_TESTING_ENABLED,
type = PreferenceItemType.SWITCH,
enabled = uploadResultsEnabled,
),
SettingsItem(
title = Res.string.Settings_AutomatedTesting_RunAutomatically_WiFiOnly,
Expand Down Expand Up @@ -187,11 +196,6 @@ class GetSettings(
title = Res.string.Settings_Privacy_Label,
route = PreferenceCategoryKey.PRIVACY,
settings = listOf(
SettingsItem(
title = Res.string.Settings_Sharing_UploadResults,
key = SettingsKey.UPLOAD_RESULTS,
type = PreferenceItemType.SWITCH,
),
SettingsItem(
title = Res.string.Settings_Privacy_SendCrashReports,
key = SettingsKey.SEND_CRASH,
Expand Down

0 comments on commit b7fb259

Please sign in to comment.