Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Update tests to reflect new metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Elise Richards committed Jul 29, 2021
1 parent f117ff7 commit a7d3540
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import mozilla.components.concept.storage.BookmarkNode
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.home.HomeFragmentDirections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.Assert.assertEquals
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.home.HomeFragmentDirections
import org.mozilla.fenix.home.recentbookmarks.controller.DefaultRecentBookmarksController
import org.mozilla.fenix.utils.Settings

@OptIn(ExperimentalCoroutinesApi::class)
class DefaultRecentBookmarksControllerTest {
Expand All @@ -43,12 +45,22 @@ class DefaultRecentBookmarksControllerTest {
private val activity: HomeActivity = mockk(relaxed = true)
private val navController: NavController = mockk(relaxUnitFun = true)
private val metrics: MetricController = mockk(relaxed = true)
private val settings: Settings = mockk(relaxed = true)

private lateinit var controller: DefaultRecentBookmarksController

private var recentBookmarksClickCounter = 0
private var showAllClickCounter = 0

@Before
fun setup() {
every { activity.openToBrowserAndLoad(any(), any(), any()) } just Runs
every { activity.components.core.metrics } returns metrics

every { activity.settings() } returns settings
every { activity.settings().recentBookmarkClickedCount } returns recentBookmarksClickCounter
every { activity.settings().recentBookmarkShowAllCount } returns showAllClickCounter

every { navController.currentDestination } returns mockk {
every { id } returns R.id.homeFragment
}
Expand All @@ -65,7 +77,7 @@ class DefaultRecentBookmarksControllerTest {
}

@Test
fun `WHEN a recently saved bookmark is clicked THEN the selected bookmark is opened`() {
fun openBookmarkOnClick() {
val bookmark = BookmarkNode(
type = BookmarkNodeType.ITEM,
guid = "guid#${Math.random() * 1000}",
Expand All @@ -77,26 +89,28 @@ class DefaultRecentBookmarksControllerTest {
children = null
)

assertEquals(0, recentBookmarksClickCounter)
controller.handleBookmarkClicked(bookmark)

verify {
recentBookmarksClickCounter = 1
activity.openToBrowserAndLoad(
searchTermOrURL = bookmark.url!!,
newTab = true,
from = BrowserDirection.FromHome
)
metrics.track(Event.RecentBookmarkClicked)
}
}

@Test
fun `WHEN show all recently saved bookmark is clicked THEN the bookmarks root is opened`() = runBlockingTest {
fun showAllButtonOpensRoot() = runBlockingTest {
showAllClickCounter = 0

controller.handleShowAllBookmarksClicked()

val directions = HomeFragmentDirections.actionGlobalBookmarkFragment(BookmarkRoot.Mobile.id)

verify {
metrics.track(Event.RecentBookmarkShowAll)
showAllClickCounter = 1
navController.navigate(directions, any<NavOptions>())
}
}
Expand Down

0 comments on commit a7d3540

Please sign in to comment.