mirror of
https://github.com/ProtonMail/android-mail.git
synced 2026-05-15 09:50:40 +00:00
Prevent mailbox reload when expanding active folder
ET-6199
This commit is contained in:
+2
-1
@@ -150,6 +150,7 @@ import kotlinx.coroutines.flow.channelFlow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
@@ -1439,7 +1440,7 @@ class MailboxViewModel @Inject constructor(
|
||||
|
||||
private fun observeMailLabelChangeRequests(): Flow<MailLabel> = observeSelectedMailLabelId()
|
||||
.mapToExistingLabel()
|
||||
.distinctUntilChanged()
|
||||
.distinctUntilChangedBy { it.id }
|
||||
|
||||
private fun Flow<MailboxState>.observeSearchQuery() = this.map { it.mailboxListState as? MailboxListState.Data }
|
||||
.mapNotNull { it?.searchState?.searchQuery }
|
||||
|
||||
+49
@@ -1706,6 +1706,55 @@ internal class MailboxViewModelTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `mailbox pager is not recreated when expanded state of selected folder changes`() = runTest {
|
||||
// Given
|
||||
val folder = MailLabelTestData.buildCustomFolder(
|
||||
id = "folder-1",
|
||||
isExpanded = false,
|
||||
children = listOf("child-1")
|
||||
)
|
||||
val child = MailLabelTestData.buildCustomFolder(id = "child-1", parent = folder)
|
||||
val mailLabelsFlow = MutableStateFlow(
|
||||
MailLabels(
|
||||
system = MailLabelTestData.dynamicSystemLabels,
|
||||
folders = listOf(folder, child),
|
||||
labels = emptyList()
|
||||
)
|
||||
)
|
||||
val currentLocationFlow = MutableStateFlow<MailLabelId>(folder.id)
|
||||
every { observeMailLabels(userId) } returns mailLabelsFlow
|
||||
every { observeLoadedMailLabelId() } returns currentLocationFlow
|
||||
every { observeSelectedMailLabelId() } returns currentLocationFlow
|
||||
coEvery { getSelectedMailLabelId() } returns folder.id
|
||||
every { mailboxReducer.newStateFrom(any(), any()) } returns createMailboxDataState()
|
||||
expectPagerMock(
|
||||
selectedLabelId = folder.id,
|
||||
pagingDataFlow = flowOf(PagingData.from(listOf(unreadMailboxItem)))
|
||||
)
|
||||
|
||||
mailboxViewModel.items.test {
|
||||
awaitItem()
|
||||
verify(exactly = 1) {
|
||||
pagerFactory.create(userId, folder.id, any(), any())
|
||||
}
|
||||
|
||||
// When
|
||||
mailLabelsFlow.value = MailLabels(
|
||||
system = MailLabelTestData.dynamicSystemLabels,
|
||||
folders = listOf(folder.copy(isExpanded = true), child),
|
||||
labels = emptyList()
|
||||
)
|
||||
|
||||
// Then
|
||||
expectNoEvents()
|
||||
verify(exactly = 1) {
|
||||
pagerFactory.create(userId, folder.id, any(), any())
|
||||
}
|
||||
cancelAndIgnoreRemainingEvents()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `mailbox pager is recreated when view mode changes`() = runTest {
|
||||
// Given
|
||||
|
||||
Reference in New Issue
Block a user