Reset in-progress topic selection upon saving

Previously, the in-progress topic selection wasn't reset upon saving. This meant that clearing out the selected topics (from the topics tab) would bring back the topic selection that was last used.

Bug: 228050946

Change-Id: I3d52baf6396b41e2116f38c89a79b419c90c63b5
pull/2/head
Alex Vanyo 3 years ago committed by Don Turner
parent e325cf9bce
commit 0d6dd0b079

@ -169,6 +169,11 @@ class ForYouViewModel @Inject constructor(
viewModelScope.launch {
topicsRepository.setFollowedTopicIds(inProgressTopicSelection)
// Clear out the in-progress selection after saving it
withMutableSnapshot {
inProgressTopicSelection = emptySet()
}
}
}
}

@ -328,6 +328,69 @@ class ForYouViewModelTest {
}
}
@Test
fun topicSelectionIsResetAfterSavingTopicsAndRemovingThem() = runTest {
viewModel.uiState
.test {
awaitItem()
topicsRepository.sendTopics(sampleTopics)
topicsRepository.setFollowedTopicIds(emptySet())
newsRepository.sendNewsResources(sampleNewsResources)
awaitItem()
viewModel.updateTopicSelection(1, isChecked = true)
awaitItem()
viewModel.saveFollowedTopics()
awaitItem()
topicsRepository.setFollowedTopicIds(emptySet())
assertEquals(
ForYouFeedUiState.PopulatedFeed.FeedWithTopicSelection(
topics = listOf(
FollowableTopic(
topic = Topic(
id = 0,
name = "Headlines",
shortDescription = "",
longDescription = "long description",
url = "URL",
imageUrl = "image URL",
),
isFollowed = false
),
FollowableTopic(
topic = Topic(
id = 1,
name = "UI",
shortDescription = "",
longDescription = "long description",
url = "URL",
imageUrl = "image URL",
),
isFollowed = false
),
FollowableTopic(
topic = Topic(
id = 2,
name = "Tools",
shortDescription = "",
longDescription = "long description",
url = "URL",
imageUrl = "image URL",
),
isFollowed = false
)
),
feed = emptyList()
),
awaitItem()
)
cancel()
}
}
@Test
fun newsResourceSelectionUpdatesAfterLoadingFollowedTopics() = runTest {
viewModel.uiState

Loading…
Cancel
Save