From c4be544d63d6d20c492fc3a9ee969fb3bdafca6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Paczos?= Date: Thu, 27 Feb 2025 14:36:38 +0100 Subject: [PATCH] netp pixels --- .../settings/LegacyProSettingNetPViewModel.kt | 4 +++- .../settings/ProSettingNetPViewModel.kt | 4 +++- .../LegacyProSettingNetPViewModelTest.kt | 21 +++++++++++++++++-- .../settings/ProSettingNetPViewModelTest.kt | 21 +++++++++++++++++-- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModel.kt b/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModel.kt index 686f54ddc531..16cd17e9f139 100644 --- a/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModel.kt +++ b/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModel.kt @@ -26,6 +26,7 @@ import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope import com.duckduckgo.app.statistics.pixels.Pixel import com.duckduckgo.common.utils.DispatcherProvider +import com.duckduckgo.common.utils.extensions.toBinaryString import com.duckduckgo.mobile.android.R as CommonR import com.duckduckgo.navigation.api.GlobalActivityStarter.ActivityParams import com.duckduckgo.networkprotection.api.NetworkProtectionAccessState @@ -101,7 +102,8 @@ class LegacyProSettingNetPViewModel( val screen = networkProtectionAccessState.getScreenForCurrentState() screen?.let { command.send(OpenNetPScreen(screen)) - pixel.fire(NETP_SETTINGS_PRESSED) + val wasUsedBefore = networkProtectionState.isOnboarded() + pixel.fire(NETP_SETTINGS_PRESSED, parameters = mapOf("was_used_before" to wasUsedBefore.toBinaryString())) } ?: logcat { "Get screen for current NetP state is null" } } } diff --git a/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModel.kt b/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModel.kt index a5881ddeb1de..ca62b5abe29c 100644 --- a/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModel.kt +++ b/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModel.kt @@ -24,6 +24,7 @@ import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope import com.duckduckgo.app.statistics.pixels.Pixel import com.duckduckgo.common.utils.DispatcherProvider +import com.duckduckgo.common.utils.extensions.toBinaryString import com.duckduckgo.navigation.api.GlobalActivityStarter.ActivityParams import com.duckduckgo.networkprotection.api.NetworkProtectionAccessState import com.duckduckgo.networkprotection.api.NetworkProtectionState @@ -136,7 +137,8 @@ class ProSettingNetPViewModel( val screen = networkProtectionAccessState.getScreenForCurrentState() screen?.let { command.send(OpenNetPScreen(screen)) - pixel.fire(NETP_SETTINGS_PRESSED) + val wasUsedBefore = networkProtectionState.isOnboarded() + pixel.fire(NETP_SETTINGS_PRESSED, parameters = mapOf("was_used_before" to wasUsedBefore.toBinaryString())) } ?: logcat { "Get screen for current NetP state is null" } } } diff --git a/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModelTest.kt b/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModelTest.kt index 25866ec4dd9a..398b9541b120 100644 --- a/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModelTest.kt +++ b/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModelTest.kt @@ -65,15 +65,32 @@ class LegacyProSettingNetPViewModelTest { } @Test - fun whenNetPSettingClickedThenReturnScreenForCurrentState() = runTest { + fun `when NetP setting clicked and not onboarded then return screen for current state and send pixel`() = runTest { val testScreen = object : ActivityParams {} whenever(networkProtectionAccessState.getScreenForCurrentState()).thenReturn(testScreen) + whenever(networkProtectionState.isOnboarded()).thenReturn(false) + + proSettingNetPViewModel.commands().test { + proSettingNetPViewModel.onNetPSettingClicked() + + assertEquals(Command.OpenNetPScreen(testScreen), awaitItem()) + verify(pixel).fire(NETP_SETTINGS_PRESSED, parameters = mapOf("was_used_before" to "0")) + + cancelAndConsumeRemainingEvents() + } + } + + @Test + fun `when NetP setting clicked and onboarded then return screen for current state and send pixel`() = runTest { + val testScreen = object : ActivityParams {} + whenever(networkProtectionAccessState.getScreenForCurrentState()).thenReturn(testScreen) + whenever(networkProtectionState.isOnboarded()).thenReturn(true) proSettingNetPViewModel.commands().test { proSettingNetPViewModel.onNetPSettingClicked() assertEquals(Command.OpenNetPScreen(testScreen), awaitItem()) - verify(pixel).fire(NETP_SETTINGS_PRESSED) + verify(pixel).fire(NETP_SETTINGS_PRESSED, parameters = mapOf("was_used_before" to "1")) cancelAndConsumeRemainingEvents() } diff --git a/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModelTest.kt b/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModelTest.kt index 92e8b91c50bb..858ce6fcab79 100644 --- a/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModelTest.kt +++ b/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModelTest.kt @@ -71,15 +71,32 @@ class ProSettingNetPViewModelTest { } @Test - fun `when netp Setting clicked then netp screen is opened`() = runTest { + fun `when NetP setting clicked and not onboarded then return screen for current state and send pixel`() = runTest { val testScreen = object : ActivityParams {} whenever(networkProtectionAccessState.getScreenForCurrentState()).thenReturn(testScreen) + whenever(networkProtectionState.isOnboarded()).thenReturn(false) proSettingNetPViewModel.commands().test { proSettingNetPViewModel.onNetPSettingClicked() assertEquals(Command.OpenNetPScreen(testScreen), awaitItem()) - verify(pixel).fire(NETP_SETTINGS_PRESSED) + verify(pixel).fire(NETP_SETTINGS_PRESSED, parameters = mapOf("was_used_before" to "0")) + + cancelAndConsumeRemainingEvents() + } + } + + @Test + fun `when NetP setting clicked and onboarded then return screen for current state and send pixel`() = runTest { + val testScreen = object : ActivityParams {} + whenever(networkProtectionAccessState.getScreenForCurrentState()).thenReturn(testScreen) + whenever(networkProtectionState.isOnboarded()).thenReturn(true) + + proSettingNetPViewModel.commands().test { + proSettingNetPViewModel.onNetPSettingClicked() + + assertEquals(Command.OpenNetPScreen(testScreen), awaitItem()) + verify(pixel).fire(NETP_SETTINGS_PRESSED, parameters = mapOf("was_used_before" to "1")) cancelAndConsumeRemainingEvents() }