Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
Add hasHint(resId: Int) and hasError(resId: Int) for KEditTextLayout
Browse files Browse the repository at this point in the history
* Added hasHint(@StringRes resId: Int)

* Update hint

* Add hasError(@StringRes resId: Int)

* Add hasError(@StringRes resId: Int) tests

* Extract getResource

Co-authored-by: Konstantin Aksenov <aksenov.kostya@gmail.com>
  • Loading branch information
igorwojda and Vacxe authored Jun 6, 2020
1 parent a2aabc5 commit 951360b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.agoda.kakao.common.utilities

import android.content.Context
import androidx.annotation.StringRes
import androidx.test.platform.app.InstrumentationRegistry

fun getResourceString(@StringRes resId: Int): String {
val targetContext: Context = InstrumentationRegistry.getInstrumentation().targetContext
return targetContext.resources.getString(resId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

package com.agoda.kakao.edit

import android.content.Context
import androidx.annotation.StringRes
import androidx.test.espresso.ViewAssertion
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.platform.app.InstrumentationRegistry
import com.agoda.kakao.common.assertions.BaseAssertions
import com.agoda.kakao.common.matchers.TextInputLayoutCounterEnabledMatcher
import com.agoda.kakao.common.matchers.TextInputLayoutErrorEnabledMatcher
import com.agoda.kakao.common.matchers.TextInputLayoutHintEnabledMatcher
import com.agoda.kakao.common.utilities.getResourceString
import com.google.android.material.textfield.TextInputLayout

/**
Expand All @@ -34,6 +38,10 @@ interface TextInputLayoutAssertions : BaseAssertions {
})
}

fun hasHint(@StringRes resId: Int) {
hasHint(getResourceString(resId))
}

fun isHintEnabled() {
view.check(ViewAssertions.matches(TextInputLayoutHintEnabledMatcher(true)))
}
Expand All @@ -42,6 +50,10 @@ interface TextInputLayoutAssertions : BaseAssertions {
view.check(ViewAssertions.matches(TextInputLayoutHintEnabledMatcher(false)))
}

fun hasError(@StringRes resId: Int) {
hasError(getResourceString(resId))
}

fun hasError(error: String) {
view.check(ViewAssertion { view, notFoundException ->
if (view is TextInputLayout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class TextInputLayoutTest {
inputLayout {
hasCounterMaxLength(50)
hasHint("This is the HINT!")
hasHint(R.string.hint)
hasError("This is the ERROR!")
hasError(R.string.error)
isCounterEnabled()
isHintEnabled()
isErrorEnabled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class TextInputLayoutActivity : AppCompatActivity() {
isHintEnabled = true
isErrorEnabled = true
counterMaxLength = 50
hint = "This is the HINT!"
error = "This is the ERROR!"
hint = resources.getString(R.string.hint)
error = resources.getString(R.string.error)
}

findViewById<Button>(R.id.toggle_counter).setOnClickListener {
Expand Down
5 changes: 5 additions & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hint">This is the HINT!</string>
<string name="error">This is the ERROR!</string>
</resources>

0 comments on commit 951360b

Please sign in to comment.