-
-
Notifications
You must be signed in to change notification settings - Fork 27
Rewrite SimImport to Kotlin + Compose #33
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
sdsantos
wants to merge
10
commits into
GrapheneOS:main
Choose a base branch
from
sdsantos:sim-import-refactor
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
10 commits
Select commit
Hold shift + click to select a range
09032d1
Migrate SimImport to Kotlin + Compose
sdsantos 5c728b3
Refactor SimImport to use Hilt and data/domain/ui package structure
sdsantos 8546284
Ensure compose stability in SimImport
sdsantos c83c498
Address code review feedback
sdsantos 8bfeb11
Introduce SimContactUiModel. Move androidTests to unitTests.
sdsantos f9ab697
Address code review comments
sdsantos d738751
Catch UnsupportedOperationException when loading SIM cards
sdsantos a76832d
Address new code review comments
sdsantos 9949dc4
Address new code review comments (second batch)
sdsantos d5eb1f2
Use AccountIconData. Switch to deletected contacts. Remove Random fro…
sdsantos 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
144 changes: 144 additions & 0 deletions
144
app/src/test/kotlin/com/android/contacts/sim/SimImportScreenTest.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,144 @@ | ||
| package com.android.contacts.sim | ||
|
|
||
| import androidx.compose.ui.test.ComposeUiTest | ||
| import androidx.compose.ui.test.ExperimentalTestApi | ||
| import androidx.compose.ui.test.assertIsDisplayed | ||
| import androidx.compose.ui.test.assertIsNotEnabled | ||
| import androidx.compose.ui.test.hasTestTag | ||
| import androidx.compose.ui.test.hasText | ||
| import androidx.compose.ui.test.onNodeWithTag | ||
| import androidx.compose.ui.test.onNodeWithText | ||
| import androidx.compose.ui.test.performClick | ||
| import androidx.compose.ui.test.v2.runComposeUiTest | ||
| import com.android.contacts.tests.AccountUiModelFactory | ||
| import com.android.contacts.tests.SimContactUiModelFactory | ||
| import com.android.contacts.ui.common.model.SelectableItem | ||
| import com.android.contacts.ui.simimport.screen.SimImportEffectHandler | ||
| import com.android.contacts.ui.simimport.screen.SimImportScreen | ||
| import com.android.contacts.ui.simimport.screen.SimImportScreenModel | ||
| import com.android.contacts.ui.simimport.screen.model.SIM_IMPORT_ACCOUNT_PICKER_MENU_ITEM_TEST_TAG | ||
| import com.android.contacts.ui.simimport.screen.model.SIM_IMPORT_ACCOUNT_PICKER_TEST_TAG | ||
| import com.android.contacts.ui.simimport.screen.model.SIM_IMPORT_CONTACTS_TO_IMPORT_TITLE_TEST_TAG | ||
| import com.android.contacts.ui.simimport.screen.model.SIM_IMPORT_DESELECT_ALL_TEST_TAG | ||
| import com.android.contacts.ui.simimport.screen.model.SIM_IMPORT_IMPORT_BUTTON_TEST_TAG | ||
| import com.android.contacts.ui.simimport.screen.model.SIM_IMPORT_SELECT_ALL_TEST_TAG | ||
| import com.android.contacts.ui.simimport.screen.model.SimImportAction as Action | ||
| import com.android.contacts.ui.simimport.screen.model.SimImportUiState as State | ||
| import io.mockk.every | ||
| import io.mockk.mockk | ||
| import io.mockk.verify | ||
| import kotlinx.collections.immutable.persistentListOf | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
|
|
||
| @OptIn(ExperimentalTestApi::class) | ||
| @RunWith(RobolectricTestRunner::class) | ||
| class SimImportScreenTest { | ||
|
|
||
| private val fakeUiStateFlow = MutableStateFlow<State>(State.Loading) | ||
| private lateinit var screenModel: SimImportScreenModel | ||
| private lateinit var effectHandler: SimImportEffectHandler | ||
|
|
||
| @Before | ||
| fun setup() { | ||
| screenModel = mockk(relaxed = true) | ||
| effectHandler = mockk(relaxed = true) | ||
| every { screenModel.uiState } returns fakeUiStateFlow | ||
| } | ||
|
|
||
| @Test | ||
| fun showCurrentAccount() = runComposeUiTest { | ||
| val account = AccountUiModelFactory.build() | ||
| fakeUiStateFlow.value = State.Ready( | ||
| accounts = persistentListOf(account), | ||
| currentAccount = account, | ||
| ) | ||
|
|
||
| setScreenContent() | ||
|
|
||
| onNodeWithText(account.name!!).assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun pickAnotherAccount() = runComposeUiTest { | ||
| val account1 = AccountUiModelFactory.build(name = "First") | ||
| val account2 = AccountUiModelFactory.build(name = "Second") | ||
| fakeUiStateFlow.value = State.Ready( | ||
| accounts = persistentListOf(account1, account2), | ||
| currentAccount = account1, | ||
| ) | ||
|
|
||
| setScreenContent() | ||
|
|
||
| onNodeWithText(account1.name!!).assertIsDisplayed() | ||
| onNodeWithTag(SIM_IMPORT_ACCOUNT_PICKER_TEST_TAG).performClick() | ||
| onNode( | ||
| hasText(account2.name!!) | ||
| .and(hasTestTag(SIM_IMPORT_ACCOUNT_PICKER_MENU_ITEM_TEST_TAG)), | ||
| ).performClick() | ||
| verify { screenModel.onAction(Action.AccountChanged(account2)) } | ||
| } | ||
|
|
||
| @Test | ||
| fun showContactToImport() = runComposeUiTest { | ||
| val account = AccountUiModelFactory.build() | ||
| val contact = SimContactUiModelFactory.build() | ||
| fakeUiStateFlow.value = State.Ready( | ||
| accounts = persistentListOf(account), | ||
| currentAccount = account, | ||
| contactsToImport = persistentListOf(SelectableItem(contact, false)), | ||
| contactsAlreadyImported = persistentListOf(), | ||
| ) | ||
|
|
||
| setScreenContent() | ||
|
|
||
| onNodeWithTag(SIM_IMPORT_CONTACTS_TO_IMPORT_TITLE_TEST_TAG).assertIsDisplayed() | ||
| onNodeWithText(contact.label).assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun clickContact() = runComposeUiTest { | ||
| val account = AccountUiModelFactory.build() | ||
| val contact = SimContactUiModelFactory.build() | ||
| fakeUiStateFlow.value = State.Ready( | ||
| accounts = persistentListOf(account), | ||
| currentAccount = account, | ||
| contactsToImport = persistentListOf(SelectableItem(contact, false)), | ||
| contactsAlreadyImported = persistentListOf(), | ||
| ) | ||
|
|
||
| setScreenContent() | ||
|
|
||
| onNodeWithText(contact.label).performClick() | ||
| verify { screenModel.onAction(Action.ContactSelectionChanged(contact, true)) } | ||
| } | ||
|
|
||
| @Test | ||
| fun checkTopBarActionsCanBeDisabled() = runComposeUiTest { | ||
| val account = AccountUiModelFactory.build() | ||
| fakeUiStateFlow.value = State.Ready( | ||
| accounts = persistentListOf(account), | ||
| currentAccount = account, | ||
| contactsToImport = persistentListOf(), | ||
| contactsAlreadyImported = persistentListOf(), | ||
| ) | ||
|
|
||
| setScreenContent() | ||
|
|
||
| onNodeWithTag(SIM_IMPORT_IMPORT_BUTTON_TEST_TAG).assertIsNotEnabled() | ||
| onNodeWithTag(SIM_IMPORT_SELECT_ALL_TEST_TAG).assertIsNotEnabled() | ||
| onNodeWithTag(SIM_IMPORT_DESELECT_ALL_TEST_TAG).assertIsNotEnabled() | ||
| } | ||
|
|
||
| private fun ComposeUiTest.setScreenContent() { | ||
| setContent { | ||
| SimImportScreen( | ||
| effectHandler = effectHandler, | ||
| screenModel = screenModel, | ||
| ) | ||
| } | ||
| } | ||
| } |
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.
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.
Duplicate of line 17.
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.
Copied from GrapheneOS/app-docs#2. Already fixed here and left a comment there.