forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue mozilla-mobile#19809: Remove Grid layout info banner in tabs tray
- Loading branch information
1 parent
bf3f81d
commit 7dc712f
Showing
6 changed files
with
110 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
app/src/test/java/org/mozilla/fenix/tabstray/TabsTrayInfoBannerBindingTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.tabstray | ||
|
||
import android.view.View.GONE | ||
import android.view.View.VISIBLE | ||
import android.view.ViewGroup | ||
import androidx.coordinatorlayout.widget.CoordinatorLayout | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.TestCoroutineDispatcher | ||
import mozilla.components.browser.state.action.TabListAction | ||
import mozilla.components.browser.state.state.createTab | ||
import mozilla.components.browser.state.store.BrowserStore | ||
import mozilla.components.support.test.libstate.ext.waitUntilIdle | ||
import mozilla.components.support.test.robolectric.testContext | ||
import mozilla.components.support.test.rule.MainCoroutineRule | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mozilla.fenix.components.metrics.Event | ||
import org.mozilla.fenix.components.metrics.MetricController | ||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner | ||
import org.mozilla.fenix.tabstray.TabsTrayInfoBannerBinding.Companion.TAB_COUNT_SHOW_CFR | ||
import org.mozilla.fenix.utils.Settings | ||
|
||
@RunWith(FenixRobolectricTestRunner::class) | ||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class TabsTrayInfoBannerBindingTest { | ||
|
||
private lateinit var store: BrowserStore | ||
private lateinit var view: ViewGroup | ||
private lateinit var interactor: NavigationInteractor | ||
private lateinit var metrics: MetricController | ||
private lateinit var settings: Settings | ||
|
||
@get:Rule | ||
val coroutinesTestRule = MainCoroutineRule(TestCoroutineDispatcher()) | ||
|
||
@Before | ||
fun setUp() { | ||
store = BrowserStore() | ||
view = CoordinatorLayout(testContext) | ||
interactor = mockk(relaxed = true) | ||
metrics = mockk(relaxed = true) | ||
settings = Settings(testContext) | ||
} | ||
|
||
@Test | ||
fun `WHEN tab number reaches CFR count THEN banner is shown`() { | ||
view.visibility = GONE | ||
|
||
val binding = | ||
TabsTrayInfoBannerBinding( | ||
context = testContext, | ||
store = store, | ||
infoBannerView = view, | ||
settings = settings, | ||
navigationInteractor = interactor, | ||
metrics = metrics | ||
) | ||
|
||
binding.start() | ||
for (i in 1 until TAB_COUNT_SHOW_CFR) { | ||
store.dispatch(TabListAction.AddTabAction(createTab("https://mozilla.org"))) | ||
store.waitUntilIdle() | ||
|
||
assert(view.visibility == GONE) | ||
} | ||
|
||
store.dispatch(TabListAction.AddTabAction(createTab("https://mozilla.org"))) | ||
store.waitUntilIdle() | ||
assert(view.visibility == VISIBLE) | ||
} | ||
|
||
@Test | ||
fun `WHEN dismiss THEN auto close tabs info banner will not open tab settings`() { | ||
view.visibility = GONE | ||
settings.listTabView = false | ||
|
||
val binding = | ||
TabsTrayInfoBannerBinding( | ||
context = testContext, | ||
store = store, | ||
infoBannerView = view, | ||
settings = settings, | ||
navigationInteractor = interactor, | ||
metrics = metrics | ||
) | ||
|
||
binding.start() | ||
for (i in 1..TAB_COUNT_SHOW_CFR) { | ||
store.dispatch(TabListAction.AddTabAction(createTab("https://mozilla.org"))) | ||
store.waitUntilIdle() | ||
} | ||
|
||
assert(view.visibility == VISIBLE) | ||
binding.banner?.dismissAction?.invoke() | ||
|
||
verify(exactly = 0) { interactor.onTabSettingsClicked() } | ||
assert(!settings.shouldShowAutoCloseTabsBanner) | ||
verify(exactly = 0) { metrics.track(Event.TabsTrayCfrTapped) } | ||
verify(exactly = 1) { metrics.track(Event.TabsTrayCfrDismissed) } | ||
} | ||
} |
Oops, something went wrong.