Skip to content

Commit

Permalink
Add the Tags feed announcement item if it's enabled only
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Horta committed May 20, 2024
1 parent 8c20b4b commit 9d1a4b9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,30 @@ class ReaderViewModel @Inject constructor(
}

private fun loadAnnouncementCard() {
_announcementCardState.value = AnnouncementCardUiState(
shouldShow = readerAnnouncementCardFeatureConfig.isEnabled() &&
appPrefsWrapper.shouldShowReaderAnnouncementCard(),
items = listOf(
val items = mutableListOf<ReaderAnnouncementCardItemData>()

if (readerTagsFeedFeatureConfig.isEnabled()) {
items.add(
ReaderAnnouncementCardItemData(
iconRes = R.drawable.ic_reader_tag,
titleRes = R.string.reader_announcement_card_tags_stream_title,
descriptionRes = R.string.reader_announcement_card_tags_stream_description,
),
ReaderAnnouncementCardItemData(
iconRes = R.drawable.ic_reader_preferences,
titleRes = R.string.reader_announcement_card_reading_preferences_title,
descriptionRes = R.string.reader_announcement_card_reading_preferences_description,
),
),
)
)
}

items.add(
ReaderAnnouncementCardItemData(
iconRes = R.drawable.ic_reader_preferences,
titleRes = R.string.reader_announcement_card_reading_preferences_title,
descriptionRes = R.string.reader_announcement_card_reading_preferences_description,
)
)

_announcementCardState.value = AnnouncementCardUiState(
shouldShow = readerAnnouncementCardFeatureConfig.isEnabled() &&
appPrefsWrapper.shouldShowReaderAnnouncementCard(),
items = items,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,16 @@ class ReaderViewModelTest : BaseUnitTest() {
}

@Test
fun `Should load announcement card correctly`() = testWithNonEmptyTags {
fun `Should load announcement card correctly with tags item`() = testWithNonEmptyTags {
whenever(readerTagsFeedFeatureConfig.isEnabled()).thenReturn(true)

triggerContentDisplay()
val observers = initObservers()

val announcementCardUiState = observers.announcementCardStateEvents.first()

assertThat(announcementCardUiState.items).hasSize(2)

val tagsFeedItem = announcementCardUiState.items[0]
assertThat(tagsFeedItem.iconRes).isEqualTo(R.drawable.ic_reader_tag)
assertThat(tagsFeedItem.titleRes).isEqualTo(R.string.reader_announcement_card_tags_stream_title)
Expand All @@ -531,6 +535,27 @@ class ReaderViewModelTest : BaseUnitTest() {
)
}

@Test
fun `Should load announcement card correctly without tags item`() = testWithNonEmptyTags {
whenever(readerTagsFeedFeatureConfig.isEnabled()).thenReturn(false)

triggerContentDisplay()
val observers = initObservers()

val announcementCardUiState = observers.announcementCardStateEvents.first()

assertThat(announcementCardUiState.items).hasSize(1)

val readerPreferencesItem = announcementCardUiState.items[0]
assertThat(readerPreferencesItem.iconRes).isEqualTo(R.drawable.ic_reader_preferences)
assertThat(readerPreferencesItem.titleRes).isEqualTo(
R.string.reader_announcement_card_reading_preferences_title
)
assertThat(readerPreferencesItem.descriptionRes).isEqualTo(
R.string.reader_announcement_card_reading_preferences_description
)
}

@Test
fun `Should show announcement card if feature flag is enabled and app preference returns true`() =
testWithNonEmptyTags {
Expand Down

0 comments on commit 9d1a4b9

Please sign in to comment.