Skip to content

Commit

Permalink
Update ReaderViewModel unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RenanLukas committed May 22, 2024
1 parent 90fbfec commit 9d73d4a
Showing 1 changed file with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,10 @@ class ReaderViewModelTest : BaseUnitTest() {
}

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

triggerContentDisplay()
viewModel.onFeedContentLoaded()
val observers = initObservers()

val announcementCardUiState = observers.announcementCardStateEvents.first()
Expand All @@ -536,10 +536,10 @@ class ReaderViewModelTest : BaseUnitTest() {
}

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

triggerContentDisplay()
viewModel.onFeedContentLoaded()
val observers = initObservers()

val announcementCardUiState = observers.announcementCardStateEvents.first()
Expand All @@ -557,32 +557,41 @@ class ReaderViewModelTest : BaseUnitTest() {
}

@Test
fun `Should show announcement card if feature flag is enabled and app preference returns true`() =
fun `Should show announcement card if feature flag is enabled, app preference returns true and feed is Discover`() =
testWithNonEmptyTags {
whenever(readerAnnouncementCardFeatureConfig.isEnabled()).thenReturn(true)
whenever(appPrefsWrapper.shouldShowReaderAnnouncementCard()).thenReturn(true)
triggerContentDisplay()
val observers = initObservers()
val readerTag = ReaderTag("Discover", "Discover", "Discover", DISCOVER_PATH, ReaderTagType.DEFAULT)
whenever(readerAnnouncementCardFeatureConfig.isEnabled()).thenReturn(true)
whenever(appPrefsWrapper.shouldShowReaderAnnouncementCard()).thenReturn(true)
val observers = initObservers()
triggerContentDisplay()
viewModel.updateSelectedContent(readerTag)
viewModel.onFeedContentLoaded()

val announcementCardUiState = observers.announcementCardStateEvents.first()
assertTrue(announcementCardUiState.shouldShow)
}
val announcementCardUiState = observers.announcementCardStateEvents.first()
assertTrue(announcementCardUiState.shouldShow)
}

@Test
fun `Should NOT show announcement card if feature flag is disabled`() = testWithNonEmptyTags {
whenever(readerAnnouncementCardFeatureConfig.isEnabled()).thenReturn(false)
triggerContentDisplay()
val observers = initObservers()
val readerTag = ReaderTag("Discover", "Discover", "Discover", DISCOVER_PATH, ReaderTagType.DEFAULT)
whenever(readerAnnouncementCardFeatureConfig.isEnabled()).thenReturn(false)
val observers = initObservers()
triggerContentDisplay()
viewModel.updateSelectedContent(readerTag)
viewModel.onFeedContentLoaded()

val announcementCardUiState = observers.announcementCardStateEvents.first()
assertFalse(announcementCardUiState.shouldShow)
}
val announcementCardUiState = observers.announcementCardStateEvents.first()
assertFalse(announcementCardUiState.shouldShow)
}

@Test
fun `Should NOT show announcement card if app preference returns false`() = testWithNonEmptyTags {
val readerTag = ReaderTag("Discover", "Discover", "Discover", DISCOVER_PATH, ReaderTagType.DEFAULT)
whenever(readerAnnouncementCardFeatureConfig.isEnabled()).thenReturn(true)
whenever(appPrefsWrapper.shouldShowReaderAnnouncementCard()).thenReturn(false)
triggerContentDisplay()
viewModel.updateSelectedContent(readerTag)
viewModel.onFeedContentLoaded()
val observers = initObservers()

val announcementCardUiState = observers.announcementCardStateEvents.first()
Expand Down

0 comments on commit 9d73d4a

Please sign in to comment.