From a5ca6fab8225f9b23eed5eff0b20125f31f490be Mon Sep 17 00:00:00 2001 From: Natthawut Haematulin Date: Fri, 6 Oct 2023 16:23:42 +0700 Subject: [PATCH] test: add UI tests --- .../ui/AuthorizingPaymentActivityTest.kt | 9 +++++++++ .../android/ui/CreditCardActivityTest.kt | 13 +++++++++++- .../android/ui/PaymentCreatorActivityTest.kt | 20 +++++++++++++------ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/sdk/src/androidTest/java/co/omise/android/ui/AuthorizingPaymentActivityTest.kt b/sdk/src/androidTest/java/co/omise/android/ui/AuthorizingPaymentActivityTest.kt index 6e99169b7..3f30242e8 100644 --- a/sdk/src/androidTest/java/co/omise/android/ui/AuthorizingPaymentActivityTest.kt +++ b/sdk/src/androidTest/java/co/omise/android/ui/AuthorizingPaymentActivityTest.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.app.Instrumentation import android.content.Intent import android.net.Uri +import android.view.WindowManager import android.widget.ProgressBar import androidx.arch.core.executor.testing.CountingTaskExecutorRule import androidx.lifecycle.MutableLiveData @@ -331,4 +332,12 @@ class AuthorizingPaymentActivityTest { ) ) } + + @Test + fun flagSecure_activityShouldContainFlagSecureInAttributes() { + val scenario = ActivityScenario.launchActivityForResult(intent) + scenario.onActivity { + assertEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) + } + } } diff --git a/sdk/src/sharedTest/java/co/omise/android/ui/CreditCardActivityTest.kt b/sdk/src/sharedTest/java/co/omise/android/ui/CreditCardActivityTest.kt index 378c301fe..c99891ccb 100644 --- a/sdk/src/sharedTest/java/co/omise/android/ui/CreditCardActivityTest.kt +++ b/sdk/src/sharedTest/java/co/omise/android/ui/CreditCardActivityTest.kt @@ -6,6 +6,7 @@ import android.app.Application import android.content.Intent import android.os.Bundle import android.view.View +import android.view.WindowManager import androidx.recyclerview.widget.RecyclerView.ViewHolder import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ActivityScenario.launchActivityForResult @@ -46,6 +47,7 @@ import org.junit.Before import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith +import org.mockito.internal.stubbing.answers.AnswersWithDelay import org.mockito.kotlin.any import org.mockito.kotlin.argumentCaptor import org.mockito.kotlin.doAnswer @@ -54,7 +56,6 @@ import org.mockito.kotlin.reset import org.mockito.kotlin.whenever @RunWith(AndroidJUnit4::class) -@Ignore class CreditCardActivityTest { private lateinit var scenario: ActivityScenario @@ -294,6 +295,7 @@ class CreditCardActivityTest { } @Test + @Ignore("Test failed") fun submitForm_disableFormWhenPressSubmit() { whenever(mockClient.send(any(), any())).doAnswer { invocation -> val callback = invocation.getArgument>(1) @@ -386,6 +388,15 @@ class CreditCardActivityTest { val result = scenario.result assertEquals(RESULT_CANCELED, result.resultCode) } + + + @Test + fun flagSecure_activityShouldContainFlagSecureInAttributes() { + val scenario = launchActivityForResult(intent) + scenario.onActivity { + assertEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) + } + } } private fun typeNumberText(numberText: String): ViewAction = diff --git a/sdk/src/sharedTest/java/co/omise/android/ui/PaymentCreatorActivityTest.kt b/sdk/src/sharedTest/java/co/omise/android/ui/PaymentCreatorActivityTest.kt index 572b6717e..7e53762d9 100644 --- a/sdk/src/sharedTest/java/co/omise/android/ui/PaymentCreatorActivityTest.kt +++ b/sdk/src/sharedTest/java/co/omise/android/ui/PaymentCreatorActivityTest.kt @@ -2,6 +2,7 @@ package co.omise.android.ui import android.app.Activity.RESULT_OK import android.content.Intent +import android.view.WindowManager import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.Espresso.onView @@ -9,7 +10,7 @@ import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.intent.Intents.intended import androidx.test.espresso.intent.matcher.ComponentNameMatchers.hasClassName import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent -import androidx.test.espresso.intent.rule.IntentsTestRule +import androidx.test.espresso.intent.rule.IntentsRule import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -26,9 +27,8 @@ import org.junit.runner.RunWith class PaymentCreatorActivityTest { @get:Rule - val intentRule = IntentsTestRule(TestFragmentActivity::class.java) + val intentRule = IntentsRule() - private lateinit var scenario: ActivityScenario private val capability = Capability() private val intent = Intent( ApplicationProvider.getApplicationContext(), @@ -42,7 +42,7 @@ class PaymentCreatorActivityTest { @Test fun initialActivity_collectExtrasIntent() { - scenario = ActivityScenario.launch(intent) + ActivityScenario.launchActivityForResult(intent) onView(withId(R.id.payment_creator_container)).check(matches(isDisplayed())) } @@ -50,7 +50,7 @@ class PaymentCreatorActivityTest { @Test fun navigateToCreditCardForm_startCreditCartActivity() { var activity: PaymentCreatorActivity? = null - scenario = ActivityScenario.launch(intent).onActivity { + ActivityScenario.launchActivityForResult(intent).onActivity { activity = it } @@ -64,10 +64,18 @@ class PaymentCreatorActivityTest { val creditCardIntent = Intent().apply { putExtra(EXTRA_TOKEN, Token()) } - scenario = ActivityScenario.launchActivityForResult(intent).onActivity { + val scenario = ActivityScenario.launchActivityForResult(intent).onActivity { it.performActivityResult(100, RESULT_OK, creditCardIntent) } assertEquals(RESULT_OK, scenario.result.resultCode) } + + @Test + fun flagSecure_activityShouldContainFlagSecureInAttributes() { + val scenario = ActivityScenario.launchActivityForResult(intent) + scenario.onActivity { + assertEquals(WindowManager.LayoutParams.FLAG_SECURE, it.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE) + } + } }