Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-run now depends on upload results settings #223

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 @@ -72,6 +72,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 @@ -82,6 +83,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 @@ -93,14 +95,15 @@ class GetSettings(
}

private fun buildSettings(
uploadResultsEnabled: Boolean,
autoRunEnabled: Boolean,
enabledCategoriesCount: Int,
maxRuntimeEnabled: Boolean,
maxRuntime: Int?,
storageUsed: Long,
supportsCrashReporting: Boolean = false,
): List<SettingsCategoryItem> {
return listOf(
return listOfNotNull(
SettingsCategoryItem(
icon = Res.drawable.notifications,
title = Res.string.Settings_Notifications_Label,
Expand All @@ -123,10 +126,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 @@ -185,29 +194,24 @@ class GetSettings(
)
},
),
SettingsCategoryItem(
icon = Res.drawable.privacy,
title = Res.string.Settings_Privacy_Label,
route = PreferenceCategoryKey.PRIVACY,
settings = buildList {
add(
SettingsItem(
title = Res.string.Settings_Sharing_UploadResults,
key = SettingsKey.UPLOAD_RESULTS,
type = PreferenceItemType.SWITCH,
),
)
if (supportsCrashReporting) {
add(
SettingsItem(
title = Res.string.Settings_Privacy_SendCrashReports,
key = SettingsKey.SEND_CRASH,
type = PreferenceItemType.SWITCH,
),
)
}
},
),
if (supportsCrashReporting) {
SettingsCategoryItem(
icon = Res.drawable.privacy,
title = Res.string.Settings_Privacy_Label,
route = PreferenceCategoryKey.PRIVACY,
settings = buildList {
if (supportsCrashReporting) {
add(
SettingsItem(
title = Res.string.Settings_Privacy_SendCrashReports,
key = SettingsKey.SEND_CRASH,
type = PreferenceItemType.SWITCH,
),
)
}
},
)
} else null,
SettingsCategoryItem(
icon = Res.drawable.proxy,
title = Res.string.Settings_Proxy_Label,
Expand Down
Loading