Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import androidx.compose.ui.test.junit4.v2.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import androidx.compose.ui.test.performTextInput
import kotlinx.collections.immutable.persistentListOf
import org.junit.Rule
import org.junit.Test
import to.bitkit.models.PubkyProfile
Expand Down Expand Up @@ -53,33 +53,85 @@ class CreatePaymentRequestScreenTest {
composeTestRule.onNodeWithTag("PaymentRequestNote").assertDoesNotExist()
}

@Test
fun detailsWithRecipientShowsCardAndSendRequest() {
composeTestRule.setContent {
AppThemeSurface {
PaymentRequestDetailsContent(
amountInputViewModel = AmountInputViewModel(AmountInputHandler.stub()),
initialDraft = draft,
onBack = {},
onContinue = {},
recipient = PubkyProfile.placeholder(target.publicKey),
)
}
}

composeTestRule.onNodeWithTag("PaymentRequestSend").assertIsDisplayed()
composeTestRule.onNodeWithText("Send Request").assertIsDisplayed()
composeTestRule.onNodeWithTag("PaymentRequestAmountContinue").assertDoesNotExist()
}

@Test
fun recipientShowsEligibleContactAndSendAction() {
val contacts = PaymentRequestFigmaFixtures.recipientContacts
composeTestRule.setContent {
AppThemeSurface {
PaymentRequestRecipientContent(
targets = persistentListOf(target),
contacts = persistentListOf(PubkyProfile.placeholder(target.publicKey)),
targets = PaymentRequestFigmaFixtures.recipientTargets,
contacts = contacts,
isCreating = false,
onBack = {},
onEditExpiration = {},
onPaste = { target.publicKey },
onPaste = { PaymentRequestFigmaFixtures.anna.publicKey },
onSend = {},
)
}
}

composeTestRule.onNodeWithTag("PaymentRequestContact${target.publicKey}").assertIsDisplayed()
composeTestRule.onNodeWithText("Alex Stronghand").assertIsDisplayed()
composeTestRule.onNodeWithText("Anna Pleb").assertIsDisplayed()
composeTestRule.onNodeWithText("Areem Holden").assertIsDisplayed()
composeTestRule.onNodeWithText("Craig Wrong").assertIsDisplayed()
composeTestRule.onNodeWithText("John Carvalho").performScrollTo().assertIsDisplayed()
composeTestRule.onNodeWithTag("PaymentRequestRecipientSearch").assertIsDisplayed()
composeTestRule.onNodeWithTag("PaymentRequestContactsHeader").assertIsDisplayed()
composeTestRule.onNodeWithTag("PaymentRequestEditExpiration").assertIsDisplayed()
composeTestRule.onNodeWithTag("PaymentRequestRecipientPaste", useUnmergedTree = true).assertIsDisplayed()
composeTestRule.onNodeWithTag("PaymentRequestSend").assertIsDisplayed()

composeTestRule.onNodeWithTag("PaymentRequestRecipientSearch").performTextInput("not this contact")

composeTestRule.onNodeWithTag("PaymentRequestContact${target.publicKey}").assertDoesNotExist()
composeTestRule.onNodeWithText("Alex Stronghand").assertDoesNotExist()
composeTestRule.onNodeWithText("No matching saved contact with a private connection.").assertIsDisplayed()
}

@Test
fun recipientFromInvoiceHidesContactsHeader() {
composeTestRule.setContent {
AppThemeSurface {
PaymentRequestRecipientContent(
targets = PaymentRequestFigmaFixtures.recipientInvoiceTargets,
contacts = PaymentRequestFigmaFixtures.recipientInvoiceContacts,
isCreating = false,
onBack = {},
onEditExpiration = {},
onPaste = { PaymentRequestFigmaFixtures.anna.publicKey },
onSend = {},
showContactsHeader = false,
)
}
}

composeTestRule.onNodeWithTag("PaymentRequestContactsHeader").assertDoesNotExist()
composeTestRule.onNodeWithText("Alex Stronghand").assertIsDisplayed()
composeTestRule.onNodeWithText("Anna Pleb").assertIsDisplayed()
composeTestRule.onNodeWithText("Areem Holden").assertIsDisplayed()
composeTestRule.onNodeWithText("Craig Wrong").assertIsDisplayed()
composeTestRule.onNodeWithText("John Carvalho").performScrollTo().assertIsDisplayed()
composeTestRule.onNodeWithText("Paola Andina").performScrollTo().assertIsDisplayed()
}

@Test
fun sentShowsSuccessSurface() {
composeTestRule.setContent {
Expand All @@ -95,7 +147,7 @@ class CreatePaymentRequestScreenTest {
composeTestRule.onNodeWithTag("PaymentRequestSent").assertIsDisplayed()
composeTestRule.onNodeWithTag("PaymentRequestSentCheck").assertIsDisplayed()
composeTestRule.onNodeWithText("PAYMENT REQUESTED").assertIsDisplayed()
composeTestRule.onNodeWithText("Waiting for payment").assertIsDisplayed()
composeTestRule.onNodeWithText("Dinner").assertIsDisplayed()
}

private val draft = PaykitPaymentRequestDraft(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package to.bitkit.ui.screens.paymentrequests

import com.synonym.paykit.PaymentRequestLifecycleState
import kotlinx.collections.immutable.persistentListOf
import to.bitkit.models.PubkyProfile
import to.bitkit.repositories.PaykitPaymentRequest
import to.bitkit.repositories.PaykitPaymentRequestDeliveryStatus
import to.bitkit.repositories.PaykitPaymentRequestDirection
import to.bitkit.repositories.PaykitPaymentRequestTarget
import kotlin.time.Instant

/** Figma frames 48185:303457, 48185:303440, 48185:303376. */
internal object PaymentRequestFigmaFixtures {
val alex = profile("pubkyyrsduhcxpw74snwyct86m38c63j3pq8x4ycqikxg64roik8yw5xg", "Alex Stronghand")
val anna = profile("pubky1rsduhcxpw74snwyct86m38c63j3pq8x4ycqikxg64roik8yw5xg", "Anna Pleb")
val areem = profile("pubky3rsduhcxpw74snwyct86m38c63j3pq8x4ycqikxg64roik8yw5xg", "Areem Holden")
val craig = profile("pubkybrsduhcxpw74snwyct86m38c63j3pq8x4ycqikxg64roik8yw5xg", "Craig Wrong")
val john = profile("pubky5rsduhcxpw74snwyct86m38c63j3pq8x4ycqikxg64roik8yw5xg", "John Carvalho")
val paola = profile("pubkynrsduhcxpw74snwyct86m38c63j3pq8x4ycqikxg64roik8yw5xg", "Paola Andina")
val ben = profile("pubky8rsduhcxpw74snwyct86m38c63j3pq8x4ycqikxg64roik8yw5xg", "Ben")

val recipientContacts = persistentListOf(alex, anna, areem, craig, john)
val recipientInvoiceContacts = persistentListOf(alex, anna, areem, craig, john, paola)
val listContacts = persistentListOf(areem, ben, anna, john)

val recipientTargets = persistentListOf(
target(alex),
target(anna),
target(areem),
target(craig),
target(john),
)
val recipientInvoiceTargets = persistentListOf(
target(alex),
target(anna),
target(areem),
target(craig),
target(john),
target(paola),
)

fun listRequests(now: Instant) = persistentListOf(
request("incoming-areem", areem.publicKey, 21_000uL, "Lunch last week", now),
request("incoming-ben", ben.publicKey, 100_000uL, "Groceries", now),
request(
id = "outgoing-anna",
counterparty = anna.publicKey,
amountSats = 14_500uL,
note = "Snacks at conference",
createdAt = now,
direction = PaykitPaymentRequestDirection.Outgoing,
deliveryStatus = PaykitPaymentRequestDeliveryStatus.Sent,
),
request(
id = "outgoing-john",
counterparty = john.publicKey,
amountSats = 50_000uL,
note = "Steaks & Burgers",
createdAt = now,
direction = PaykitPaymentRequestDirection.Outgoing,
deliveryStatus = PaykitPaymentRequestDeliveryStatus.Sent,
),
)

fun listPending(now: Instant) = persistentListOf(
request("incoming-areem", areem.publicKey, 21_000uL, "Lunch last week", now),
request("incoming-ben", ben.publicKey, 100_000uL, "Groceries", now),
)

fun target(profile: PubkyProfile) = PaykitPaymentRequestTarget(
publicKey = profile.publicKey,
receiverPath = "bitkit/wallet",
)

fun request(
id: String,
counterparty: String,
amountSats: ULong,
note: String,
createdAt: Instant,
direction: PaykitPaymentRequestDirection = PaykitPaymentRequestDirection.Incoming,
deliveryStatus: PaykitPaymentRequestDeliveryStatus? = null,
) = PaykitPaymentRequest(
paymentRequestId = id,
counterparty = counterparty,
counterpartyReceiverPath = "bitkit/wallet",
amountValue = "0",
amountSats = amountSats,
note = note,
createdAt = createdAt,
expiresAt = null,
acceptedPaymentEndpointIdentifiers = listOf("btc-lightning-bolt11"),
deliveryStatus = deliveryStatus,
direction = direction,
lifecycleState = PaymentRequestLifecycleState.PROPOSED,
)

private fun profile(publicKey: String, name: String) =
PubkyProfile.forDisplay(publicKey, name, null)
}
Loading