Skip to content

Commit

Permalink
Merge pull request #20103 from wordpress-mobile/issue/20091-reader-ia…
Browse files Browse the repository at this point in the history
…-show-onboarding-for-new-reader-users

[Reader IA] Show onboarding for users with no tags or dailyprompt tag only
  • Loading branch information
develric authored Feb 1, 2024
2 parents eeec540 + 2ce97ec commit 12f0213
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 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 @@ -66,7 +66,7 @@
<com.google.android.material.textview.MaterialTextView
style="@style/ReaderTextView.Interests.Title"
android:id="@+id/title"
android:text="@string/reader_label_choose_your_interests"
android:text="@string/reader_label_choose_interests"
android:visibility="gone"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@id/guideline_beginning"
Expand Down
2 changes: 1 addition & 1 deletion WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2162,7 +2162,7 @@
<string name="reader_label_local_related_posts">More from %s</string>
<string name="reader_label_global_related_posts">More on WordPress.com</string>
<string name="reader_label_visit">Visit site</string>
<string name="reader_label_choose_your_interests">Choose your topics</string>
<string name="reader_label_choose_interests">Choose your interests</string>
<string name="reader_view_comments">View comments</string>
<string name="reader_welcome_banner">Welcome to Reader. Discover millions of blogs at your fingertips.</string>
<string name="reader_label_toolbar_back">Back</string>
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 12f0213

Please sign in to comment.