-
Notifications
You must be signed in to change notification settings - Fork 727
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix binding diff with prop group (#347)
* Fix diff binding with groups * update tests * unit tests * update tests
- Loading branch information
Showing
75 changed files
with
717 additions
and
673 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
123 changes: 123 additions & 0 deletions
123
epoxy-integrationtest/src/test/java/com/airbnb/epoxy/BindDiffTest.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,123 @@ | ||
package com.airbnb.epoxy | ||
|
||
import android.view.View | ||
import com.airbnb.epoxy.integrationtest.BuildConfig | ||
import com.airbnb.epoxy.integrationtest.ViewWithAnnotationsForIntegrationTest | ||
import com.airbnb.epoxy.integrationtest.ViewWithAnnotationsForIntegrationTestModel_ | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.verify | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.annotation.Config | ||
|
||
/** Tests that a partial bind of model (from a diff) binds the correct props. This is particularly tricky with prop groups. */ | ||
@RunWith(RobolectricTestRunner::class) | ||
@Config(constants = BuildConfig::class, sdk = intArrayOf(21)) | ||
class BindDiffTest { | ||
|
||
private inline fun validateDiff( | ||
model1Props: ViewWithAnnotationsForIntegrationTestModel_.() -> Unit, | ||
model2Props: ViewWithAnnotationsForIntegrationTestModel_.() -> Unit, | ||
viewCallVerifications: ViewWithAnnotationsForIntegrationTest.() -> Unit | ||
) { | ||
val model1 = ViewWithAnnotationsForIntegrationTestModel_().id(1).apply(model1Props) | ||
val model2 = ViewWithAnnotationsForIntegrationTestModel_().id(1).apply(model2Props) | ||
|
||
val viewMock = mock(ViewWithAnnotationsForIntegrationTest::class.java) | ||
model2.bind(viewMock, model1) | ||
|
||
verify(viewMock).viewCallVerifications() | ||
} | ||
|
||
@Test | ||
fun singlePropChanged() { | ||
validateDiff( | ||
model1Props = { | ||
requiredText("hello") | ||
groupWithNoDefault("text") | ||
groupWithDefault("text") | ||
}, | ||
model2Props = { | ||
requiredText("hello2") | ||
groupWithNoDefault("text") | ||
groupWithDefault("text") | ||
}, | ||
viewCallVerifications = { | ||
setRequiredText("hello2") | ||
} | ||
) | ||
} | ||
|
||
@Test | ||
fun multiplePropsChanged() { | ||
validateDiff( | ||
model1Props = { | ||
requiredText("hello") | ||
groupWithNoDefault("text") | ||
}, | ||
model2Props = { | ||
requiredText("hello2") | ||
groupWithNoDefault("text2") | ||
}, | ||
viewCallVerifications = { | ||
setGroupWithNoDefault("text2") | ||
setRequiredText("hello2") | ||
} | ||
) | ||
} | ||
|
||
@Test | ||
fun propGroupChangedFromOneAttributeToAnother() { | ||
val clickListener = View.OnClickListener { v -> } | ||
validateDiff( | ||
model1Props = { | ||
requiredText("hello") | ||
groupWithNoDefault("text") | ||
}, | ||
model2Props = { | ||
requiredText("hello") | ||
groupWithNoDefault(clickListener) | ||
}, | ||
viewCallVerifications = { | ||
setGroupWithNoDefault(clickListener) | ||
} | ||
) | ||
} | ||
|
||
@Test | ||
fun propGroupChangedToDefault() { | ||
validateDiff( | ||
model1Props = { | ||
requiredText("hello") | ||
groupWithNoDefault("text") | ||
groupWithDefault("custom value") | ||
}, | ||
model2Props = { | ||
requiredText("hello") | ||
groupWithNoDefault("text") | ||
}, | ||
viewCallVerifications = { | ||
setGroupWithDefault(null as View.OnClickListener?) | ||
} | ||
) | ||
} | ||
|
||
@Test | ||
fun propGroupChangedFromDefault() { | ||
validateDiff( | ||
model1Props = { | ||
requiredText("hello") | ||
groupWithNoDefault("text") | ||
}, | ||
model2Props = { | ||
requiredText("hello") | ||
groupWithNoDefault("text") | ||
groupWithDefault("custom value") | ||
}, | ||
viewCallVerifications = { | ||
setGroupWithDefault("custom value") | ||
} | ||
) | ||
} | ||
} |
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
Oops, something went wrong.