Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
fix: adjust override title when navigate in screen (#1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusguardieirozup committed Oct 20, 2020
1 parent 0ee2166 commit ff2d230
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ internal class ToolbarManager {
val textAppearance = typedArray.getResourceId(
R.styleable.BeagleToolbarStyle_titleTextAppearance, 0
)
removePreviousToolbarTitle(toolbar)
if (typedArray.getBoolean(R.styleable.BeagleToolbarStyle_centerTitle, false)) {
removePreviousToolbarTitle(toolbar)
val titleTextView = generateCenterTitle(context, navigationBar, textAppearance, toolbar)
toolbar.addView(titleTextView)
centerTitle(toolbar, titleTextView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class ScreenComponentTest : BaseComponentTest() {
val navigationBar = NavigationBar("Stub")
mockkConstructor(ToolbarManager::class)
screenComponent = ScreenComponent(child = screenComponent, navigationBar = navigationBar)
every { anyConstructed<ToolbarManager>().configureToolbar(any(), any(), any(), any()) } just Runs

//WHEN
screenComponent.buildView(rootView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.graphics.drawable.Drawable
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.ActionBar
import androidx.appcompat.widget.Toolbar
import androidx.core.content.res.ResourcesCompat
Expand All @@ -42,6 +43,7 @@ import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.impl.annotations.RelaxedMockK
import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.slot
import io.mockk.spyk
Expand Down Expand Up @@ -170,6 +172,8 @@ class ToolbarManagerTest : BaseTest() {
fun configure_toolbar_style_when_toolbar_is_not_null() {
// Given
val title = RandomData.string()
val textView: TextView = mockk()
every { toolbar.findViewById<TextView>(any()) } returns textView
every { navigationBar.title } returns title
every { beagleSdk.designSystem } returns designSystemMock
every { designSystemMock.toolbarStyle(style) } returns styleInt
Expand All @@ -181,6 +185,7 @@ class ToolbarManagerTest : BaseTest() {
toolbarManager.configureToolbar(rootView, navigationBar, beagleFlexView, screenComponent)

// Then
verify(exactly = once()) { toolbar.removeView(textView) }
verify(atLeast = once()) { toolbar.navigationIcon = navigationIcon }
verify(atLeast = once()) { toolbar.title = title }
verify(atLeast = once()) { toolbar.setTitleTextAppearance(context, titleTextAppearance) }
Expand All @@ -199,6 +204,8 @@ class ToolbarManagerTest : BaseTest() {
every { context.supportActionBar } returns actionBar
every { context.getToolbar() } returns toolbar
every { navigationBar.showBackButton } returns false
every { toolbar.findViewById<TextView>(any()) } returns mockk()


// When
toolbarManager.configureToolbar(rootView, navigationBar, beagleFlexView, screenComponent)
Expand All @@ -220,6 +227,8 @@ class ToolbarManagerTest : BaseTest() {
every { navigationBar.navigationBarItems } returns navigationBarItems
val menuItem = spyk<MenuItem>()
every { menu.add(any(), any(), any(), any<String>()) } returns menuItem
every { toolbar.findViewById<TextView>(any()) } returns mockk()


// WHEN
toolbarManager.configureToolbar(rootView, navigationBar, beagleFlexView, screenComponent)
Expand All @@ -246,6 +255,8 @@ class ToolbarManagerTest : BaseTest() {
val menuItem = spyk<MenuItem>()
every { menu.add(any(), any(), any(), any<String>()) } returns menuItem
every { ResourcesCompat.getDrawable(any(), any(), any()) } returns icon
every { toolbar.findViewById<TextView>(any()) } returns mockk()


// WHEN
toolbarManager.configureToolbar(rootView, navigationBar, beagleFlexView, screenComponent)
Expand Down

0 comments on commit ff2d230

Please sign in to comment.