-
Notifications
You must be signed in to change notification settings - Fork 658
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make EmbeddedContent have real content. (#9768)
- Loading branch information
1 parent
6749823
commit 0c4cce6
Showing
11 changed files
with
138 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 68 additions & 4 deletions
72
paymentsheet/src/main/java/com/stripe/android/paymentelement/embedded/EmbeddedContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,73 @@ | ||
package com.stripe.android.paymentelement.embedded | ||
|
||
import androidx.compose.material.Text | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Immutable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.testTag | ||
import androidx.compose.ui.res.dimensionResource | ||
import androidx.compose.ui.unit.dp | ||
import com.stripe.android.core.strings.ResolvableString | ||
import com.stripe.android.paymentsheet.R | ||
import com.stripe.android.paymentsheet.ui.ErrorMessage | ||
import com.stripe.android.paymentsheet.ui.Mandate | ||
import com.stripe.android.paymentsheet.verticalmode.PaymentMethodVerticalLayoutInteractor | ||
import com.stripe.android.paymentsheet.verticalmode.PaymentMethodVerticalLayoutUI | ||
import com.stripe.android.uicore.strings.resolve | ||
|
||
@Composable | ||
internal fun EmbeddedContent() { | ||
Text("Hello World!") | ||
@Immutable | ||
internal data class EmbeddedContent( | ||
private val interactor: PaymentMethodVerticalLayoutInteractor, | ||
private val error: ResolvableString? = null, | ||
private val mandate: ResolvableString? = null, | ||
) { | ||
@Composable | ||
fun Content() { | ||
val horizontalPadding = dimensionResource(R.dimen.stripe_paymentsheet_outer_spacing_horizontal) | ||
Column( | ||
modifier = Modifier | ||
.padding(horizontal = horizontalPadding) | ||
.padding(top = 8.dp) | ||
) { | ||
EmbeddedVerticalList() | ||
EmbeddedError() | ||
EmbeddedMandate() | ||
} | ||
} | ||
|
||
@Composable | ||
private fun EmbeddedVerticalList() { | ||
PaymentMethodVerticalLayoutUI( | ||
interactor = interactor, | ||
modifier = Modifier.padding(bottom = 8.dp), | ||
) | ||
} | ||
|
||
@Composable | ||
private fun EmbeddedError() { | ||
error?.let { | ||
ErrorMessage( | ||
error = it.resolve(), | ||
modifier = Modifier | ||
.padding(top = 2.dp, bottom = 8.dp) | ||
.testTag(EMBEDDED_ERROR_TEXT_TEST_TAG), | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun EmbeddedMandate() { | ||
Mandate( | ||
mandateText = mandate?.resolve(), | ||
modifier = Modifier | ||
.padding(bottom = 8.dp) | ||
.testTag(EMBEDDED_MANDATE_TEXT_TEST_TAG), | ||
) | ||
} | ||
|
||
companion object { | ||
const val EMBEDDED_ERROR_TEXT_TEST_TAG = "EMBEDDED_ERROR" | ||
const val EMBEDDED_MANDATE_TEXT_TEST_TAG = "EMBEDDED_MANDATE" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...src/test/java/com/stripe/android/paymentelement/embedded/EmbeddedContentScreenshotTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.stripe.android.paymentelement.embedded | ||
|
||
import com.stripe.android.core.strings.resolvableString | ||
import com.stripe.android.lpmfoundations.paymentmethod.PaymentMethodMetadataFactory | ||
import com.stripe.android.paymentsheet.verticalmode.FakePaymentMethodVerticalLayoutInteractor | ||
import com.stripe.android.screenshottesting.PaparazziRule | ||
import org.junit.Rule | ||
import kotlin.test.Test | ||
|
||
internal class EmbeddedContentScreenshotTest { | ||
@get:Rule | ||
val paparazziRule = PaparazziRule() | ||
|
||
@Test | ||
fun displaysVerticalModeList() { | ||
val metadata = PaymentMethodMetadataFactory.create() | ||
val interactor = FakePaymentMethodVerticalLayoutInteractor.create(metadata) | ||
val content = EmbeddedContent(interactor) | ||
paparazziRule.snapshot { | ||
content.Content() | ||
} | ||
} | ||
|
||
@Test | ||
fun displaysVerticalModeListWithError() { | ||
val metadata = PaymentMethodMetadataFactory.create() | ||
val interactor = FakePaymentMethodVerticalLayoutInteractor.create(metadata) | ||
val content = EmbeddedContent(interactor, error = "Some error".resolvableString) | ||
paparazziRule.snapshot { | ||
content.Content() | ||
} | ||
} | ||
|
||
@Test | ||
fun displaysVerticalModeListWithMandate() { | ||
val metadata = PaymentMethodMetadataFactory.create() | ||
val interactor = FakePaymentMethodVerticalLayoutInteractor.create(metadata) | ||
val content = EmbeddedContent(interactor, mandate = "Some mandate".resolvableString) | ||
paparazziRule.snapshot { | ||
content.Content() | ||
} | ||
} | ||
|
||
@Test | ||
fun displaysVerticalModeListWithErrorAndMandate() { | ||
val metadata = PaymentMethodMetadataFactory.create() | ||
val interactor = FakePaymentMethodVerticalLayoutInteractor.create(metadata) | ||
val content = EmbeddedContent( | ||
interactor = interactor, | ||
error = "Some error".resolvableString, | ||
mandate = "Some mandate".resolvableString | ||
) | ||
paparazziRule.snapshot { | ||
content.Content() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+17.7 KB
...EmbeddedContentScreenshotTest_displaysVerticalModeListWithErrorAndMandate[].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+14 KB
....embedded_EmbeddedContentScreenshotTest_displaysVerticalModeListWithError[].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+14.2 KB
...mbedded_EmbeddedContentScreenshotTest_displaysVerticalModeListWithMandate[].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10 KB
...ntelement.embedded_EmbeddedContentScreenshotTest_displaysVerticalModeList[].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.