Last active
October 4, 2020 09:16
-
-
Save adam-hurwitz/e10f35dfe0a3ccd4bf92ffcfaeab3740 to your computer and use it in GitHub Desktop.
Android Model-View-Intent with Unit Tests - FeedViewTest.kt Init Intent and Render State
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
private lateinit var test: FeedViewTestCase | |
private val intent = FeedViewIntent() | |
@ParameterizedTest | |
@MethodSource("FeedViewTestCaseStream") | |
fun `FeedView`(feedViewTestCase: FeedViewTestCase) = testCoroutineDispatcher.runBlockingTest { | |
test = feedViewTestCase | |
mockComponents(test) | |
val viewModel = FeedViewModel(...) | |
viewModel.bindIntents(object : FeedView { | |
override fun initState() = intent.initState | |
override fun loadFromNetwork() = intent.loadFromNetwork.filterNotNull() | |
override fun render(state: FeedViewState) { | |
when (state) { | |
is Feed -> testRenderFeed(state) | |
... | |
} | |
} | |
}) | |
// LoadFromNetwork intent | |
intent.loadFromNetwork.value = true | |
} | |
private fun testRenderFeed(feed: Feed) { | |
val expect = Feed( | |
toolbarState = setToolbarState(test.feedLoadIntent.feedType), | |
feed = test.mockFeedList.asPagedList(), | |
error = test.error | |
) | |
assertThat(feed).isEqualToComparingFieldByField(expect) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment