Skip to content

Commit 7d9c9f6

Browse files
committed
Update test infrastructure for embedded checkout support
This commit updates the test infrastructure to support the new embedded checkout interfaces while maintaining compatibility with existing tests. CheckoutViewControllerTests changes: - Updated MockCheckoutWebViewController initializations to include new parameters - Added createEmptyCheckoutCompletedPayload() helper for embedded checkout tests - Maintained backward compatibility with existing test methods MockCheckoutWebViewDelegate changes: - Added embedded checkout delegate method implementations - Added properties to capture embedded checkout event payloads - Added XCTestExpectation properties for embedded checkout event testing - Maintained all existing legacy delegate method functionality All existing tests continue to pass while new embedded checkout functionality can be tested using the extended mock interfaces.
1 parent 21ca044 commit 7d9c9f6

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

Tests/ShopifyCheckoutSheetKitTests/CheckoutViewControllerTests.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CheckoutViewDelegateTests: XCTestCase {
3838
$0.title = customTitle ?? "Checkout"
3939
}
4040
viewController = MockCheckoutWebViewController(
41-
checkoutURL: checkoutURL, delegate: delegate
41+
checkoutURL: checkoutURL, delegate: delegate, entryPoint: nil, options: nil
4242
)
4343

4444
navigationController = UINavigationController(rootViewController: viewController)
@@ -209,7 +209,7 @@ class CheckoutViewDelegateTests: XCTestCase {
209209

210210
func testCloseButtonUsesSystemDefaultWhenTintColorIsNil() {
211211
ShopifyCheckoutSheetKit.configuration.closeButtonTintColor = nil
212-
let controller = MockCheckoutWebViewController(checkoutURL: checkoutURL, delegate: delegate)
212+
let controller = MockCheckoutWebViewController(checkoutURL: checkoutURL, delegate: delegate, entryPoint: nil, options: nil)
213213

214214
let closeButton = controller.navigationItem.rightBarButtonItem
215215
XCTAssertNotNil(closeButton)
@@ -220,7 +220,7 @@ class CheckoutViewDelegateTests: XCTestCase {
220220
func testCloseButtonUsesCustomImageAndTintWhenColorIsSet() {
221221
let customColor = UIColor.red
222222
ShopifyCheckoutSheetKit.configuration.closeButtonTintColor = customColor
223-
let controller = MockCheckoutWebViewController(checkoutURL: checkoutURL, delegate: delegate)
223+
let controller = MockCheckoutWebViewController(checkoutURL: checkoutURL, delegate: delegate, entryPoint: nil, options: nil)
224224

225225
let closeButton = controller.navigationItem.rightBarButtonItem
226226
XCTAssertNotNil(closeButton)
@@ -231,7 +231,7 @@ class CheckoutViewDelegateTests: XCTestCase {
231231

232232
func testCloseButtonImageIsXMarkCircleFill() {
233233
ShopifyCheckoutSheetKit.configuration.closeButtonTintColor = .blue
234-
let controller = MockCheckoutWebViewController(checkoutURL: checkoutURL, delegate: delegate)
234+
let controller = MockCheckoutWebViewController(checkoutURL: checkoutURL, delegate: delegate, entryPoint: nil, options: nil)
235235

236236
let closeButton = controller.navigationItem.rightBarButtonItem
237237
let expectedImage = UIImage(systemName: "xmark.circle.fill")
@@ -249,6 +249,10 @@ protocol Dismissible: AnyObject {
249249

250250
extension CheckoutWebViewController: Dismissible {}
251251

252+
func createEmptyCheckoutCompletedPayload() -> CheckoutCompletePayload {
253+
return CheckoutCompletePayload(orderID: "test_order_123")
254+
}
255+
252256
class MockCheckoutWebViewController: CheckoutWebViewController {
253257
private(set) var dismissCalled = false
254258

Tests/ShopifyCheckoutSheetKitTests/Mocks/MockCheckoutWebViewDelegate.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,36 @@ class MockCheckoutWebViewDelegate: CheckoutWebViewDelegate {
8484
completedEventReceived = event
8585
didEmitCheckoutCompletedEventExpectation?.fulfill()
8686
}
87+
88+
// MARK: - Embedded Checkout Delegate Methods
89+
90+
var stateChangePayloadReceived: CheckoutStatePayload?
91+
var completePayloadReceived: CheckoutCompletePayload?
92+
var errorsReceived: [ErrorPayload]?
93+
var webPixelsPayloadReceived: WebPixelsPayload?
94+
95+
var didChangeStateExpectation: XCTestExpectation?
96+
var didCompleteEmbeddedCheckoutExpectation: XCTestExpectation?
97+
var didFailEmbeddedCheckoutExpectation: XCTestExpectation?
98+
var didEmitEmbeddedWebPixelEventExpectation: XCTestExpectation?
99+
100+
func checkoutViewDidChangeState(state: CheckoutStatePayload) {
101+
stateChangePayloadReceived = state
102+
didChangeStateExpectation?.fulfill()
103+
}
104+
105+
func checkoutViewDidComplete(payload: CheckoutCompletePayload) {
106+
completePayloadReceived = payload
107+
didCompleteEmbeddedCheckoutExpectation?.fulfill()
108+
}
109+
110+
func checkoutViewDidFail(errors: [ErrorPayload]) {
111+
errorsReceived = errors
112+
didFailEmbeddedCheckoutExpectation?.fulfill()
113+
}
114+
115+
func checkoutViewDidEmitWebPixelEvent(payload: WebPixelsPayload) {
116+
webPixelsPayloadReceived = payload
117+
didEmitEmbeddedWebPixelEventExpectation?.fulfill()
118+
}
87119
}

0 commit comments

Comments
 (0)