Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package com.reactnativestripesdk.paymentsheet
package com.reactnativestripesdk

import android.os.Bundle
import androidx.core.os.bundleOf
import com.reactnativestripesdk.PaymentSheetFragment
import androidx.test.core.app.ApplicationProvider
import com.facebook.react.bridge.Arguments
import com.facebook.react.soloader.OpenSourceMergedSoMapping
import com.facebook.soloader.SoLoader
import com.reactnativestripesdk.utils.readableMapOf
import com.stripe.android.paymentsheet.PaymentSheet
import org.junit.Assert
import org.junit.Before
import org.junit.Test

class PaymentSheetFragmentTest {
@Test
fun hasNoArgsConstructor() {
// This is just a type check to make sure to keep a no args constructor
// so that when the fragment is re-created it doesn't crash.
PaymentSheetFragment()
class PaymentSheetManagerTest {
@Before
fun setup() {
SoLoader.init(ApplicationProvider.getApplicationContext(), OpenSourceMergedSoMapping)
}

@Test
fun buildGooglePayConfig() {
val config =
PaymentSheetFragment.buildGooglePayConfig(
bundleOf(
PaymentSheetManager.buildGooglePayConfig(
readableMapOf(
"merchantCountryCode" to "US",
"currencyCode" to "USD",
"testEnv" to true,
Expand All @@ -39,13 +40,13 @@ class PaymentSheetFragmentTest {

@Test
fun buildGooglePayConfig_returnsNull() {
val config = PaymentSheetFragment.buildGooglePayConfig(null)
val config = PaymentSheetManager.buildGooglePayConfig(null)
Assert.assertNull(config)
}

@Test
fun buildGooglePayConfig_returnsNullForEmptyBundle() {
val config = PaymentSheetFragment.buildGooglePayConfig(Bundle.EMPTY)
val config = PaymentSheetManager.buildGooglePayConfig(Arguments.createMap())
Assert.assertNull(config)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.reactnativestripesdk.addresssheet

import androidx.core.os.bundleOf
import androidx.test.core.app.ApplicationProvider
import com.facebook.react.bridge.BridgeReactContext
import com.facebook.react.bridge.WritableNativeMap
import com.facebook.react.soloader.OpenSourceMergedSoMapping
import com.facebook.soloader.SoLoader
import com.reactnativestripesdk.utils.readableMapOf
import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.paymentsheet.addresselement.AddressDetails
import com.stripe.android.paymentsheet.addresselement.AddressLauncher
Expand All @@ -14,10 +13,6 @@ import org.junit.Before
import org.junit.Test

class AddressSheetViewTest {
private val reactApplicationContext =
BridgeReactContext(
ApplicationProvider.getApplicationContext(),
)
private val testCity = "testCity"
private val testCountry = "testCountry"
private val testLine1 = "testLine1"
Expand All @@ -29,14 +24,14 @@ class AddressSheetViewTest {

@Before
fun setup() {
SoLoader.init(reactApplicationContext, OpenSourceMergedSoMapping)
SoLoader.init(ApplicationProvider.getApplicationContext(), OpenSourceMergedSoMapping)
}

@Test
fun buildAddressDetails_Default() {
val addressDetails =
AddressSheetView.buildAddressDetails(
bundleOf(),
readableMapOf(),
)
Assert.assertNull(addressDetails.address)
Assert.assertNull(addressDetails.name)
Expand All @@ -48,12 +43,12 @@ class AddressSheetViewTest {
fun buildAddressDetails_Custom() {
val addressDetails =
AddressSheetView.buildAddressDetails(
bundleOf(
readableMapOf(
"name" to testName,
"phone" to testPhone,
"isCheckboxSelected" to true,
"address" to
bundleOf(
readableMapOf(
"city" to testCity,
"line1" to testLine1,
),
Expand All @@ -70,7 +65,7 @@ class AddressSheetViewTest {
fun buildAddress_Default() {
val address =
AddressSheetView.buildAddress(
bundleOf(),
readableMapOf(),
)
Assert.assertNull(address?.city)
Assert.assertNull(address?.country)
Expand All @@ -84,7 +79,7 @@ class AddressSheetViewTest {
fun buildAddress_Custom() {
val address =
AddressSheetView.buildAddress(
bundleOf(
readableMapOf(
"city" to testCity,
"line1" to testLine1,
"country" to testCountry,
Expand Down Expand Up @@ -178,28 +173,24 @@ class AddressSheetViewTest {
),
)

val result =
WritableNativeMap().also {
it.putString("name", testName)
it.putMap(
"address",
WritableNativeMap().also {
it.putString("city", testCity)
it.putString("country", testCountry)
it.putString("state", testState)
it.putString("line1", testLine1)
it.putString("line2", testLine2)
it.putString("postalCode", testPostalCode)
},
)
it.putString("phone", testPhone)
it.putBoolean("isCheckboxSelected", true)
}

val expected =
WritableNativeMap().also {
it.putMap("result", result)
}
readableMapOf(
"result" to
readableMapOf(
"name" to testName,
"address" to
readableMapOf(
"city" to testCity,
"country" to testCountry,
"state" to testState,
"line1" to testLine1,
"line2" to testLine2,
"postalCode" to testPostalCode,
),
"phone" to testPhone,
"isCheckboxSelected" to true,
),
)

Assert.assertEquals(expected, received)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.reactnativestripesdk.mappers

import androidx.test.core.app.ApplicationProvider
import com.facebook.react.bridge.BridgeReactContext
import com.facebook.react.bridge.WritableNativeMap
import com.facebook.react.soloader.OpenSourceMergedSoMapping
import com.facebook.soloader.SoLoader
Expand All @@ -11,14 +10,9 @@ import org.junit.Before
import org.junit.Test

class MappersTest {
private val reactApplicationContext =
BridgeReactContext(
ApplicationProvider.getApplicationContext(),
)

@Before
fun setup() {
SoLoader.init(reactApplicationContext, OpenSourceMergedSoMapping)
SoLoader.init(ApplicationProvider.getApplicationContext(), OpenSourceMergedSoMapping)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.sp
import androidx.test.core.app.ApplicationProvider
import com.facebook.react.bridge.BridgeReactContext
import com.facebook.react.soloader.OpenSourceMergedSoMapping
import com.facebook.soloader.SoLoader
import com.reactnativestripesdk.toHtmlString
Expand All @@ -20,14 +19,9 @@ import org.junit.Before
import org.junit.Test

class PaymentOptionDisplayDataMapperTest {
private val reactApplicationContext =
BridgeReactContext(
ApplicationProvider.getApplicationContext(),
)

@Before
fun setup() {
SoLoader.init(reactApplicationContext, OpenSourceMergedSoMapping)
SoLoader.init(ApplicationProvider.getApplicationContext(), OpenSourceMergedSoMapping)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.facebook.react.uimanager.UIManagerHelper
import com.google.android.material.shape.CornerFamily
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import com.reactnativestripesdk.utils.getIntOr
import com.reactnativestripesdk.utils.getIntOrNull
import com.reactnativestripesdk.utils.getValOr
import com.stripe.android.databinding.StripeBecsDebitWidgetBinding
Expand Down Expand Up @@ -41,11 +42,11 @@ class AuBECSDebitFormView(
val textColor = getValOr(value, "textColor", null)
val textErrorColor = getValOr(value, "textErrorColor", null)
val placeholderColor = getValOr(value, "placeholderColor", null)
val fontSize = getIntOrNull(value, "fontSize")
val borderWidth = getIntOrNull(value, "borderWidth")
val fontSize = value.getIntOrNull("fontSize")
val borderWidth = value.getIntOrNull("borderWidth")
val backgroundColor = getValOr(value, "backgroundColor", null)
val borderColor = getValOr(value, "borderColor", null)
val borderRadius = getIntOrNull(value, "borderRadius") ?: 0
val borderRadius = value.getIntOr("borderRadius", 0)

textColor?.let {
(binding.accountNumberEditText as StripeEditText).setTextColor(Color.parseColor(it))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.google.android.material.shape.CornerFamily
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import com.reactnativestripesdk.utils.PostalCodeUtilities
import com.reactnativestripesdk.utils.getIntOr
import com.reactnativestripesdk.utils.getIntOrNull
import com.reactnativestripesdk.utils.getValOr
import com.reactnativestripesdk.utils.hideSoftKeyboard
Expand Down Expand Up @@ -103,12 +104,12 @@ class CardFieldView(
}

fun setCardStyle(value: ReadableMap?) {
val borderWidth = getIntOrNull(value, "borderWidth")
val borderWidth = value.getIntOrNull("borderWidth")
val backgroundColor = getValOr(value, "backgroundColor", null)
val borderColor = getValOr(value, "borderColor", null)
val borderRadius = getIntOrNull(value, "borderRadius") ?: 0
val borderRadius = value.getIntOr("borderRadius", 0)
val textColor = getValOr(value, "textColor", null)
val fontSize = getIntOrNull(value, "fontSize")
val fontSize = value.getIntOrNull("fontSize")
val fontFamily = getValOr(value, "fontFamily")
val placeholderColor = getValOr(value, "placeholderColor", null)
val textErrorColor = getValOr(value, "textErrorColor", null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.graphics.Color
import android.os.Build
import android.text.InputFilter
import android.view.View
import android.view.View.OnFocusChangeListener
import android.widget.FrameLayout
import androidx.core.view.setMargins
import com.facebook.react.bridge.ReadableMap
Expand All @@ -18,6 +17,7 @@ import com.google.android.material.shape.CornerFamily
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import com.reactnativestripesdk.utils.PostalCodeUtilities
import com.reactnativestripesdk.utils.getIntOr
import com.reactnativestripesdk.utils.getIntOrNull
import com.reactnativestripesdk.utils.getValOr
import com.reactnativestripesdk.utils.hideSoftKeyboard
Expand Down Expand Up @@ -143,10 +143,10 @@ class CardFormView(
fun setCardStyle(value: ReadableMap?) {
val backgroundColor = getValOr(value, "backgroundColor", null)
val textColor = getValOr(value, "textColor", null)
val borderWidth = getIntOrNull(value, "borderWidth")
val borderWidth = value.getIntOrNull("borderWidth")
val borderColor = getValOr(value, "borderColor", null)
val borderRadius = getIntOrNull(value, "borderRadius") ?: 0
val fontSize = getIntOrNull(value, "fontSize")
val borderRadius = value.getIntOr("borderRadius", 0)
val fontSize = value.getIntOrNull("fontSize")
val fontFamily = getValOr(value, "fontFamily")
val placeholderColor = getValOr(value, "placeholderColor", null)
val textErrorColor = getValOr(value, "textErrorColor", null)
Expand Down
Loading