Skip to content

Commit

Permalink
Fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Nov 15, 2024
1 parent bf6377a commit e5f5734
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ class ReaderReadingPreferencesTrackerTest {
verify(analyticsTrackerWrapper).track(Stat.READER_READING_PREFERENCES_CLOSED)
}

@Test
fun `when trackFeedbackTapped is called, then track event`() {
tracker.trackFeedbackTapped()

verify(analyticsTrackerWrapper).track(Stat.READER_READING_PREFERENCES_FEEDBACK_TAPPED)
}

@Test
fun `when trackItemTapped is called with theme, then track event`() {
ReaderReadingPreferences.Theme.values().forEach { theme ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.wordpress.android.ui.reader.tracker.ReaderReadingPreferencesTracker
import org.wordpress.android.ui.reader.usecases.ReaderGetReadingPreferencesSyncUseCase
import org.wordpress.android.ui.reader.usecases.ReaderSaveReadingPreferencesUseCase
import org.wordpress.android.ui.reader.viewmodels.ReaderReadingPreferencesViewModel.ActionEvent
import org.wordpress.android.util.config.ReaderReadingPreferencesFeedbackFeatureConfig

@ExperimentalCoroutinesApi
class ReaderReadingPreferencesViewModelTest : BaseUnitTest() {
Expand All @@ -31,9 +30,6 @@ class ReaderReadingPreferencesViewModelTest : BaseUnitTest() {
@Mock
lateinit var saveReadingPreferences: ReaderSaveReadingPreferencesUseCase

@Mock
lateinit var readingPreferencesFeedbackFeatureConfig: ReaderReadingPreferencesFeedbackFeatureConfig

@Mock
lateinit var readingPreferencesTracker: ReaderReadingPreferencesTracker

Expand All @@ -49,7 +45,6 @@ class ReaderReadingPreferencesViewModelTest : BaseUnitTest() {
viewModel = ReaderReadingPreferencesViewModel(
getReadingPreferences,
saveReadingPreferences,
readingPreferencesFeedbackFeatureConfig,
readingPreferencesTracker,
viewModelDispatcher,
)
Expand Down Expand Up @@ -211,46 +206,10 @@ class ReaderReadingPreferencesViewModelTest : BaseUnitTest() {
assertThat(updateEvent).isEqualTo(ActionEvent.UpdatePostDetails)
}

@Test
fun `when onSendFeedbackClick is called then it emits OpenWebView action event`() = test {
// When
viewModel.onSendFeedbackClick()

// Then
val openWebViewEvent = collectedEvents.last() as ActionEvent.OpenWebView
assertThat(openWebViewEvent.url).isEqualTo(EXPECTED_FEEDBACK_URL)
}

@Test
fun `when readerReadingPreferencesFeedbackFeatureConfig is true then isFeedbackEnabled emits true`() = test {
// Given
whenever(readingPreferencesFeedbackFeatureConfig.isEnabled()).thenReturn(true)

// When
viewModel.init()

// Then
val isFeedbackEnabled = viewModel.isFeedbackEnabled.first()
assertThat(isFeedbackEnabled).isTrue()
}

@Test
fun `when readerReadingPreferencesFeedbackFeatureConfig is false then isFeedbackEnabled emits false`() = test {
// Given
whenever(readingPreferencesFeedbackFeatureConfig.isEnabled()).thenReturn(false)

// When
viewModel.init()

// Then
val isFeedbackEnabled = viewModel.isFeedbackEnabled.first()
assertThat(isFeedbackEnabled).isFalse()
}

// analytics tests
@Test
fun `when onScreenOpened is called then it should track the screen opened event`() = test {
ReaderReadingPreferencesTracker.Source.values().forEach { source ->
ReaderReadingPreferencesTracker.Source.entries.forEach { source ->
// When
viewModel.onScreenOpened(source)

Expand All @@ -268,18 +227,9 @@ class ReaderReadingPreferencesViewModelTest : BaseUnitTest() {
verify(readingPreferencesTracker).trackScreenClosed()
}

@Test
fun `when onSendFeedbackClick is called then it should track the feedback tapped event`() = test {
// When
viewModel.onSendFeedbackClick()

// Then
verify(readingPreferencesTracker).trackFeedbackTapped()
}

@Test
fun `when onThemeClick is called then it should track the theme tapped event`() = test {
ReaderReadingPreferences.Theme.values().forEach { theme ->
ReaderReadingPreferences.Theme.entries.forEach { theme ->
// When
viewModel.onThemeClick(theme)

Expand All @@ -290,7 +240,7 @@ class ReaderReadingPreferencesViewModelTest : BaseUnitTest() {

@Test
fun `when onFontFamilyClick is called then it should track the font family tapped event`() = test {
ReaderReadingPreferences.FontFamily.values().forEach { fontFamily ->
ReaderReadingPreferences.FontFamily.entries.forEach { fontFamily ->
// When
viewModel.onFontFamilyClick(fontFamily)

Expand All @@ -301,7 +251,7 @@ class ReaderReadingPreferencesViewModelTest : BaseUnitTest() {

@Test
fun `when onFontSizeClick is called then it should track the font size tapped event`() = test {
ReaderReadingPreferences.FontSize.values().forEach { fontSize ->
ReaderReadingPreferences.FontSize.entries.forEach { fontSize ->
// When
viewModel.onFontSizeClick(fontSize)

Expand All @@ -325,6 +275,5 @@ class ReaderReadingPreferencesViewModelTest : BaseUnitTest() {

companion object {
private val DEFAULT_READING_PREFERENCES = ReaderReadingPreferences()
private const val EXPECTED_FEEDBACK_URL = "https://automattic.survey.fm/reader-customization-survey"
}
}

0 comments on commit e5f5734

Please sign in to comment.