Skip to content

Commit 6b119f9

Browse files
committed
Normalize RN checkout E2E native support
1 parent 3c9fe7c commit 6b119f9

6 files changed

Lines changed: 30 additions & 11 deletions

File tree

platforms/android/lib/src/main/java/com/shopify/checkoutkit/CheckoutDialog.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ internal class CheckoutDialog(
7474
setBackgroundColor(colorScheme.headerBackgroundColor())
7575
setTitleTextColor(colorScheme.headerFontColor())
7676
inflateMenu(R.menu.checkout_menu)
77-
menu.findItem(R.id.checkoutKitCloseBtn).apply { setupCloseButton(colorScheme) }
77+
menu.findItem(R.id.shopify_checkout_kit_close_button).apply { setupCloseButton(colorScheme) }
7878
}
7979

8080
findViewById<ProgressBar>(R.id.progressBar).apply {

platforms/android/lib/src/main/res/menu/checkout_menu.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
33
xmlns:android="http://schemas.android.com/apk/res/android">
4-
<item android:id="@+id/checkoutKitCloseBtn"
4+
<item android:id="@+id/shopify_checkout_kit_close_button"
55
android:icon="@drawable/close"
66
android:title="@string/close_checkout"
77
app:showAsAction="always" />

platforms/android/lib/src/test/java/com/shopify/checkoutkit/CheckoutDialogTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class CheckoutDialogTest {
201201

202202
// click cancel button
203203
val header = dialog.findViewById<Toolbar>(R.id.checkoutKitHeader)
204-
header.menu.performIdentifierAction(R.id.checkoutKitCloseBtn, 0)
204+
header.menu.performIdentifierAction(R.id.shopify_checkout_kit_close_button, 0)
205205
ShadowLooper.runUiThreadTasks()
206206

207207
verify(mockListener, timeout(2000)).onCheckoutCanceled()
@@ -216,7 +216,7 @@ class CheckoutDialogTest {
216216

217217
// click cancel button
218218
val header = dialog.findViewById<Toolbar>(R.id.checkoutKitHeader)
219-
header.menu.performIdentifierAction(R.id.checkoutKitCloseBtn, 0)
219+
header.menu.performIdentifierAction(R.id.shopify_checkout_kit_close_button, 0)
220220
ShadowLooper.runUiThreadTasks()
221221

222222
assertThat(dialog.containsChildOfType(CheckoutWebView::class.java)).isFalse()
@@ -272,7 +272,7 @@ class CheckoutDialogTest {
272272

273273
val dialog = ShadowDialog.getLatestDialog() as CheckoutDialog
274274
val toolbar = dialog.findViewById<Toolbar>(R.id.checkoutKitHeader)
275-
val closeMenuItem = toolbar.menu.findItem(R.id.checkoutKitCloseBtn)
275+
val closeMenuItem = toolbar.menu.findItem(R.id.shopify_checkout_kit_close_button)
276276

277277
assertThat(closeMenuItem).isNotNull
278278
assertThat(closeMenuItem.icon).isNotNull
@@ -296,7 +296,7 @@ class CheckoutDialogTest {
296296

297297
val dialog = ShadowDialog.getLatestDialog() as CheckoutDialog
298298
val toolbar = dialog.findViewById<Toolbar>(R.id.checkoutKitHeader)
299-
val closeMenuItem = toolbar.menu.findItem(R.id.checkoutKitCloseBtn)
299+
val closeMenuItem = toolbar.menu.findItem(R.id.shopify_checkout_kit_close_button)
300300

301301
assertThat(closeMenuItem).isNotNull
302302
assertThat(closeMenuItem.icon).isNotNull
@@ -319,7 +319,7 @@ class CheckoutDialogTest {
319319

320320
val dialog = ShadowDialog.getLatestDialog() as CheckoutDialog
321321
val toolbar = dialog.findViewById<Toolbar>(R.id.checkoutKitHeader)
322-
val closeMenuItem = toolbar.menu.findItem(R.id.checkoutKitCloseBtn)
322+
val closeMenuItem = toolbar.menu.findItem(R.id.shopify_checkout_kit_close_button)
323323

324324
assertThat(closeMenuItem).isNotNull
325325
assertThat(closeMenuItem.icon).isNotNull
@@ -360,7 +360,7 @@ class CheckoutDialogTest {
360360

361361
val dialog = ShadowDialog.getLatestDialog() as CheckoutDialog
362362
val toolbar = dialog.findViewById<Toolbar>(R.id.checkoutKitHeader)
363-
val closeMenuItem = toolbar.menu.findItem(R.id.checkoutKitCloseBtn)
363+
val closeMenuItem = toolbar.menu.findItem(R.id.shopify_checkout_kit_close_button)
364364

365365
assertThat(closeMenuItem).isNotNull
366366
assertThat(closeMenuItem.icon).isNotNull

platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/AcceleratedCheckoutButtons.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,18 @@ class RCTAcceleratedCheckoutButtonsView: UIView {
288288

289289
// Attach config (and Apple Pay config if available)
290290
if let applePayConfig = AcceleratedCheckoutConfiguration.shared.applePayConfiguration {
291-
view = AnyView(buttons.environment(\.shopifyAcceleratedCheckoutsConfiguration, config).environment(\.shopifyApplePayConfiguration, applePayConfig).environment(\.colorScheme, colorScheme))
291+
view = AnyView(
292+
buttons
293+
.environment(\.shopifyAcceleratedCheckoutsConfiguration, config)
294+
.environment(\.shopifyApplePayConfiguration, applePayConfig)
295+
.environment(\.colorScheme, colorScheme)
296+
)
292297
} else {
293-
view = AnyView(buttons.environment(\.shopifyAcceleratedCheckoutsConfiguration, config).environment(\.colorScheme, colorScheme))
298+
view = AnyView(
299+
buttons
300+
.environment(\.shopifyAcceleratedCheckoutsConfiguration, config)
301+
.environment(\.colorScheme, colorScheme)
302+
)
294303
}
295304

296305
if let hostingController {

platforms/swift/Sources/ShopifyCheckoutKit/CheckoutWebViewController.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import WebKit
33

44
@MainActor
55
class CheckoutWebViewController: UIViewController, UIAdaptivePresentationControllerDelegate {
6+
/// Stable identifier consumed by React Native Maestro E2E tests.
7+
/// Keep this value in sync with the checkout close selector used by E2E flows.
8+
private static let closeButtonAccessibilityIdentifier = "shopify_checkout_kit_close_button"
9+
610
var onCancel: (() -> Void)?
711
var onFail: ((CheckoutError) -> Void)?
812
weak var delegate: (any CheckoutDelegate)?
@@ -41,14 +45,17 @@ class CheckoutWebViewController: UIViewController, UIAdaptivePresentationControl
4145
}
4246

4347
item.tintColor = closeButtonTintColor
48+
item.accessibilityIdentifier = Self.closeButtonAccessibilityIdentifier
4449
return item
4550
}
4651

47-
return UIBarButtonItem(
52+
let item = UIBarButtonItem(
4853
barButtonSystemItem: .close,
4954
target: self,
5055
action: #selector(close)
5156
)
57+
item.accessibilityIdentifier = Self.closeButtonAccessibilityIdentifier
58+
return item
5259
}()
5360

5461
var progressObserver: NSKeyValueObservation?

platforms/swift/Tests/ShopifyCheckoutKitTests/CheckoutViewControllerTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import XCTest
77
class CheckoutViewDelegateTests: XCTestCase {
88
private var customTitle: String?
99
private let checkoutURL = URL(string: "https://checkout-sdk.myshopify.com")!
10+
private let expectedCloseButtonIdentifier = "shopify_checkout_kit_close_button"
1011
private var viewController: MockCheckoutWebViewController!
1112
private var navigationController: UINavigationController!
1213

@@ -86,6 +87,7 @@ class CheckoutViewDelegateTests: XCTestCase {
8687
XCTAssertNotNil(closeButton)
8788
XCTAssertEqual(closeButton?.style, .plain)
8889
XCTAssertNil(closeButton?.image)
90+
XCTAssertEqual(closeButton?.accessibilityIdentifier, expectedCloseButtonIdentifier)
8991
}
9092

9193
func testCloseButtonUsesCustomImageAndTintWhenColorIsSet() {
@@ -98,6 +100,7 @@ class CheckoutViewDelegateTests: XCTestCase {
98100
XCTAssertEqual(closeButton?.style, .plain)
99101
XCTAssertNotNil(closeButton?.image)
100102
XCTAssertEqual(closeButton?.tintColor, customColor)
103+
XCTAssertEqual(closeButton?.accessibilityIdentifier, expectedCloseButtonIdentifier)
101104
}
102105

103106
func testCloseButtonImageIsXMarkCircleFill() {

0 commit comments

Comments
 (0)