diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/BaseUCTest.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/BaseUCTest.kt new file mode 100644 index 0000000..d0f6bc0 --- /dev/null +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/BaseUCTest.kt @@ -0,0 +1,30 @@ +package com.tarkvaraprojekt.mobileauthapp + +//import androidx.fragment.app.testing.launchFragmentInContainer +import androidx.test.espresso.IdlingPolicies +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.rule.ActivityTestRule + +import org.junit.* +import org.junit.runner.RunWith +import java.util.concurrent.TimeUnit + +@RunWith(AndroidJUnit4::class) +open class BaseUCTest { + @get:Rule + var activityActivityTestRule: ActivityTestRule = ActivityTestRule( + MainActivity::class.java + ) + + @Before + fun setUp() { + IdlingPolicies.setMasterPolicyTimeout(3, TimeUnit.SECONDS) + IdlingPolicies.setIdlingResourceTimeout(3, TimeUnit.SECONDS) + activityActivityTestRule.activity + .supportFragmentManager.beginTransaction() + } + + @After + fun tearDown() { + } +} \ No newline at end of file diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC12Test.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC12Test.kt new file mode 100644 index 0000000..7734dc9 --- /dev/null +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC12Test.kt @@ -0,0 +1,50 @@ +package com.tarkvaraprojekt.mobileauthapp + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.NoMatchingViewException +import androidx.test.espresso.action.ViewActions.* +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.* + +import org.junit.* + +class UC12Test : BaseUCTest() { + + private fun navigateToPINView() { + onView(withId(R.id.menu_settings_option)).perform(click()) + try { + // Delete existing PIN + onView(withText(R.string.pin1_delete)).perform(click()) + } catch (ignore: NoMatchingViewException) {} + + onView(withId(R.id.pin_menu_action)).perform(click()) + } + + @Test + fun validPIN() { + navigateToPINView() + onView(withText(R.string.pin_helper_text)).check(matches(isDisplayed())) + onView(supportsInputMethods()).perform(typeText("0000")) + onView(withText(R.string.continue_button)).perform(click()) + + onView(withText(R.string.pin_status_saved)).check(matches(isDisplayed())) + } + + @Test + fun tooShortPIN() { + navigateToPINView() + onView(supportsInputMethods()).perform(typeText("000")) + onView(withText(R.string.continue_button)).perform(click()) + + onView(withText(R.string.pin_helper_text)).check(matches(isDisplayed())) + } + + @Test + fun tooLongPIN() { + navigateToPINView() + onView(supportsInputMethods()).perform(typeText("0".repeat(13))) + onView(withText(R.string.continue_button)).perform(click()) + + onView(withText(R.string.pin_helper_text)).check(matches(isDisplayed())) + } +} \ No newline at end of file diff --git a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt index 3c03951..dca2c2b 100644 --- a/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt +++ b/MobileAuthApp/app/src/androidTest/java/com/tarkvaraprojekt/mobileauthapp/UC4Test.kt @@ -1,39 +1,16 @@ package com.tarkvaraprojekt.mobileauthapp -//import androidx.fragment.app.testing.launchFragmentInContainer import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.IdlingPolicies import androidx.test.espresso.NoMatchingViewException import androidx.test.espresso.action.ViewActions.* import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.ViewMatchers.* -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.rule.ActivityTestRule import org.junit.* -import org.junit.runner.RunWith -import java.util.concurrent.TimeUnit -@RunWith(AndroidJUnit4::class) -class UC4Test { - @get:Rule - var activityActivityTestRule: ActivityTestRule = ActivityTestRule( - MainActivity::class.java - ) +class UC4Test : BaseUCTest() { - @Before - fun setUp() { - IdlingPolicies.setMasterPolicyTimeout(3, TimeUnit.SECONDS) - IdlingPolicies.setIdlingResourceTimeout(3, TimeUnit.SECONDS) - activityActivityTestRule.activity - .supportFragmentManager.beginTransaction() - } - - @After - fun tearDown() { - } - - fun navigateToCANView() { + private fun navigateToCANView() { onView(withId(R.id.menu_settings_option)).perform(click()) try { // Delete existing CAN