From c5efabc51efc9830a6f19e884c3900baf5e584a2 Mon Sep 17 00:00:00 2001 From: Roger Yang Date: Wed, 5 Oct 2022 18:35:08 -0400 Subject: [PATCH] [fenix] Close https://github.com/mozilla-mobile/fenix/issues/24498: Add test for history search telemetry --- .../fenix/library/history/HistoryFragment.kt | 1 - .../fenix/library/history/HistoryInteractor.kt | 3 +++ .../fenix/library/history/HistoryInteractorTest.kt | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt index d23d5b54e5..e82761c38a 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt @@ -287,7 +287,6 @@ class HistoryFragment : LibraryPageFragment(), UserInteractionHandler { true } R.id.history_search -> { - GleanHistory.searchIconTapped.record(NoExtras()) historyInteractor.onSearch() true } diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryInteractor.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryInteractor.kt index 6aef870127..d9395a010b 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryInteractor.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryInteractor.kt @@ -4,7 +4,9 @@ package org.mozilla.fenix.library.history +import mozilla.components.service.glean.private.NoExtras import org.mozilla.fenix.selection.SelectionInteractor +import org.mozilla.fenix.GleanMetrics.History as GleanHistory /** * Interface for the HistoryInteractor. This interface is implemented by objects that want @@ -86,6 +88,7 @@ class DefaultHistoryInteractor( } override fun onSearch() { + GleanHistory.searchIconTapped.record(NoExtras()) historyController.handleSearch() } diff --git a/app/src/test/java/org/mozilla/fenix/library/history/HistoryInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/library/history/HistoryInteractorTest.kt index 83b209703f..9ee32319f9 100644 --- a/app/src/test/java/org/mozilla/fenix/library/history/HistoryInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/history/HistoryInteractorTest.kt @@ -7,14 +7,26 @@ package org.mozilla.fenix.library.history import io.mockk.every import io.mockk.mockk import io.mockk.verifyAll +import mozilla.components.service.glean.testing.GleanTestRule +import mozilla.components.support.test.robolectric.testContext +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertNull import org.junit.Assert.assertTrue +import org.junit.Rule import org.junit.Test +import org.junit.runner.RunWith +import org.mozilla.fenix.GleanMetrics.History as GleanHistory +import org.mozilla.fenix.helpers.FenixRobolectricTestRunner +@RunWith(FenixRobolectricTestRunner::class) // For GleanTestRule class HistoryInteractorTest { private val historyItem = History.Regular(0, "title", "url", 0.toLong(), HistoryItemTimeGroup.timeGroupForTimestamp(0)) val controller: HistoryController = mockk(relaxed = true) val interactor = DefaultHistoryInteractor(controller) + @get:Rule + val gleanTestRule = GleanTestRule(testContext) + @Test fun onOpen() { interactor.open(historyItem) @@ -67,11 +79,13 @@ class HistoryInteractorTest { @Test fun onSearch() { + assertNull(GleanHistory.searchIconTapped.testGetValue()) interactor.onSearch() verifyAll { controller.handleSearch() } + assertNotNull(GleanHistory.searchIconTapped.testGetValue()) } @Test