Skip to content

Commit

Permalink
netp pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasPaczos committed Feb 27, 2025
1 parent 55278d4 commit c4be544
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit c4be544

Please sign in to comment.