This file contains hidden or 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
fun loadText(textId: Long) { | |
buildRequest<String>( | |
path = "text/endpoint", | |
params = { | |
kv("id", textId) | |
} | |
).execute { | |
copy(text = it) | |
} | |
} |
This file contains hidden or 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
@Test | |
fun loadText() = TextViewModel::loadText { | |
withParams(1) | |
expectRequests { | |
GET("text/endpoint?id=1") shouldReturn "server result" | |
} expectState { | |
copy(text = "server result") | |
} | |
} |
This file contains hidden or 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
@Test | |
fun setBold() = TextViewModel::setBold { | |
sets { ::options { ::bold } } | |
} |
This file contains hidden or 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
@Test | |
fun squared() = TestViewModel::squareNumber { | |
setsMapped(2 to 4, 5 to 25) { ::result } | |
} |
This file contains hidden or 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
@Test | |
fun initialization() = testInitialization( | |
expectRequests = { | |
GET("text/endpoint") | |
}, | |
expectState = { | |
copy(text = Loading()) | |
} | |
) |
This file contains hidden or 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
class HappoTestActivity : IntegrationTestActivity() { | |
override fun testCurrentScreen( | |
mockProvider: MockedFragmentProvider, | |
fragment: MvRxFragment, | |
resetView: (onViewReset: (MvRxFragment) -> Unit) -> Unit, | |
finishedTestingFragment: () -> Unit | |
) { | |
happoViewSnapshotBuilder.snap( | |
activity = this, | |
component = mockProvider.fragmentName, |
This file contains hidden or 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
class InteractionTestActivity : IntegrationTestActivity() { | |
override fun testCurrentScreen( | |
mockProvider: MockedFragmentProvider, | |
fragment: MvRxFragment, | |
resetView: (onViewReset: (MvRxFragment) -> Unit) -> Unit, | |
finishedTestingFragment: () -> Unit | |
) { | |
ActivityInteractionTester( | |
activity = this, | |
resetViewCallback = resetView, |
This file contains hidden or 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
@Test | |
fun screenshotBookingFragment() = runScreenshots("com.airbnb.booking.BookingFragment") | |
@Test | |
fun screenshotSearchFragment() = runScreenshots("com.airbnb.search.SearchFragment") | |
fun runScreenshots(fragmentName: String) { | |
val intent = IntegrationTestActivity.intent<HappoTestActivity>( | |
context = InstrumentationRegistry.getInstrumentation().targetContext, | |
fragmentName = fragmentName |
This file contains hidden or 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
fun waitForLoopers(loopers: List<Looper>) { | |
val idleDetectors = loopers.map { HandlerIdleDetector(Handler(it)) } | |
while (idleDetectors.any { !it.isIdle }) { | |
} | |
} | |
class HandlerIdleDetector(val handler: Handler) { | |
var isIdle = false | |
init { |
This file contains hidden or 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
val testContextMessage = "Error while testing 'Default State' mock for BookingFragment -> Clicking 'book_button' view on thread 'AsyncTask #1'" | |
throw IllegalStateException(testContextMessage, originalException) |