Skip to content

Commit

Permalink
Show Discover Welcome state if only following dailyprompt tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Horta committed Feb 1, 2024
1 parent e27b845 commit 2ce97ec
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.wordpress.android.models.discover.ReaderDiscoverCard.ReaderRecommende
import org.wordpress.android.models.discover.ReaderDiscoverCards
import org.wordpress.android.modules.IO_THREAD
import org.wordpress.android.modules.UI_THREAD
import org.wordpress.android.ui.bloggingprompts.BloggingPromptsPostTagProvider.Companion.BLOGGING_PROMPT_TAG
import org.wordpress.android.ui.pages.SnackbarMessageHolder
import org.wordpress.android.ui.reader.ReaderTypes.ReaderPostListType.TAG_FOLLOWED
import org.wordpress.android.ui.reader.discover.ReaderCardUiState.ReaderPostNewUiState
Expand Down Expand Up @@ -149,7 +150,10 @@ class ReaderDiscoverViewModel @Inject constructor(
_uiState.addSource(readerDiscoverDataProvider.discoverFeed) { posts ->
launch {
val userTags = getFollowedTagsUseCase.get()
if (userTags.isEmpty()) {

// since new users have the dailyprompt tag followed by default, we need to ignore them when
// checking if the user has any tags followed, so we show the onboarding state (ShowNoFollowedTags)
if (userTags.filterNot { it.tagSlug == BLOGGING_PROMPT_TAG }.isEmpty()) {
_uiState.value = DiscoverUiState.EmptyUiState.ShowNoFollowedTagsUiState {
parentViewModel.onShowReaderInterests()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.wordpress.android.R
import org.wordpress.android.analytics.AnalyticsTracker
import org.wordpress.android.models.ReaderTag
import org.wordpress.android.models.ReaderTagList
import org.wordpress.android.ui.bloggingprompts.BloggingPromptsPostTagProvider.Companion.BLOGGING_PROMPT_TAG
import org.wordpress.android.ui.pages.SnackbarMessageHolder
import org.wordpress.android.ui.reader.discover.interests.ReaderInterestsFragment.EntryPoint
import org.wordpress.android.ui.reader.discover.interests.ReaderInterestsViewModel.DoneButtonUiState.DoneButtonDisabledUiState
Expand Down Expand Up @@ -92,7 +93,9 @@ class ReaderInterestsViewModel @Inject constructor(
}

private fun checkAndLoadInterests(userTags: ReaderTagList) {
if (userTags.isEmpty()) {
// since new users have the dailyprompt tag followed by default, we need to ignore them when
// checking if the user has any tags followed, so we show the onboarding state (ShowNoFollowedTags)
if (userTags.filterNot { it.tagSlug == BLOGGING_PROMPT_TAG }.isEmpty()) {
loadInterests(userTags)
} else {
parentViewModel?.onCloseReaderInterests()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.wordpress.android.models.ReaderBlog
import org.wordpress.android.models.ReaderPost
import org.wordpress.android.models.ReaderTag
import org.wordpress.android.models.ReaderTagList
import org.wordpress.android.models.ReaderTagType
import org.wordpress.android.models.discover.ReaderDiscoverCard.InterestsYouMayLikeCard
import org.wordpress.android.models.discover.ReaderDiscoverCard.ReaderPostCard
import org.wordpress.android.models.discover.ReaderDiscoverCard.ReaderRecommendedBlogsCard
Expand Down Expand Up @@ -292,6 +293,29 @@ class ReaderDiscoverViewModelTest : BaseUnitTest() {
assertThat(uiStates[1]).isInstanceOf(ShowNoFollowedTagsUiState::class.java)
}

@Test
fun `ShowFollowInterestsEmptyUiState is shown when the user follows only the daily prompt tag`() = test {
// Arrange
val tagsWithDailyPrompt = ReaderTagList().apply {
add(
ReaderTag(
"dailyprompt",
"dailyprompt",
"dailyprompt",
"https://public-api.wordpress.com/rest/v1.2/read/tags/dailyprompt/posts",
ReaderTagType.DEFAULT
)
)
}
whenever(getFollowedTagsUseCase.get()).thenReturn(tagsWithDailyPrompt)
val uiStates = init().uiStates
// Act
viewModel.start(parentViewModel)
// Assert
assertThat(uiStates.size).isEqualTo(2)
assertThat(uiStates[1]).isInstanceOf(ShowNoFollowedTagsUiState::class.java)
}

@Test
fun `ShowNoPostsUiState is shown when the discoverFeed does not contain any posts`() = test {
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ class ReaderInterestsViewModelTest : BaseUnitTest() {
verify(readerTagRepository, times(1)).getInterests()
}

@Test
fun `getInterests invoked if only daily prompt user tag received from repo`() =
testWithDailyPromptUserTag {
// Given
val interests = getInterests()
whenever(readerTagRepository.getInterests()).thenReturn(SuccessWithData(interests))

// When
initViewModel()

// Then
verify(readerTagRepository, times(1)).getInterests()
}

@Test
fun `discover close reader screen triggered if non empty user tags are received from repo`() =
testWithNonEmptyUserTags {
Expand Down Expand Up @@ -602,6 +616,25 @@ class ReaderInterestsViewModelTest : BaseUnitTest() {
}
}

private fun <T> testWithDailyPromptUserTag(block: suspend CoroutineScope.() -> T) {
test {
val tagsWithDailyPrompt = ReaderTagList().apply {
add(
ReaderTag(
"dailyprompt",
"dailyprompt",
"dailyprompt",
"https://public-api.wordpress.com/rest/v1.2/read/tags/dailyprompt/posts",
ReaderTagType.DEFAULT
)
)
}

whenever(readerTagRepository.getUserTags()).thenReturn(SuccessWithData(tagsWithDailyPrompt))
block()
}
}

private fun <T> testWithFailedUserTags(block: suspend CoroutineScope.() -> T) {
test {
whenever(readerTagRepository.getUserTags()).thenReturn(NetworkUnavailable)
Expand Down

0 comments on commit 2ce97ec

Please sign in to comment.