-
Notifications
You must be signed in to change notification settings - Fork 37
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
11
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
11 commits
Select commit
Hold shift + click to select a range
64446ef
Update verification-metadata.xml
stringres 3517938
Add settings activity
stringres 83d1d10
Add settings main screen
stringres f615bf2
Add subscription settings screen
stringres 2e0cd0d
Add app settings screen
stringres f67d7c2
Fix navigation issues
stringres c6c978d
Add settings tests
stringres 046dd9e
Add conversation user flow test
stringres 10fa182
Remove old settings implementation
stringres 47800dd
Update ViewModel and Compose for detekt
stringres 90cc047
Update ktlint config to prevent collapsing data classes
stringres 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
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