Skip to content

Commit

Permalink
fix units tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swabbass committed Nov 9, 2021
1 parent 131d6ba commit b2a28cb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.aurelhubert.ahbottomnavigation.AHTextView
import com.reactnativenavigation.utils.ReactTypefaceUtils

open class TypefaceLoader(private val context: Context) {
val defaultTypeFace: Typeface by lazy {
open val defaultTypeFace: Typeface by lazy {
AHTextView(context).typeface ?: Typeface.DEFAULT
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ class TypefaceLoaderMock() : TypefaceLoader(mock()) {

constructor(mockTypefaces: Map<String, Typeface>?) : this() {
this.mockTypefaces = mockTypefaces

}

override val defaultTypeFace: Typeface
get() = Typeface.DEFAULT

override fun getTypeFace(fontFamilyName: String?, fontStyle: String?, fontWeight: String?, defaultTypeFace: Typeface?): Typeface? {
return mockTypefaces?.getOrDefault(fontFamilyName, defaultTypeFace) ?: defaultTypeFace
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,11 @@ class TopBarControllerTest : BaseTest() {
verify(removedControllers[textButton1.id]!!, never()).destroy()
verify(removedControllers[textButton2.id]!!, never()).destroy()

verify(rightButtonControllers[textButton1.id]!!, times(1)).addToMenu(any(), any())
verify(rightButtonControllers[textButton2.id]!!, times(1)).addToMenu(any(), any())
verify(rightButtonControllers[textButton1.id]!!, times(2)).addToMenu(any(), any())
verify(rightButtonControllers[textButton2.id]!!, times(2)).addToMenu(any(), any())
}
@Test
fun `mergeRightButtons - should rebuild menu when adding menu items`(){
fun `mergeRightButtons - should rebuild menu when adding menu items, existing should not be destroyed`(){
val controllers = spy(LinkedHashMap<String,ButtonController>())
uut.mergeRightButtonsOptions(controllers, listOf(textButton1)) {
createButtonController(it)
Expand All @@ -351,8 +351,8 @@ class TopBarControllerTest : BaseTest() {
createButtonController(it)
}
assertThat(uut.rightButtonCount).isEqualTo(2)
verify(controllers, times(1)).remove(any())
verify(controllers[textButton1.id]!!, times(1)).addToMenu(any(), any())
verify(controllers, never()).remove(any())
verify(controllers[textButton1.id]!!, times(2)).addToMenu(any(), any())
}
@Test
fun `mergeRightButtons - should modify changed buttons`(){
Expand All @@ -374,12 +374,13 @@ class TopBarControllerTest : BaseTest() {
verify(controllers[textButton1.id]!!, never()).destroy()
}

fun `mergeRightButtons - reorder of same menu items should rebuild menu`(){
@Test
fun `mergeRightButtons - reorder of same menu items should rebuild menu, not view recreation`(){
val controllers = spy(LinkedHashMap<String,ButtonController>())
uut.mergeRightButtonsOptions(controllers, listOf(textButton1, textButton2)) {
createButtonController(it)
}
assertThat(uut.rightButtonCount).isEqualTo(1)
assertThat(uut.rightButtonCount).isEqualTo(2)
verify(controllers[textButton1.id]!!, times(1)).addToMenu(any(), any())
verify(controllers[textButton2.id]!!, times(1)).addToMenu(any(), any())

Expand All @@ -390,8 +391,8 @@ class TopBarControllerTest : BaseTest() {
verify(controllers[textButton2.id]!!, never()).mergeButtonOptions(any(), any())
verify(controllers[textButton1.id]!!, times(2)).addToMenu(any(), any())
verify(controllers[textButton2.id]!!, times(2)).addToMenu(any(), any())
verify(controllers[textButton1.id]!!, times(1)).destroy()
verify(controllers[textButton2.id]!!, times(1)).destroy()
verify(controllers[textButton1.id]!!, never()).destroy()
verify(controllers[textButton2.id]!!, never()).destroy()
}

private fun createButtonController(it: ButtonOptions) =
Expand Down

0 comments on commit b2a28cb

Please sign in to comment.