From e5d73f58d771aded2fb9c409f65aa1a291ea2426 Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Tue, 9 Apr 2019 14:35:42 +0200 Subject: [PATCH 1/2] Do not parse empty date in AllTimeStats --- .../insights/usecases/AllTimeStatsUseCase.kt | 7 ++++- .../usecases/AllTimeStatsUseCaseTest.kt | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) 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..f574315b0c63 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 } From 3519e84e30b1fa410671b7cf80347268104d3d41 Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Wed, 10 Apr 2019 15:21:40 +0200 Subject: [PATCH 2/2] Remove unnecessary space --- .../lists/sections/insights/usecases/AllTimeStatsUseCaseTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f574315b0c63..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 @@ -131,7 +131,7 @@ class AllTimeStatsUseCaseTest : BaseUnitTest() { 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) + val model = InsightsAllTimeModel(1L, null, 1, 0, 0, "", 0) whenever(insightsStore.getAllTimeInsights(site)).thenReturn(model) whenever( insightsStore.fetchAllTimeInsights(