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/1837/head
Alex Vanyo 4 years ago committed by Don Turner
parent 36c4e3dcf9
commit b6eae2907c

@ -169,6 +169,11 @@ class ForYouViewModel @Inject constructor(
viewModelScope.launch { viewModelScope.launch {
topicsRepository.setFollowedTopicIds(inProgressTopicSelection) 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 @Test
fun newsResourceSelectionUpdatesAfterLoadingFollowedTopics() = runTest { fun newsResourceSelectionUpdatesAfterLoadingFollowedTopics() = runTest {
viewModel.uiState viewModel.uiState

Loading…
Cancel
Save