diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt index 32c7efe6e7ea..9a1c8c57fc10 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt @@ -66,13 +66,18 @@ class AllTimeStatsUseCase Column(string.stats_visitors, domainModel.visitors.toFormattedString()) ) ) + val tooltip = if (domainModel.viewsBestDay.isNotEmpty()) { + statsDateFormatter.printDate(domainModel.viewsBestDay) + } else { + null + } items.add( QuickScanItem( Column(string.posts, domainModel.posts.toFormattedString()), Column( string.stats_insights_best_ever, domainModel.viewsBestDayTotal.toFormattedString(), - statsDateFormatter.printDate(domainModel.viewsBestDay) + tooltip ) ) ) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCaseTest.kt index 7b9848e1c084..aec2213d2044 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCaseTest.kt @@ -127,6 +127,32 @@ class AllTimeStatsUseCaseTest : BaseUnitTest() { } } + @Test + fun `best day is null when it's empty`() = test { + val forced = false + val refresh = true + val model = InsightsAllTimeModel(1L, null, 1, 0, 0, "", 0) + whenever(insightsStore.getAllTimeInsights(site)).thenReturn(model) + whenever( + insightsStore.fetchAllTimeInsights( + site, + forced + ) + ).thenReturn(OnStatsFetched(model)) + + val result = loadAllTimeInsights(refresh, forced) + + assertThat(result.state).isEqualTo(UseCaseState.SUCCESS) + assertThat(result.type).isEqualTo(InsightsTypes.ALL_TIME_STATS) + val items = result.data!! + assertEquals(items.size, 3) + assertTrue(items[0] is Title) + assertEquals((items[0] as Title).textResource, R.string.stats_insights_all_time_stats) + (items[2] as QuickScanItem).apply { + assertThat(this.rightColumn.tooltip).isNull() + } + } + private suspend fun loadAllTimeInsights(refresh: Boolean, forced: Boolean): UseCaseModel { var result: UseCaseModel? = null useCase.liveData.observeForever { result = it }