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
import android.content.Context | |
import android.os.SystemClock | |
import android.support.v4.widget.SwipeRefreshLayout | |
import android.util.AttributeSet | |
/** | |
* ContentLoadingSwipeRefreshLayout implements a SwipeRefreshLayout that waits a minimum time to | |
* dismiss the refreshing indicator before showing. Once visible, the refreshing indicator will be | |
* visible for a minimum amount of time to avoid "flashes" in the UI when an event could take | |
* a largely variable time to complete (from none, to a user perceivable amount). |
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
class TaskDiffCallback : DiffUtil.ItemCallback<Task>() { | |
override fun areItemsTheSame(oldItem: Task, newItem: Task): Boolean { | |
return oldItem?.id == newItem?.id | |
} | |
override fun areContentsTheSame(oldItem: Task, newItem: Task): Boolean { | |
return oldItem == newItem | |
} | |
} |
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
class LoginFragment : Fragment(), Injectable { | |
@Inject | |
@VisibleForTesting | |
lateinit var viewModelFactory: ViewModelProvider.Factory | |
private lateinit var dataBinding: LoginFragmentBinding | |
private lateinit var viewModel: LoginViewModel |
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
<?xml version="1.0" encoding="utf-8"?> | |
<layout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools"> | |
<!--suppress AndroidUnknownAttribute --> | |
<data class="LoginFragmentBinding"> | |
<variable | |
name="viewModel" | |
type="com.melnykov.mvvmtesting.ui.login.LoginViewModel" /> |
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
@Test | |
fun isSignInButtonEnabledBinding() { | |
isSignInButtonEnabled.set(true) | |
onView(withId(R.id.button_sign_in)).check(matches(isEnabled())) | |
} | |
@Test | |
fun isProgressBarVisibleBinding() { | |
isProgressBarVisible.set(true) | |
onView(withId(R.id.progress_overlay)).check(matches(isDisplayed())) |
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
@MediumTest | |
@RunWith(AndroidJUnit4::class) | |
class LoginFragmentTest { | |
@Rule | |
@JvmField | |
val activityRule = IntentsTestRule(SingleFragmentActivity::class.java) | |
@Rule | |
@JvmField |
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
@Test | |
fun emailAndPasswordAreEmptyInitially() { | |
onView(withId(R.id.edit_text_email)).check(matches(withText(""))) | |
onView(withId(R.id.edit_text_password)).check(matches(withText(""))) | |
} |
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
class LoginViewModel @Inject constructor(private val loginGateway: LoginGateway) : ViewModel() { | |
val emailField = ObservableField<String>() | |
val passwordField = ObservableField<String>() | |
val isSignInButtonEnabled = ObservableBoolean() | |
val isProgressBarVisible = ObservableBoolean() | |
val navigateToForgotPasswordPage = SingleLiveEvent<Unit>() |
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
class SingleFragmentActivity : AppCompatActivity() { | |
fun setFragment(fragment: Fragment) { | |
supportFragmentManager.beginTransaction() | |
.add(android.R.id.content, fragment) | |
.commit() | |
} | |
} |
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
@Test | |
fun navigateToForgotPasswordPage_StartsBrowser() { | |
intending(not(isInternal())).respondWith( | |
Instrumentation.ActivityResult(Activity.RESULT_OK, null)) | |
navigateToForgotPasswordPage.call() | |
intended(allOf(hasAction(Intent.ACTION_VIEW), | |
hasData(Urls.FORGOT_PASSWORD))) | |
} |
NewerOlder