Skip to content

Commit

Permalink
Execute executePendingBindings to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Serchinastico committed Jan 30, 2019
1 parent 07a1e0b commit a4308ad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,44 @@ class SuperHeroViewHolderTest : ScreenshotTest {
@Test
fun showsAnySuperHero() {
val superHero = givenASuperHero()
val (holder, binding) = givenASuperHeroViewHolder()
val holder = givenASuperHeroViewHolder()

renderViewHolder(superHero, holder, binding)
holder.render(superHero)

compareScreenshot(holder, R.dimen.super_hero_row_height)
}

@Test
fun showsSuperHeroesWithLongNames() {
val superHero = givenASuperHeroWithALongName()
val (holder, binding) = givenASuperHeroViewHolder()
val holder = givenASuperHeroViewHolder()

renderViewHolder(superHero, holder, binding)
holder.render(superHero)

compareScreenshot(holder, R.dimen.super_hero_row_height)
}

@Test
fun showsSuperHeroesWithLongDescriptions() {
val superHero = givenASuperHeroWithALongDescription()
val (holder, binding) = givenASuperHeroViewHolder()
val holder = givenASuperHeroViewHolder()

renderViewHolder(superHero, holder, binding)
holder.render(superHero)

compareScreenshot(holder, R.dimen.super_hero_row_height)
}

@Test
fun showsAvengersBadge() {
val superHero = givenASuperHero(isAvenger = true)
val (holder, binding) = givenASuperHeroViewHolder()
val holder = givenASuperHeroViewHolder()

renderViewHolder(superHero, holder, binding)
holder.render(superHero)

compareScreenshot(holder, R.dimen.super_hero_row_height)
}

private fun renderViewHolder(
superHero: SuperHero,
holder: SuperHeroViewHolder,
binding: SuperHeroRowBinding
) {
holder.render(superHero)
binding.executePendingBindings()
}

private fun givenASuperHeroViewHolder(): Pair<SuperHeroViewHolder, SuperHeroRowBinding> =
private fun givenASuperHeroViewHolder(): SuperHeroViewHolder =
runOnUi {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val inflater = LayoutInflater.from(context)
Expand All @@ -71,7 +62,7 @@ class SuperHeroViewHolderTest : ScreenshotTest {
SuperHeroViewHolder(
binding,
mock<SuperHeroesPresenter>(SuperHeroesPresenter::class.java)
) to binding
)
}

private fun givenASuperHeroWithALongDescription(): SuperHero {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class SuperHeroViewHolder(
fun render(superHero: SuperHero) {
binding.superHero = superHero
binding.listener = listener
binding.executePendingBindings()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.karumi.jetpack.superheroes.R
import com.karumi.jetpack.superheroes.databinding.SuperHeroRowBinding
import com.karumi.jetpack.superheroes.domain.model.SuperHero
import com.karumi.jetpack.superheroes.ui.presenter.SuperHeroesListener
import com.karumi.jetpack.superheroes.ui.presenter.SuperHeroesPresenter

internal class SuperHeroesAdapter(
private val listener: SuperHeroesListener
Expand Down

0 comments on commit a4308ad

Please sign in to comment.