Skip to content

Commit

Permalink
Close mozilla-mobile#24498: Add test for history search telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketsroger authored and mergify[bot] committed Oct 6, 2022
1 parent 102acb3 commit e81da18
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ class HistoryFragment : LibraryPageFragment<History>(), UserInteractionHandler {
true
}
R.id.history_search -> {
GleanHistory.searchIconTapped.record(NoExtras())
historyInteractor.onSearch()
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,6 +88,7 @@ class DefaultHistoryInteractor(
}

override fun onSearch() {
GleanHistory.searchIconTapped.record(NoExtras())
historyController.handleSearch()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -67,11 +79,13 @@ class HistoryInteractorTest {

@Test
fun onSearch() {
assertNull(GleanHistory.searchIconTapped.testGetValue())
interactor.onSearch()

verifyAll {
controller.handleSearch()
}
assertNotNull(GleanHistory.searchIconTapped.testGetValue())
}

@Test
Expand Down

0 comments on commit e81da18

Please sign in to comment.