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
@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
@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 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 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
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 setBold() = TextViewModel::setBold { | |
initialState { | |
setFalse { ::options { ::bold } } | |
} | |
withParams(true) expectState { | |
setTrue { ::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
data class TextOptions(val bold: Boolean = false) | |
data class TextState(val text: String? = null, val options: TextOptions = TextOptions()) : MvRxState | |
class TextViewModel(state: TextState) : MvRxViewModel<TextState>(state) { | |
fun setText(text: String) { | |
setState { | |
copy(text = text) | |
} |
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 TextViewModelTest : ViewModelTest<TextState, TextViewModel> { | |
override fun buildViewModel() = TextViewModel(TextState()) | |
@Test | |
fun setText() = TextViewModel::setText { | |
withParams("hello") expectState { | |
copy(text = "hello") | |
} | |
} |
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 setText() = TextViewModel::setText { | |
withParams("hello") expectState { | |
copy(text = "hello") | |
} | |
} |