From 2ba577079f7d5b20cfa30ae11082260cc178f4da Mon Sep 17 00:00:00 2001 From: khaykov Date: Sat, 21 May 2022 21:27:28 -0500 Subject: [PATCH 1/8] Store prompt value in flux-c. --- .../bloggingreminders/BloggingRemindersModelMapper.kt | 6 ++++-- .../ui/bloggingreminders/BloggingRemindersUiModel.kt | 2 +- .../bloggingreminders/BloggingRemindersViewModel.kt | 11 ++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersModelMapper.kt b/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersModelMapper.kt index 8b579eda5ea8..58ccc35e2dfe 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersModelMapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersModelMapper.kt @@ -29,7 +29,8 @@ class BloggingRemindersModelMapper } }.toSet(), uiModel.hour, - uiModel.minute + uiModel.minute, + uiModel.isPromptIncluded ) } @@ -38,7 +39,8 @@ class BloggingRemindersModelMapper domainModel.siteId, domainModel.enabledDays.map { DayOfWeek.valueOf(it.name) }.toSet(), domainModel.hour, - domainModel.minute + domainModel.minute, + domainModel.isPromptIncluded ) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersUiModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersUiModel.kt index 3db0341e4f76..4c3bb47ed223 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersUiModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersUiModel.kt @@ -11,7 +11,7 @@ data class BloggingRemindersUiModel( val enabledDays: Set = setOf(), val hour: Int, val minute: Int, - val isPromptIncluded: Boolean = true // TODO: get a real value here when implemented + val isPromptIncluded: Boolean ) { fun getNotificationTime(): CharSequence = LocalTime.of(hour, minute).format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersViewModel.kt index 42b09bcd997e..d4cf21d159ba 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersViewModel.kt @@ -215,6 +215,7 @@ class BloggingRemindersViewModel @Inject constructor( outState.putStringArrayList(SELECTED_DAYS, ArrayList(model.enabledDays.map { it.name })) outState.putInt(SELECTED_HOUR, model.hour) outState.putInt(SELECTED_MINUTE, model.minute) + outState.putBoolean(IS_BLOGGING_PROMPT_INCLUDED, model.isPromptIncluded) } _isFirstTimeFlow.value?.let { outState.putBoolean(IS_FIRST_TIME_FLOW, it) @@ -230,7 +231,14 @@ class BloggingRemindersViewModel @Inject constructor( val enabledDays = state.getStringArrayList(SELECTED_DAYS)?.map { DayOfWeek.valueOf(it) }?.toSet() ?: setOf() val selectedHour = state.getInt(SELECTED_HOUR) val selectedMinute = state.getInt(SELECTED_MINUTE) - _bloggingRemindersModel.value = BloggingRemindersUiModel(siteId, enabledDays, selectedHour, selectedMinute) + val isPromptIncluded = state.getBoolean(IS_BLOGGING_PROMPT_INCLUDED) + _bloggingRemindersModel.value = BloggingRemindersUiModel( + siteId, + enabledDays, + selectedHour, + selectedMinute, + isPromptIncluded + ) } _isFirstTimeFlow.value = state.getBoolean(IS_FIRST_TIME_FLOW) } @@ -295,6 +303,7 @@ class BloggingRemindersViewModel @Inject constructor( private const val SELECTED_DAYS = "key_selected_days" private const val SELECTED_HOUR = "key_selected_hour" private const val SELECTED_MINUTE = "key_selected_minute" + private const val IS_BLOGGING_PROMPT_INCLUDED = "key_is_blogging_prompt_included" private const val IS_FIRST_TIME_FLOW = "is_first_time_flow" private const val SITE_ID = "key_site_id" } From 98979d69441765f9e4da6d56397f56fdc3eb5fc9 Mon Sep 17 00:00:00 2001 From: khaykov Date: Mon, 23 May 2022 14:51:06 +0300 Subject: [PATCH 2/8] Updated flux-c hash. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b1e420331870..7470c7f0d466 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ ext { coroutinesVersion = '1.5.2' androidxWorkVersion = "2.7.0" - fluxCVersion = 'trunk-c5a745e60ccb39fc8178a146d467c3221d931bb1' + fluxCVersion = '2418-525ef9f193152e8cb274035a3470fa9aa46d980d' appCompatVersion = '1.0.2' androidxCoreVersion = '1.3.2' From 49de3179657b49fdb1520fc4f900677bb2d2f744 Mon Sep 17 00:00:00 2001 From: khaykov Date: Mon, 23 May 2022 14:51:47 +0300 Subject: [PATCH 3/8] Use value from Blogging Reminder store when determining when to show prompt. --- .../workers/reminder/PromptReminderNotifier.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/workers/reminder/PromptReminderNotifier.kt b/WordPress/src/main/java/org/wordpress/android/workers/reminder/PromptReminderNotifier.kt index 5bdeb4391292..54105767f798 100644 --- a/WordPress/src/main/java/org/wordpress/android/workers/reminder/PromptReminderNotifier.kt +++ b/WordPress/src/main/java/org/wordpress/android/workers/reminder/PromptReminderNotifier.kt @@ -7,6 +7,7 @@ import androidx.core.app.NotificationCompat.PRIORITY_DEFAULT import kotlinx.coroutines.flow.firstOrNull import org.wordpress.android.R import org.wordpress.android.fluxc.store.AccountStore +import org.wordpress.android.fluxc.store.BloggingRemindersStore import org.wordpress.android.fluxc.store.SiteStore import org.wordpress.android.fluxc.store.bloggingprompts.BloggingPromptsStore import org.wordpress.android.push.NotificationPushIds.REMINDER_NOTIFICATION_ID @@ -26,11 +27,9 @@ class PromptReminderNotifier @Inject constructor( val accountStore: AccountStore, val reminderNotificationManager: ReminderNotificationManager, val bloggingPromptsFeatureConfig: BloggingPromptsFeatureConfig, - val bloggingPromptsStore: BloggingPromptsStore + val bloggingPromptsStore: BloggingPromptsStore, + private val bloggingRemindersStore: BloggingRemindersStore ) { - // TODO @RenanLukas replace with remote field in SiteModel after endpoint integration - var hasOptedInBloggingPromptsReminders = true - suspend fun notify(siteId: Int) { val notificationId = REMINDER_NOTIFICATION_ID + siteId val context = contextProvider.getContext() @@ -89,11 +88,17 @@ class PromptReminderNotifier @Inject constructor( // analyticsTracker.trackNotificationReceived() } - fun shouldNotify(siteId: Int): Boolean { + suspend fun shouldNotify(siteId: Int): Boolean { val hasAccessToken = accountStore.hasAccessToken() val isBloggingPromptsEnabled = bloggingPromptsFeatureConfig.isEnabled() val siteModel = siteStore.getSiteByLocalId(siteId) - val hasOptedInBloggingPromptsReminders = siteModel != null && hasOptedInBloggingPromptsReminders + + val isPromptOptedIn = bloggingRemindersStore.bloggingRemindersModel(siteId).firstOrNull()?.isPromptIncluded + ?: false + // TODO @klymyam check the value from the site model when we will start syncing the settings with remote + // val isPromptOptedIn = siteModel.isBloggingPromptsOptedIn + + val hasOptedInBloggingPromptsReminders = siteModel != null && isPromptOptedIn return hasAccessToken && isBloggingPromptsEnabled && hasOptedInBloggingPromptsReminders } From cbe94250bb840a1ef31e971618bcc3ea37fcea65 Mon Sep 17 00:00:00 2001 From: khaykov Date: Mon, 23 May 2022 14:51:59 +0300 Subject: [PATCH 4/8] Updated tests. --- .../BloggingRemindersAnalyticsTrackerTest.kt | 2 +- .../BloggingRemindersViewModelTest.kt | 5 +- .../DaySelectionBuilderTest.kt | 28 +++++------ .../bloggingreminders/EpilogueBuilderTest.kt | 8 ++-- .../reminder/PromptReminderNotifierTest.kt | 47 +++++++++++++------ 5 files changed, 55 insertions(+), 35 deletions(-) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersAnalyticsTrackerTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersAnalyticsTrackerTest.kt index 036fecc9d650..90acac0caf7e 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersAnalyticsTrackerTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersAnalyticsTrackerTest.kt @@ -135,7 +135,7 @@ class BloggingRemindersAnalyticsTrackerTest { @Test fun `trackRemindersScheduled tracks correct event and properties`() { bloggingRemindersUiModel = BloggingRemindersUiModel( - 1, setOf(MONDAY, THURSDAY, FRIDAY), 14, 30) + 1, setOf(MONDAY, THURSDAY, FRIDAY), 14, 30, true) bloggingRemindersAnalyticsTracker.trackRemindersScheduled( bloggingRemindersUiModel.enabledDays.size, bloggingRemindersUiModel.getNotificationTime24hour()) verify(analyticsTracker).track(eq(BLOGGING_REMINDERS_SCHEDULED), checkMap { diff --git a/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersViewModelTest.kt index 2b1847e20a6d..3f42a81fd74d 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersViewModelTest.kt @@ -171,7 +171,8 @@ class BloggingRemindersViewModelTest : BaseUnitTest() { siteId, setOf(DayOfWeek.MONDAY, DayOfWeek.SUNDAY), hour, - minute + minute, + false ) ) ).thenReturn(dayLabel) @@ -423,7 +424,7 @@ class BloggingRemindersViewModelTest : BaseUnitTest() { private fun initEmptyStore(): BloggingRemindersUiModel { val emptyModel = BloggingRemindersModel(siteId) whenever(bloggingRemindersStore.bloggingRemindersModel(siteId)).thenReturn(flowOf(emptyModel)) - return BloggingRemindersUiModel(siteId, hour = hour, minute = minute) + return BloggingRemindersUiModel(siteId, hour = hour, minute = minute, isPromptIncluded = false) } private fun assertPrologue() { diff --git a/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/DaySelectionBuilderTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/DaySelectionBuilderTest.kt index b55662a18809..facc6fbf7488 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/DaySelectionBuilderTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/DaySelectionBuilderTest.kt @@ -74,7 +74,7 @@ class DaySelectionBuilderTest { @Test fun `builds UI model with no selected days`() { - val bloggingRemindersModel = BloggingRemindersUiModel(1, hour = hour, minute = minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, hour = hour, minute = minute, isPromptIncluded = false) val dayLabel = UiStringText("Not set") whenever(dayLabelUtils.buildNTimesLabel(bloggingRemindersModel)) .thenReturn(dayLabel) @@ -92,7 +92,7 @@ class DaySelectionBuilderTest { @Test fun `builds UI model with selected days`() { - val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute, isPromptIncluded = false) val dayLabel = UiStringText("Twice a week") whenever(dayLabelUtils.buildNTimesLabel(bloggingRemindersModel)) .thenReturn(dayLabel) @@ -110,7 +110,7 @@ class DaySelectionBuilderTest { @Test fun `click on a day select day`() { - val bloggingRemindersModel = BloggingRemindersUiModel(1, hour = hour, minute = minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, hour = hour, minute = minute, isPromptIncluded = false) whenever(dayLabelUtils.buildNTimesLabel(bloggingRemindersModel)).thenReturn(UiStringText("Once a week")) val uiModel = daySelectionBuilder.buildSelection( @@ -129,7 +129,7 @@ class DaySelectionBuilderTest { @Test fun `primary button disabled when model is empty and is first time flow`() { - val bloggingRemindersModel = BloggingRemindersUiModel(1, hour = hour, minute = minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, hour = hour, minute = minute, isPromptIncluded = false) val primaryButton = daySelectionBuilder.buildPrimaryButton(bloggingRemindersModel, true, onConfirm) @@ -144,7 +144,7 @@ class DaySelectionBuilderTest { @Test fun `primary button enabled when model is not empty and is first time flow`() { - val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute, isPromptIncluded = false) val primaryButton = daySelectionBuilder.buildPrimaryButton(bloggingRemindersModel, true, onConfirm) @@ -159,7 +159,7 @@ class DaySelectionBuilderTest { @Test fun `primary button enabled when model is empty and is not first time flow`() { - val bloggingRemindersModel = BloggingRemindersUiModel(1, hour = hour, minute = minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, hour = hour, minute = minute, isPromptIncluded = false) val primaryButton = daySelectionBuilder.buildPrimaryButton(bloggingRemindersModel, false, onConfirm) @@ -176,7 +176,7 @@ class DaySelectionBuilderTest { fun `primary button shows a different label when blogging prompt FF is on`() { whenever(bloggingPromptsFeatureConfig.isEnabled()).thenReturn(true) - val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute, isPromptIncluded = false) val primaryButton = daySelectionBuilder.buildPrimaryButton(bloggingRemindersModel, true, onConfirm) @@ -191,7 +191,7 @@ class DaySelectionBuilderTest { @Test fun `click on primary button confirm selection`() { - val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute, false) val primaryButton = daySelectionBuilder.buildPrimaryButton(bloggingRemindersModel, false, onConfirm) @@ -204,7 +204,7 @@ class DaySelectionBuilderTest { fun `include prompt switch is visible when days are selected`() { whenever(bloggingPromptsFeatureConfig.isEnabled()).thenReturn(true) - val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute, false) val dayLabel = UiStringText("Twice a week") whenever(dayLabelUtils.buildNTimesLabel(bloggingRemindersModel)) .thenReturn(dayLabel) @@ -223,7 +223,7 @@ class DaySelectionBuilderTest { @Test fun `include prompt switch is not visible when days are not selected`() { - val bloggingRemindersModel = BloggingRemindersUiModel(1, hour = hour, minute = minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, hour = hour, minute = minute, isPromptIncluded = false) val dayLabel = UiStringText("Not set") whenever(dayLabelUtils.buildNTimesLabel(bloggingRemindersModel)) .thenReturn(dayLabel) @@ -244,7 +244,7 @@ class DaySelectionBuilderTest { fun `single include prompt switch is visible when FF is on`() { whenever(bloggingPromptsFeatureConfig.isEnabled()).thenReturn(true) - val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute, false) val dayLabel = UiStringText("Twice a week") whenever(dayLabelUtils.buildNTimesLabel(bloggingRemindersModel)) .thenReturn(dayLabel) @@ -265,7 +265,7 @@ class DaySelectionBuilderTest { fun `include prompt switch is not visible when FF is off`() { whenever(bloggingPromptsFeatureConfig.isEnabled()).thenReturn(false) - val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute, false) val dayLabel = UiStringText("Twice a week") whenever(dayLabelUtils.buildNTimesLabel(bloggingRemindersModel)) .thenReturn(dayLabel) @@ -286,7 +286,7 @@ class DaySelectionBuilderTest { fun `click on a prompt switch toggles the prompt state`() { whenever(bloggingPromptsFeatureConfig.isEnabled()).thenReturn(true) - val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute,false) val dayLabel = UiStringText("Twice a week") whenever(dayLabelUtils.buildNTimesLabel(bloggingRemindersModel)) .thenReturn(dayLabel) @@ -309,7 +309,7 @@ class DaySelectionBuilderTest { fun `click on a blogging prompt help button shows blogging prompt dialog`() { whenever(bloggingPromptsFeatureConfig.isEnabled()).thenReturn(true) - val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute, false) val dayLabel = UiStringText("Twice a week") whenever(dayLabelUtils.buildNTimesLabel(bloggingRemindersModel)) .thenReturn(dayLabel) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/EpilogueBuilderTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/EpilogueBuilderTest.kt index 7d520bc70b58..461fc2669853 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/EpilogueBuilderTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/EpilogueBuilderTest.kt @@ -46,7 +46,7 @@ class EpilogueBuilderTest { @Test fun `builds UI model with no selected days`() { - val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(), hour, minute) + val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(), hour, minute, false) val uiModel = epilogueBuilder.buildUiItems(bloggingRemindersModel) assertModelWithNoSelection(uiModel) @@ -58,7 +58,8 @@ class EpilogueBuilderTest { 1, setOf(DayOfWeek.WEDNESDAY, DayOfWeek.SUNDAY), hour, - minute + minute, + false ) val dayLabel = "twice" whenever(dayLabelUtils.buildLowercaseNTimesLabel(bloggingRemindersModel)) @@ -88,7 +89,8 @@ class EpilogueBuilderTest { 1, DayOfWeek.values().toSet(), hour, - minute + minute, + false ) val message = "You'll get reminders to blog everyday at 10:00 am." whenever( diff --git a/WordPress/src/test/java/org/wordpress/android/workers/reminder/PromptReminderNotifierTest.kt b/WordPress/src/test/java/org/wordpress/android/workers/reminder/PromptReminderNotifierTest.kt index c532b3254105..a33b1fc6e9a4 100644 --- a/WordPress/src/test/java/org/wordpress/android/workers/reminder/PromptReminderNotifierTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/workers/reminder/PromptReminderNotifierTest.kt @@ -1,12 +1,18 @@ package org.wordpress.android.workers.reminder +import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever +import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.runBlocking import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue +import org.junit.Before import org.junit.Test +import org.wordpress.android.fluxc.model.BloggingRemindersModel import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.store.AccountStore +import org.wordpress.android.fluxc.store.BloggingRemindersStore import org.wordpress.android.fluxc.store.SiteStore import org.wordpress.android.fluxc.store.bloggingprompts.BloggingPromptsStore import org.wordpress.android.util.config.BloggingPromptsFeatureConfig @@ -21,6 +27,8 @@ class PromptReminderNotifierTest { private val accountStore: AccountStore = mock() private val reminderNotificationManager: ReminderNotificationManager = mock() private val bloggingPromptsFeatureConfig: BloggingPromptsFeatureConfig = mock() + private val bloggingRemindersStore: BloggingRemindersStore = mock() + private val bloggingReminder: BloggingRemindersModel = mock() private val classToTest = PromptReminderNotifier( contextProvider = contextProvider, @@ -29,45 +37,54 @@ class PromptReminderNotifierTest { accountStore = accountStore, reminderNotificationManager = reminderNotificationManager, bloggingPromptsFeatureConfig = bloggingPromptsFeatureConfig, - bloggingPromptsStore = bloggingPromptsStore + bloggingPromptsStore = bloggingPromptsStore, + bloggingRemindersStore ) + @Before + fun setUp() { + whenever(bloggingRemindersStore.bloggingRemindersModel(any())).thenReturn(flowOf(bloggingReminder)) + } + @Test - fun `Should NOT notify if hasAccessToken returns FALSE`() { + fun `Should NOT notify if hasAccessToken returns FALSE`() = runBlocking { whenever(accountStore.hasAccessToken()).thenReturn(false) assertFalse(classToTest.shouldNotify(123)) } @Test - fun `Should NOT notify if blogging prompts notification flag isEnabled returns FALSE`() { + fun `Should NOT notify if blogging prompts notification flag isEnabled returns FALSE`() = runBlocking { whenever(bloggingPromptsFeatureConfig.isEnabled()).thenReturn(false) assertFalse(classToTest.shouldNotify(123)) } @Test - fun `Should NOT notify if getSiteByLocalId returns NULL`() { + fun `Should NOT notify if getSiteByLocalId returns NULL`() = runBlocking { val siteId = 123 whenever(siteStore.getSiteByLocalId(siteId)).thenReturn(null) assertFalse(classToTest.shouldNotify(siteId)) } @Test - fun `Should NOT notify if SiteModel hasOptedInBloggingPromptsReminders returns FALSE`() { + fun `Should NOT notify if SiteModel hasOptedInBloggingPromptsReminders returns FALSE`() = runBlocking { val siteId = 123 val siteModel: SiteModel = mock() - classToTest.hasOptedInBloggingPromptsReminders = false + + whenever(bloggingReminder.isPromptIncluded).thenReturn(false) whenever(siteStore.getSiteByLocalId(siteId)).thenReturn(siteModel) assertFalse(classToTest.shouldNotify(123)) } @Test - fun `Should notify if has access token, flag is enabled and has opted in for blogging prompts reminders`() { - val siteId = 123 - val siteModel: SiteModel = mock() - whenever(accountStore.hasAccessToken()).thenReturn(true) - whenever(bloggingPromptsFeatureConfig.isEnabled()).thenReturn(true) - classToTest.hasOptedInBloggingPromptsReminders = true - whenever(siteStore.getSiteByLocalId(siteId)).thenReturn(siteModel) - assertTrue(classToTest.shouldNotify(siteId)) - } + fun `Should notify if has access token, flag is enabled and has opted in for blogging prompts reminders`() = + runBlocking { + val siteId = 123 + val siteModel: SiteModel = mock() + + whenever(bloggingReminder.isPromptIncluded).thenReturn(true) + whenever(accountStore.hasAccessToken()).thenReturn(true) + whenever(bloggingPromptsFeatureConfig.isEnabled()).thenReturn(true) + whenever(siteStore.getSiteByLocalId(siteId)).thenReturn(siteModel) + assertTrue(classToTest.shouldNotify(siteId)) + } } From d0b53d1395f58eb18c5f161b3ab74a1d89703787 Mon Sep 17 00:00:00 2001 From: khaykov Date: Mon, 23 May 2022 15:49:36 +0300 Subject: [PATCH 5/8] Fixed ktlint and DB migration. --- .../DaySelectionBuilderTest.kt | 26 ++++++++++++++++--- build.gradle | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/DaySelectionBuilderTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/DaySelectionBuilderTest.kt index facc6fbf7488..64e926153ead 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/DaySelectionBuilderTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/bloggingreminders/DaySelectionBuilderTest.kt @@ -92,7 +92,13 @@ class DaySelectionBuilderTest { @Test fun `builds UI model with selected days`() { - val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute, isPromptIncluded = false) + val bloggingRemindersModel = BloggingRemindersUiModel( + 1, + setOf(WEDNESDAY, SUNDAY), + hour, + minute, + isPromptIncluded = false + ) val dayLabel = UiStringText("Twice a week") whenever(dayLabelUtils.buildNTimesLabel(bloggingRemindersModel)) .thenReturn(dayLabel) @@ -144,7 +150,13 @@ class DaySelectionBuilderTest { @Test fun `primary button enabled when model is not empty and is first time flow`() { - val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute, isPromptIncluded = false) + val bloggingRemindersModel = BloggingRemindersUiModel( + 1, + setOf(WEDNESDAY, SUNDAY), + hour, + minute, + isPromptIncluded = false + ) val primaryButton = daySelectionBuilder.buildPrimaryButton(bloggingRemindersModel, true, onConfirm) @@ -176,7 +188,13 @@ class DaySelectionBuilderTest { fun `primary button shows a different label when blogging prompt FF is on`() { whenever(bloggingPromptsFeatureConfig.isEnabled()).thenReturn(true) - val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute, isPromptIncluded = false) + val bloggingRemindersModel = BloggingRemindersUiModel( + 1, + setOf(WEDNESDAY, SUNDAY), + hour, + minute, + isPromptIncluded = false + ) val primaryButton = daySelectionBuilder.buildPrimaryButton(bloggingRemindersModel, true, onConfirm) @@ -286,7 +304,7 @@ class DaySelectionBuilderTest { fun `click on a prompt switch toggles the prompt state`() { whenever(bloggingPromptsFeatureConfig.isEnabled()).thenReturn(true) - val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute,false) + val bloggingRemindersModel = BloggingRemindersUiModel(1, setOf(WEDNESDAY, SUNDAY), hour, minute, false) val dayLabel = UiStringText("Twice a week") whenever(dayLabelUtils.buildNTimesLabel(bloggingRemindersModel)) .thenReturn(dayLabel) diff --git a/build.gradle b/build.gradle index 7470c7f0d466..0bdd9cc43646 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ ext { coroutinesVersion = '1.5.2' androidxWorkVersion = "2.7.0" - fluxCVersion = '2418-525ef9f193152e8cb274035a3470fa9aa46d980d' + fluxCVersion = '2418-4391d5fde49b6fc7d770309af69ad9142c100cdf' appCompatVersion = '1.0.2' androidxCoreVersion = '1.3.2' From 4ecc291bebee830aaa10ee53f62f39541d590a2a Mon Sep 17 00:00:00 2001 From: khaykov Date: Mon, 23 May 2022 16:16:26 +0300 Subject: [PATCH 6/8] Updated flux-c hash. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0bdd9cc43646..ef5924233f70 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ ext { coroutinesVersion = '1.5.2' androidxWorkVersion = "2.7.0" - fluxCVersion = '2418-4391d5fde49b6fc7d770309af69ad9142c100cdf' + fluxCVersion = '2418-6b6f904fda4fbd6f831dff55de3d42e601806a63' appCompatVersion = '1.0.2' androidxCoreVersion = '1.3.2' From cc23d597a7b53de60afe977bd33b0680cdd7fed3 Mon Sep 17 00:00:00 2001 From: khaykov Date: Mon, 23 May 2022 17:15:36 +0300 Subject: [PATCH 7/8] Updated flux-c hash. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index ef5924233f70..eab258e84572 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ ext { coroutinesVersion = '1.5.2' androidxWorkVersion = "2.7.0" - fluxCVersion = '2418-6b6f904fda4fbd6f831dff55de3d42e601806a63' + fluxCVersion = '2418-aff87e91f6da67318b4c2c0dc66bfc5a358aecef' appCompatVersion = '1.0.2' androidxCoreVersion = '1.3.2' From 5d6810039d846f2ffde414bc382e584c4bac1f0f Mon Sep 17 00:00:00 2001 From: khaykov Date: Wed, 25 May 2022 18:53:50 +0300 Subject: [PATCH 8/8] Updated flux-c hash. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c382abd2bb96..fcae46a1ab10 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ ext { coroutinesVersion = '1.5.2' androidxWorkVersion = "2.7.0" - fluxCVersion = '2418-5ce8128c0a532ab65bfd235c7b56689073192415' + fluxCVersion = 'trunk-f72e5d145dcfcf6e6875863e874496c1866676e7' appCompatVersion = '1.0.2' androidxCoreVersion = '1.3.2'