-
Notifications
You must be signed in to change notification settings - Fork 38
Settings Screen: Java/XML to Kotlin/Compose migration + tests #101
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
Open
m4pl
wants to merge
14
commits into
GrapheneOS:main
Choose a base branch
from
m4pl:appsettings-compose
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
64446ef
Update verification-metadata.xml
m4pl 3517938
Add settings activity
m4pl 83d1d10
Add settings main screen
m4pl f615bf2
Add subscription settings screen
m4pl 2e0cd0d
Add app settings screen
m4pl f67d7c2
Fix navigation issues
m4pl c6c978d
Add settings tests
m4pl 046dd9e
Add conversation user flow test
m4pl 10fa182
Remove old settings implementation
m4pl 47800dd
Update ViewModel and Compose for detekt
m4pl 90cc047
Update ktlint config to prevent collapsing data classes
m4pl 49d90d0
Add default test rules
m4pl ac01128
Fix minor UI differences from the previous version
m4pl 1072453
Fix settings UI when active SIM subscription changes
m4pl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/com/android/common/test/helpers/ShellCommandHelper.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.android.common.test.helpers | ||
|
|
||
| import android.os.ParcelFileDescriptor | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
|
|
||
| object ShellCommandHelper { | ||
|
|
||
| fun setupSmsDefaultRole() { | ||
| val instrumentation = InstrumentationRegistry.getInstrumentation() | ||
| val packageName = instrumentation.targetContext.packageName | ||
| val command = "cmd role add-role-holder android.app.role.SMS $packageName" | ||
|
|
||
| executeShellCommand(command) | ||
| } | ||
|
|
||
| private fun executeShellCommand(command: String): String { | ||
| val instrumentation = InstrumentationRegistry.getInstrumentation() | ||
| val parcelFileDescriptor = instrumentation.uiAutomation.executeShellCommand(command) | ||
|
|
||
| return ParcelFileDescriptor.AutoCloseInputStream(parcelFileDescriptor).use { inputStream -> | ||
| String(inputStream.readBytes()) | ||
| } | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
app/src/androidTest/java/com/android/common/test/helpers/TestDataSeeder.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.android.common.test.helpers | ||
|
|
||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import com.android.messaging.debug.seedTestData | ||
|
|
||
| object TestDataSeeder { | ||
|
|
||
| fun seedTestData() { | ||
| val context = InstrumentationRegistry.getInstrumentation().targetContext | ||
| seedTestData(context) | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
app/src/androidTest/java/com/android/common/test/rules/AppTestRule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.android.common.test.rules | ||
|
|
||
| import com.android.common.test.helpers.ShellCommandHelper | ||
| import org.junit.rules.TestRule | ||
| import org.junit.runner.Description | ||
| import org.junit.runners.model.Statement | ||
|
|
||
| class AppTestRule : TestRule { | ||
|
|
||
| override fun apply( | ||
| base: Statement, | ||
| description: Description, | ||
| ): Statement { | ||
| return object : Statement() { | ||
| override fun evaluate() { | ||
| ShellCommandHelper.setupSmsDefaultRole() | ||
| base.evaluate() | ||
| } | ||
| } | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
app/src/androidTest/java/com/android/common/test/rules/MessagingTestRule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.android.common.test.rules | ||
|
|
||
| import com.android.common.test.helpers.TestDataSeeder | ||
| import org.junit.rules.TestRule | ||
| import org.junit.runner.Description | ||
| import org.junit.runners.model.Statement | ||
|
|
||
| class MessagingTestRule : TestRule { | ||
|
|
||
| override fun apply( | ||
| base: Statement, | ||
| description: Description, | ||
| ): Statement { | ||
| return object : Statement() { | ||
| override fun evaluate() { | ||
| TestDataSeeder.seedTestData() | ||
| base.evaluate() | ||
| } | ||
| } | ||
| } | ||
| } |
224 changes: 224 additions & 0 deletions
224
...androidTest/java/com/android/messaging/ui/appsettings/general/ui/AppSettingsScreenTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| package com.android.messaging.ui.appsettings.general.ui | ||
|
|
||
| import androidx.activity.ComponentActivity | ||
| import androidx.compose.ui.test.assertIsDisplayed | ||
| import androidx.compose.ui.test.junit4.createAndroidComposeRule | ||
| import androidx.compose.ui.test.onNodeWithText | ||
| import androidx.compose.ui.test.performClick | ||
| import com.android.messaging.R | ||
| import com.android.messaging.ui.appsettings.general.model.AppSettingsUiState | ||
| import com.android.messaging.ui.appsettings.screen.SettingsScreenModel | ||
| import com.android.messaging.ui.appsettings.screen.model.SettingsAction as Action | ||
| import com.android.messaging.ui.core.AppTheme | ||
| import io.mockk.mockk | ||
| import io.mockk.verify | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Before | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
|
|
||
| class AppSettingsScreenTest { | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createAndroidComposeRule<ComponentActivity>() | ||
|
|
||
| private lateinit var screenModel: SettingsScreenModel | ||
|
|
||
| @Before | ||
| fun setup() { | ||
| screenModel = mockk(relaxed = true) | ||
| } | ||
|
|
||
| @Test | ||
| fun defaultSmsAppItem_displaysLabel() { | ||
| val appSettings = AppSettingsUiState( | ||
| isDefaultSmsApp = true, | ||
| defaultSmsAppLabel = "Messaging", | ||
| ) | ||
|
|
||
| setContent(appSettings = appSettings) | ||
|
|
||
| composeTestRule.onNodeWithText("Messaging").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun defaultSmsAppClick_delegatesToScreenModel() { | ||
| val appSettings = AppSettingsUiState( | ||
| isDefaultSmsApp = true, | ||
| defaultSmsAppLabel = "Messaging", | ||
| ) | ||
|
|
||
| setContent(appSettings = appSettings) | ||
|
|
||
| val title = composeTestRule.activity.getString(R.string.sms_disabled_pref_title) | ||
| composeTestRule.onNodeWithText(title).performClick() | ||
|
|
||
| verify(exactly = 1) { | ||
| screenModel.onAction(Action.DefaultSmsAppClicked(true)) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun notificationsClick_delegatesToScreenModel() { | ||
| setContent() | ||
|
|
||
| val title = composeTestRule.activity.getString( | ||
| R.string.notifications_enabled_conversation_pref_title, | ||
| ) | ||
| composeTestRule.onNodeWithText(title).performClick() | ||
|
|
||
| verify(exactly = 1) { | ||
| screenModel.onAction(Action.NotificationsClicked) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun sendSoundToggle_delegatesToScreenModel() { | ||
| val appSettings = AppSettingsUiState(sendSoundEnabled = true) | ||
|
|
||
| setContent(appSettings = appSettings) | ||
|
|
||
| val title = composeTestRule.activity.getString(R.string.send_sound_pref_title) | ||
| composeTestRule.onNodeWithText(title).performClick() | ||
|
|
||
| verify(exactly = 1) { | ||
| screenModel.onAction(Action.SendSoundChanged(false)) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun debugSection_hiddenWhenDebugDisabled() { | ||
| val appSettings = AppSettingsUiState(isDebugEnabled = false) | ||
|
|
||
| setContent(appSettings = appSettings) | ||
|
|
||
| val debugTitle = composeTestRule.activity.getString(R.string.debug_category_pref_title) | ||
| composeTestRule.onNodeWithText(debugTitle).assertDoesNotExist() | ||
|
|
||
| val dumpSmsTitle = composeTestRule.activity.getString(R.string.dump_sms_pref_title) | ||
| composeTestRule.onNodeWithText(dumpSmsTitle).assertDoesNotExist() | ||
| } | ||
|
|
||
| @Test | ||
| fun debugSection_shownWhenDebugEnabled() { | ||
| val appSettings = AppSettingsUiState( | ||
| isDebugEnabled = true, | ||
| dumpSmsEnabled = false, | ||
| dumpMmsEnabled = false, | ||
| ) | ||
|
|
||
| setContent(appSettings = appSettings) | ||
|
|
||
| val debugTitle = composeTestRule.activity.getString(R.string.debug_category_pref_title) | ||
| composeTestRule.onNodeWithText(debugTitle).assertIsDisplayed() | ||
|
|
||
| val dumpSmsTitle = composeTestRule.activity.getString(R.string.dump_sms_pref_title) | ||
| composeTestRule.onNodeWithText(dumpSmsTitle).assertIsDisplayed() | ||
|
|
||
| val dumpMmsTitle = composeTestRule.activity.getString(R.string.dump_mms_pref_title) | ||
| composeTestRule.onNodeWithText(dumpMmsTitle).assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun dumpSmsToggle_delegatesToScreenModel() { | ||
| val appSettings = AppSettingsUiState( | ||
| isDebugEnabled = true, | ||
| dumpSmsEnabled = false, | ||
| ) | ||
|
|
||
| setContent(appSettings = appSettings) | ||
|
|
||
| val title = composeTestRule.activity.getString(R.string.dump_sms_pref_title) | ||
| composeTestRule.onNodeWithText(title).performClick() | ||
|
|
||
| verify(exactly = 1) { | ||
| screenModel.onAction(Action.DumpSmsChanged(true)) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun dumpMmsToggle_delegatesToScreenModel() { | ||
| val appSettings = AppSettingsUiState( | ||
| isDebugEnabled = true, | ||
| dumpMmsEnabled = false, | ||
| ) | ||
|
|
||
| setContent(appSettings = appSettings) | ||
|
|
||
| val title = composeTestRule.activity.getString(R.string.dump_mms_pref_title) | ||
| composeTestRule.onNodeWithText(title).performClick() | ||
|
|
||
| verify(exactly = 1) { | ||
| screenModel.onAction(Action.DumpMmsChanged(true)) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun licensesClick_delegatesToScreenModel() { | ||
| setContent() | ||
|
|
||
| val title = composeTestRule.activity.getString(R.string.menu_license) | ||
| composeTestRule.onNodeWithText(title).performClick() | ||
|
|
||
| verify(exactly = 1) { | ||
| screenModel.onAction(Action.LicensesClicked) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun advancedSettings_shownWhenTopLevel() { | ||
| var advancedClicks = 0 | ||
|
|
||
| composeTestRule.setContent { | ||
| AppTheme { | ||
| AppSettingsScreen( | ||
| appSettings = AppSettingsUiState(), | ||
| screenModel = screenModel, | ||
| onNavigateBack = {}, | ||
| isTopLevel = true, | ||
| onAdvancedClick = { advancedClicks += 1 }, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| val advancedTitle = composeTestRule.activity.getString(R.string.advanced_settings) | ||
| composeTestRule.onNodeWithText(advancedTitle).assertIsDisplayed() | ||
| composeTestRule.onNodeWithText(advancedTitle).performClick() | ||
|
|
||
| composeTestRule.runOnIdle { | ||
| assertEquals(1, advancedClicks) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun advancedSettings_hiddenWhenNotTopLevel() { | ||
| composeTestRule.setContent { | ||
| AppTheme { | ||
| AppSettingsScreen( | ||
| appSettings = AppSettingsUiState(), | ||
| screenModel = screenModel, | ||
| onNavigateBack = {}, | ||
| isTopLevel = false, | ||
| onAdvancedClick = null, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| val advancedTitle = composeTestRule.activity.getString(R.string.advanced_settings) | ||
| composeTestRule.onNodeWithText(advancedTitle).assertDoesNotExist() | ||
| } | ||
|
|
||
| private fun setContent( | ||
| appSettings: AppSettingsUiState = AppSettingsUiState(), | ||
| ) { | ||
| composeTestRule.setContent { | ||
| AppTheme { | ||
| AppSettingsScreen( | ||
| appSettings = appSettings, | ||
| screenModel = screenModel, | ||
| onNavigateBack = {}, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, this is removing the exported Activity
.ui.appsettings.ApplicationSettingsActivityand just using.ui.appsettings.SettingsActivitynow.Since
.ui.appsettings.ApplicationSettingsActivityused to be exported, for completeness, maybe anactivity-aliascould be added here for.ui.appsettings.ApplicationSettingsActivitywithandroid:targetActivity=".ui.appsettings.SettingsActivity">There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will take a look, thanks