Issue #18535: Set the span count for grid view
parent
2c6395cafe
commit
a443509c8b
@ -0,0 +1,19 @@
|
||||
/* 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.ext
|
||||
|
||||
import android.content.Context
|
||||
|
||||
private const val MIN_COLUMN_WIDTH_DP = 180
|
||||
|
||||
/**
|
||||
* Returns the number of grid columns we can fit on the screen in the tabs tray.
|
||||
*/
|
||||
internal val Context.numberOfGridColumns: Int
|
||||
get() {
|
||||
val displayMetrics = resources.displayMetrics
|
||||
val screenWidthDp = displayMetrics.widthPixels / displayMetrics.density
|
||||
return (screenWidthDp / MIN_COLUMN_WIDTH_DP).toInt()
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/* 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.browser
|
||||
|
||||
import android.content.Context
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkStatic
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.tabstray.TrayPagerAdapter
|
||||
import org.mozilla.fenix.tabstray.ext.numberOfGridColumns
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
|
||||
class DefaultBrowserTrayInteractorTest {
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
mockkStatic("org.mozilla.fenix.tabstray.ext.ContextKt")
|
||||
}
|
||||
|
||||
@After
|
||||
fun shutdown() {
|
||||
unmockkStatic("org.mozilla.fenix.tabstray.ext.ContextKt")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN pager position is synced tabs THEN return a list layout manager`() {
|
||||
val interactor = DefaultBrowserTrayInteractor(mockk(), mockk(), mockk(), mockk())
|
||||
|
||||
val result = interactor.getLayoutManagerForPosition(
|
||||
mockk(),
|
||||
TrayPagerAdapter.POSITION_SYNCED_TABS
|
||||
)
|
||||
|
||||
assertEquals(1, (result as GridLayoutManager).spanCount)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN setting is grid view THEN return grid layout manager`() {
|
||||
val context = mockk<Context>()
|
||||
val settings = mockk<Settings>()
|
||||
val interactor = DefaultBrowserTrayInteractor(mockk(), mockk(), mockk(), settings)
|
||||
|
||||
every { context.numberOfGridColumns }.answers { 4 }
|
||||
every { settings.gridTabView }.answers { true }
|
||||
|
||||
val result = interactor.getLayoutManagerForPosition(
|
||||
context,
|
||||
TrayPagerAdapter.POSITION_NORMAL_TABS
|
||||
)
|
||||
|
||||
assertEquals(4, (result as GridLayoutManager).spanCount)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN setting is list view THEN return list layout manager`() {
|
||||
val context = mockk<Context>()
|
||||
val settings = mockk<Settings>()
|
||||
val interactor = DefaultBrowserTrayInteractor(mockk(), mockk(), mockk(), settings)
|
||||
|
||||
every { context.numberOfGridColumns }.answers { 4 }
|
||||
every { settings.gridTabView }.answers { false }
|
||||
|
||||
val result = interactor.getLayoutManagerForPosition(
|
||||
context,
|
||||
TrayPagerAdapter.POSITION_NORMAL_TABS
|
||||
)
|
||||
|
||||
// Should NOT be 4.
|
||||
assertEquals(1, (result as GridLayoutManager).spanCount)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue