Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions app/jacoco-rules/instrumented/included-class-patterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
com/android/messaging/ui/appsettings/**
com/android/messaging/ui/contact/**
com/android/messaging/ui/conversation/**
com/android/messaging/ui/conversationlist/**
com/android/messaging/ui/core/**
1 change: 1 addition & 0 deletions app/jacoco-rules/unit/included-class-patterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ com/android/messaging/sms/**
com/android/messaging/ui/appsettings/**
com/android/messaging/ui/contact/**
com/android/messaging/ui/conversation/**
com/android/messaging/ui/conversationlist/**
com/android/messaging/ui/core/**
com/android/messaging/util/core/**
com/android/messaging/util/db/**
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ package com.android.messaging.ui.appsettings.general.ui

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsSelected
import androidx.compose.ui.test.hasScrollAction
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.isDialog
import androidx.compose.ui.test.isSelectable
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollToNode
import com.android.messaging.R
import com.android.messaging.data.appsettings.model.ConversationSwipeOption
import com.android.messaging.data.appsettings.model.ConversationSwipeSettings
import com.android.messaging.ui.appsettings.general.model.AppSettingsAction as Action
import com.android.messaging.ui.appsettings.general.model.AppSettingsUiState
import com.android.messaging.ui.core.AppTheme
Expand Down Expand Up @@ -112,9 +117,11 @@ class AppSettingsScreenTest {
setContent(appSettings = appSettings)

val debugTitle = composeTestRule.activity.getString(R.string.debug_category_pref_title)
scrollToText(text = debugTitle)
composeTestRule.onNodeWithText(debugTitle).assertIsDisplayed()

val dumpSmsTitle = composeTestRule.activity.getString(R.string.dump_sms_pref_title)
scrollToText(text = dumpSmsTitle)
composeTestRule.onNodeWithText(dumpSmsTitle).assertIsDisplayed()

val dumpMmsTitle = composeTestRule.activity.getString(R.string.dump_mms_pref_title)
Expand All @@ -132,6 +139,7 @@ class AppSettingsScreenTest {
setContent(appSettings = appSettings)

val title = composeTestRule.activity.getString(R.string.dump_sms_pref_title)
scrollToText(text = title)
composeTestRule.onNodeWithText(title).performClick()

verify(exactly = 1) {
Expand All @@ -157,11 +165,104 @@ class AppSettingsScreenTest {
}
}

@Test
fun swipeSection_showsSelectedOptionForEachDirection() {
val appSettings = AppSettingsUiState(
conversationSwipeSettings = ConversationSwipeSettings(
startToEnd = ConversationSwipeOption.Delete,
endToStart = ConversationSwipeOption.ToggleRead,
),
)

setContent(appSettings = appSettings)

val categoryTitle = composeTestRule.activity.getString(R.string.swipe_category_pref_title)
scrollToText(text = categoryTitle)
composeTestRule.onNodeWithText(categoryTitle).assertIsDisplayed()

val startToEndTitle = composeTestRule.activity.getString(
R.string.swipe_start_to_end_pref_title,
)
scrollToText(text = startToEndTitle)
composeTestRule
.onNode(hasText(startToEndTitle) and hasText(string(R.string.action_delete)))
.assertIsDisplayed()

val endToStartTitle = composeTestRule.activity.getString(
R.string.swipe_end_to_start_pref_title,
)
scrollToText(text = endToStartTitle)
composeTestRule
.onNode(
hasText(endToStartTitle) and hasText(string(R.string.swipe_action_toggle_read)),
)
.assertIsDisplayed()
}

@Test
fun swipeStartToEndSelection_delegatesToScreenModelAndClosesDialog() {
setContent()

val title = composeTestRule.activity.getString(R.string.swipe_start_to_end_pref_title)
scrollToText(text = title)
composeTestRule.onNodeWithText(title).performClick()

composeTestRule.onNode(isDialog()).assertIsDisplayed()
composeTestRule
.onNode(isSelectable() and hasText(string(R.string.swipe_action_toggle_read)))
.assertIsSelected()
composeTestRule
.onNode(isSelectable() and hasText(string(R.string.action_delete)))
.performClick()

verify(exactly = 1) {
onAction(
Action.ConversationSwipeStartToEndOptionChanged(ConversationSwipeOption.Delete),
)
}
composeTestRule.onNode(isDialog()).assertDoesNotExist()
}

@Test
fun swipeEndToStartSelection_delegatesToScreenModel() {
setContent()

val title = composeTestRule.activity.getString(R.string.swipe_end_to_start_pref_title)
scrollToText(text = title)
composeTestRule.onNodeWithText(title).performClick()

composeTestRule
.onNode(isSelectable() and hasText(string(R.string.swipe_action_toggle_read)))
.performClick()

verify(exactly = 1) {
onAction(
Action.ConversationSwipeEndToStartOptionChanged(ConversationSwipeOption.ToggleRead),
)
}
}

@Test
fun swipeOptionDialog_cancelClosesWithoutChangingOption() {
setContent()

val title = composeTestRule.activity.getString(R.string.swipe_end_to_start_pref_title)
scrollToText(text = title)
composeTestRule.onNodeWithText(title).performClick()
composeTestRule.onNodeWithText(string(android.R.string.cancel)).performClick()

composeTestRule.onNode(isDialog()).assertDoesNotExist()
verify(exactly = 0) {
onAction(any<Action.ConversationSwipeEndToStartOptionChanged>())
}
}

@Test
fun licensesClick_delegatesToScreenModel() {
setContent()

val title = composeTestRule.activity.getString(R.string.menu_license)
scrollToText(text = title)
composeTestRule.onNodeWithText(title).performClick()

verify(exactly = 1) {
Expand Down Expand Up @@ -240,6 +341,10 @@ class AppSettingsScreenTest {
composeTestRule.onNodeWithText(advancedTitle).assertDoesNotExist()
}

private fun string(resId: Int): String {
return composeTestRule.activity.getString(resId)
}

private fun scrollToText(text: String) {
composeTestRule.onNode(hasScrollAction()).performScrollToNode(hasText(text))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import android.content.res.Resources
import com.android.messaging.Factory
import com.android.messaging.R
import com.android.messaging.data.appsettings.model.AppBooleanPref
import com.android.messaging.data.appsettings.model.ConversationSwipeOption
import com.android.messaging.data.appsettings.model.ConversationSwipePref
import com.android.messaging.data.appsettings.model.ConversationSwipeSettings
import com.android.messaging.data.appsettings.model.LinkOpeningMode
import com.android.messaging.data.appsettings.repository.AppSettingsRepositoryImpl
import com.android.messaging.data.debug.DebugFeaturesProvider
Expand Down Expand Up @@ -71,6 +74,12 @@ internal class AppSettingsRepositoryImplTest {
every {
context.getString(R.string.youtube_link_previews_pref_key)
} returns YOUTUBE_LINK_PREVIEWS_PREF_KEY
every {
context.getString(R.string.conversation_swipe_start_to_end_pref_key)
} returns SWIPE_START_TO_END_PREF_KEY
every {
context.getString(R.string.conversation_swipe_end_to_start_pref_key)
} returns SWIPE_END_TO_START_PREF_KEY
every {
resources.getBoolean(R.bool.youtube_link_previews_pref_default)
} returns YOUTUBE_LINK_PREVIEWS_DEFAULT
Expand Down Expand Up @@ -116,6 +125,8 @@ internal class AppSettingsRepositoryImplTest {
every {
appPrefs.getString(LINK_OPENING_PREF_KEY, LINK_OPENING_DEFAULT)
} returns LinkOpeningMode.OpenOnTap.prefValue
every { appPrefs.getString(SWIPE_START_TO_END_PREF_KEY, null) } returns "Delete"
every { appPrefs.getString(SWIPE_END_TO_START_PREF_KEY, null) } returns null

val result = createRepository(
ioDispatcher = UnconfinedTestDispatcher(testScheduler),
Expand All @@ -127,6 +138,13 @@ internal class AppSettingsRepositoryImplTest {
assertTrue(result.inConversationSoundEnabled)
assertTrue(result.youTubeLinkPreviewsEnabled)
assertEquals(LinkOpeningMode.OpenOnTap, result.linkOpeningMode)
assertEquals(
ConversationSwipeSettings(
startToEnd = ConversationSwipeOption.Delete,
endToStart = ConversationSwipeOption.Archive,
),
result.conversationSwipeSettings,
)
assertTrue(result.isDebugEnabled)
assertTrue(result.dumpSmsEnabled)
assertFalse(result.dumpMmsEnabled)
Expand Down Expand Up @@ -200,6 +218,64 @@ internal class AppSettingsRepositoryImplTest {
}
}

@Test
fun setConversationSwipeOptions_writesExpectedStringToEachPreferenceKey() {
runTest {
every { appPrefs.putString(any(), any()) } just runs
val repository = createRepository(
ioDispatcher = UnconfinedTestDispatcher(testScheduler),
)

repository.setConversationSwipeOption(
pref = ConversationSwipePref.START_TO_END,
option = ConversationSwipeOption.Archive,
)
repository.setConversationSwipeOption(
pref = ConversationSwipePref.END_TO_START,
option = ConversationSwipeOption.ToggleRead,
)

verify(exactly = 1) {
appPrefs.putString(SWIPE_START_TO_END_PREF_KEY, "Archive")
appPrefs.putString(SWIPE_END_TO_START_PREF_KEY, "ToggleRead")
}
}
}

@Test
fun getConversationSwipeSettings_readsStoredOptions() {
runTest {
every { appPrefs.getString(SWIPE_START_TO_END_PREF_KEY, null) } returns "Archive"
every { appPrefs.getString(SWIPE_END_TO_START_PREF_KEY, null) } returns "Delete"

val result = createRepository(
ioDispatcher = UnconfinedTestDispatcher(testScheduler),
).getConversationSwipeSettings()

assertEquals(
ConversationSwipeSettings(
startToEnd = ConversationSwipeOption.Archive,
endToStart = ConversationSwipeOption.Delete,
),
result,
)
}
}

@Test
fun getConversationSwipeSettings_fallsBackToDefaultsWhenMissingOrUnknown() {
runTest {
every { appPrefs.getString(SWIPE_START_TO_END_PREF_KEY, null) } returns null
every { appPrefs.getString(SWIPE_END_TO_START_PREF_KEY, null) } returns "UnknownValue"

val result = createRepository(
ioDispatcher = UnconfinedTestDispatcher(testScheduler),
).getConversationSwipeSettings()

assertEquals(ConversationSwipeSettings.Default, result)
}
}

@Test
fun isYouTubeLinkPreviewsEnabled_readsPreferenceWithResourceDefault() {
runTest {
Expand Down Expand Up @@ -315,6 +391,8 @@ internal class AppSettingsRepositoryImplTest {
private const val LINK_OPENING_PREF_KEY = "link_opening"
private const val SEND_SOUND_DEFAULT = true
private const val SEND_SOUND_PREF_KEY = "send_sound"
private const val SWIPE_END_TO_START_PREF_KEY = "conversation_swipe_end_to_start"
private const val SWIPE_START_TO_END_PREF_KEY = "conversation_swipe_start_to_end"
private const val YOUTUBE_LINK_PREVIEWS_DEFAULT = false
private const val YOUTUBE_LINK_PREVIEWS_PREF_KEY = "youtube_link_previews"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.android.messaging.ui.appsettings.general

import app.cash.turbine.test
import com.android.messaging.data.appsettings.model.ConversationSwipeOption
import com.android.messaging.data.appsettings.model.LinkOpeningMode
import com.android.messaging.testutil.MainDispatcherRule
import com.android.messaging.ui.appsettings.general.delegate.AppSettingsDelegate
Expand Down Expand Up @@ -123,6 +124,46 @@ class AppSettingsViewModelTest {
}
}

@Test
fun onConversationSwipeStartToEndOptionChanged_delegatesToAppSettings() {
runTest(context = mainDispatcherRule.testDispatcher) {
val delegate = mockDelegate()
val viewModel = createViewModel(delegate = delegate)

viewModel.onAction(
Action.ConversationSwipeStartToEndOptionChanged(
option = ConversationSwipeOption.Delete,
),
)

verify(exactly = 1) {
delegate.onConversationSwipeStartToEndOptionChanged(
option = ConversationSwipeOption.Delete,
)
}
}
}

@Test
fun onConversationSwipeEndToStartOptionChanged_delegatesToAppSettings() {
runTest(context = mainDispatcherRule.testDispatcher) {
val delegate = mockDelegate()
val viewModel = createViewModel(delegate = delegate)

viewModel.onAction(
Action.ConversationSwipeEndToStartOptionChanged(
option = ConversationSwipeOption.ToggleRead,
),
)

verify(exactly = 1) {
delegate.onConversationSwipeEndToStartOptionChanged(
option = ConversationSwipeOption.ToggleRead,
)
}
}
}

@Test
fun onDefaultSmsAppClick_whenDefault_emitsOpenManageDefaultApps() {
runTest(context = mainDispatcherRule.testDispatcher) {
Expand Down
Loading