Skip to content

Commit

Permalink
Merge pull request #229 from Worldpay/point-to-try-and-stabilise-ui-t…
Browse files Browse the repository at this point in the history
…ests

Point to try and stabilise UI tests
  • Loading branch information
ochalet-wp authored Jun 6, 2024
2 parents c69eaab + 4940987 commit 860aa2c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class CardConfigurationProvider(
} catch (ex: Exception) {
Log.d(
javaClass.simpleName,
"Error while fetching card configuration (setting defaults): $ex"
"Error while fetching card configuration (setting defaults): $ex", ex
)
cardConfiguration = CardConfiguration(emptyList(), DefaultCardRules.CARD_DEFAULTS)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class SessionResponseTest {
SessionResponse(
SessionResponse.Links(
SessionResponse.Links.Endpoints(
"https://npe.access.worldpay.com/sessions/<encrypted-data>"
"https://try.access.worldpay.com/sessions/<encrypted-data>"
),
arrayOf(
SessionResponse.Links.Curies(
Expand Down Expand Up @@ -133,7 +133,7 @@ class SessionResponseTest {
),
arrayOf(
SessionResponse.Links.Curies(
"https://npe.access.worldpay.com/rels/sessions{rel}.json",
"https://try.access.worldpay.com/rels/sessions{rel}.json",
"sessions",
true
)
Expand Down Expand Up @@ -275,11 +275,11 @@ class SessionResponseTest {
SessionResponse(
SessionResponse.Links(
SessionResponse.Links.Endpoints(
"https://npe.access.worldpay.com/sessions/<encrypted-data>"
"https://try.access.worldpay.com/sessions/<encrypted-data>"
),
arrayOf(
SessionResponse.Links.Curies(
"https://npe.access.worldpay.com/rels/sessions{rel}.json",
"https://try.access.worldpay.com/rels/sessions{rel}.json",
"sessions",
true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CardFragmentTestUtils(activityRule: ActivityTestRule<MainActivity>) : Abst
}

fun isInInitialState(): CardFragmentTestUtils {
attemptToCloseDialogIfPresent()
progressBarNotVisible()
enabledStateIs(pan = true, cvc = true, expiryDate = true, submitButton = false)
cardDetailsAre(pan = "", cvc = "", expiryDate = "")
Expand Down Expand Up @@ -69,6 +70,16 @@ class CardFragmentTestUtils(activityRule: ActivityTestRule<MainActivity>) : Abst
return this
}

fun attemptToCloseDialogIfPresent(): CardFragmentTestUtils {
try {
onView(withId(android.R.id.button1))
.perform(click())
} catch (e:Exception) {
// no dialog is present
}
return this
}

fun closeDialog(): CardFragmentTestUtils {
onView(withId(android.R.id.button1)).perform(click())
return this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.worldpay.access.checkout.sample.card

import android.util.Log
import android.widget.ImageView
import androidx.core.content.res.ResourcesCompat.getColor
import androidx.fragment.app.FragmentActivity
Expand Down Expand Up @@ -30,7 +31,11 @@ class CardValidationListener(private val activity: FragmentActivity) : AccessChe

override fun onBrandChange(cardBrand: CardBrand?) {
val brandLogo = activity.findViewById<ImageView>(R.id.card_flow_brand_logo)
getInstance(activity).fetchAndApplyCardLogo(cardBrand, brandLogo)
if (brandLogo != null) {
getInstance(activity).fetchAndApplyCardLogo(cardBrand, brandLogo)
} else {
Log.d(this::class.java.simpleName, "Received CardBranch change but could not find ImageView with id `R.id.card_flow_brand_logo`")
}
}

override fun onExpiryDateValidated(isValid: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class SVGImageLoader @JvmOverloads constructor(
override fun onResponse(call: Call, response: Response) {
response.body?.let { responseBody ->
run {
Log.d("SVGImageLoader", "Received image for brand $brandName")
svgImageRenderer.renderImage(responseBody.byteStream(), target, brandName)
}
}
Expand Down
2 changes: 1 addition & 1 deletion demo-app/src/prod/res/values/api_config.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="endpoint">https://npe.access.worldpay.com</string>
<string name="endpoint">https://try.access.worldpay.com</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CardConfigurationSchemaTest {

@Test
fun `given local card configuration file in repo then should be valid against remote card configuration JSON schema`() {
val url = "https://npe.access.worldpay.com/access-checkout/cardConfigurationSchema.json"
val url = "https://try.access.worldpay.com/access-checkout/cardConfigurationSchema.json"

val schema = JsonLoader.fromURL(URL(url))
val cardConfiguration = JsonLoader.fromPath("src/mock/res/raw/card_configuration_file.json")
Expand All @@ -25,7 +25,7 @@ class CardConfigurationSchemaTest {

@Test
fun `card type file in repo should be valid against remote card configuration JSON schema`() {
val url = "https://npe.access.worldpay.com/access-checkout/cardTypesSchema.json"
val url = "https://try.access.worldpay.com/access-checkout/cardTypesSchema.json"

val schema = JsonLoader.fromURL(URL(url))
val cardConfiguration = JsonLoader.fromPath("src/mock/res/raw/card_types.json")
Expand Down

0 comments on commit 860aa2c

Please sign in to comment.