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
@get:Rule | |
val cleanState = cleanStateRule() | |
@Test | |
fun login_redirects_to_home_with_success_task() { | |
//Set login state to success | |
onUiSync { | |
val loggedUser = User(email = MockModels.anyEmail, uid = MockModels.anyId, username = MockModels.anyUsername, photoUrl = MockModels.anyPhoto) | |
val state = SessionState().copy(loginRequestState = requestSuccess(), verified = false, loggedIn = true, loggedUser = loggedUser) | |
sessionStore.setTestState(state) |
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
@get:Rule | |
val testDispatcher = testDispatcherRule() | |
@Test | |
fun login_button_dispatch_login_action() { | |
onView(withId(R.id.username_edit_text)).perform(typeText("someUsername")) | |
onView(withId(R.id.password_edit_text)).perform(typeText("somePassword")) | |
onView(withId(R.id.login_button)).perform(click()) | |
assertThat(testDispatcher.actions, contains(LoginAction(someUsername, somePassword))) |
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
fun listenUsernameChanges(){ | |
//Using RxJava | |
sessionStore | |
.flowable() | |
.map { it.name } | |
.subscribe { updateUsername(it) } | |
// Custom callback | |
sessionStore |
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
data class SessionState(val loginTask : Task = taskIdle(), | |
val loggedUsername : String? = null) | |
class SessionStore : Store<SessionState>(val loginController : controller) { | |
@Reducer | |
fun login(action: LoginAction): SessionState { | |
controller.login(user = action.username, password = action.password) | |
return state.copy(loginTask = taskRunning()) |
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
data class LoginAction(val username: String, val password: String) : Action | |
data class LoginCompleteAction(val loginTask: Task, val user: User?) |