Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mludowise-stripe committed Sep 25, 2024
1 parent 7fe0bd9 commit 737a3a9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 6 deletions.
18 changes: 13 additions & 5 deletions StripeConnect/StripeConnect.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
41D17A6D2C5A7429007C6EE6 /* StripeiOS-Shared.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 41D17A622C5A7429007C6EE6 /* StripeiOS-Shared.xcconfig */; };
41D17A6E2C5A7429007C6EE6 /* Version.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 41D17A632C5A7429007C6EE6 /* Version.xcconfig */; };
E65691002CA37FAC00E0DB00 /* LogoutSender.swift in Sources */ = {isa = PBXBuildFile; fileRef = E65690FF2CA37FAC00E0DB00 /* LogoutSender.swift */; };
E65691022CA3B50B00E0DB00 /* LogoutSenderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E65691012CA3B50B00E0DB00 /* LogoutSenderTests.swift */; };
E65691082CA3C3F000E0DB00 /* EmbeddedComponentManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E65691072CA3C3F000E0DB00 /* EmbeddedComponentManagerTests.swift */; };
E6F485F82C9E35A5000D914F /* PaymentDetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6F485F72C9E35A5000D914F /* PaymentDetailsViewController.swift */; };
E6F485FC2C9E360A000D914F /* ConnectJSURLParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6F485FB2C9E360A000D914F /* ConnectJSURLParams.swift */; };
E6F485FE2C9E36B2000D914F /* PaymentDetailsViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6F485FD2C9E36B2000D914F /* PaymentDetailsViewControllerTests.swift */; };
Expand Down Expand Up @@ -187,6 +189,8 @@
41D17A622C5A7429007C6EE6 /* StripeiOS-Shared.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "StripeiOS-Shared.xcconfig"; sourceTree = "<group>"; };
41D17A632C5A7429007C6EE6 /* Version.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Version.xcconfig; sourceTree = "<group>"; };
E65690FF2CA37FAC00E0DB00 /* LogoutSender.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoutSender.swift; sourceTree = "<group>"; };
E65691012CA3B50B00E0DB00 /* LogoutSenderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoutSenderTests.swift; sourceTree = "<group>"; };
E65691072CA3C3F000E0DB00 /* EmbeddedComponentManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmbeddedComponentManagerTests.swift; sourceTree = "<group>"; };
E6F485F72C9E35A5000D914F /* PaymentDetailsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaymentDetailsViewController.swift; sourceTree = "<group>"; };
E6F485FB2C9E360A000D914F /* ConnectJSURLParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectJSURLParams.swift; sourceTree = "<group>"; };
E6F485FD2C9E36B2000D914F /* PaymentDetailsViewControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaymentDetailsViewControllerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -219,6 +223,7 @@
isa = PBXGroup;
children = (
410D0FDA2C6D21B0009B0E26 /* CallSetterWithSerializableValueSenderTests.swift */,
E65691012CA3B50B00E0DB00 /* LogoutSenderTests.swift */,
410D0FDC2C6D23AD009B0E26 /* ReturnedFromAuthenticatedWebViewSenderTests.swift */,
410D0FD82C6D1F25009B0E26 /* UpdateConnectInstanceSenderTests.swift */,
);
Expand Down Expand Up @@ -283,9 +288,9 @@
isa = PBXGroup;
children = (
413987BC2C63F34B001D375E /* VoidPayload.swift */,
418666492C66AC66003DB62E /* OnSetterFunctionCalledMessageHandler.swift */,
413987BA2C63F34B001D375E /* ScriptMessageHandler.swift */,
413987BB2C63F34B001D375E /* ScriptMessageHandlerWithReply.swift */,
418666492C66AC66003DB62E /* OnSetterFunctionCalledMessageHandler.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -471,13 +476,14 @@
41D17A4E2C5A73A7007C6EE6 /* StripeConnectTests */ = {
isa = PBXGroup;
children = (
41BCCFFC2C8BA44700797E01 /* Resources */,
41BCCFEE2C8B3C7900797E01 /* Helpers */,
41810D682C88C4B100F10EB7 /* AppearanceTests.swift */,
416E9E882C76B36F00A0B917 /* Components */,
41BCCFFA2C8B95BB00797E01 /* CustomFontSourceTests.swift */,
E65691072CA3C3F000E0DB00 /* EmbeddedComponentManagerTests.swift */,
41BCCFEE2C8B3C7900797E01 /* Helpers */,
41814EE62C6BC8690014EB5E /* Internal */,
41BCCFFC2C8BA44700797E01 /* Resources */,
416E9E812C76994C00A0B917 /* WebView+Tests.swift */,
41810D682C88C4B100F10EB7 /* AppearanceTests.swift */,
41BCCFFA2C8B95BB00797E01 /* CustomFontSourceTests.swift */,
);
path = StripeConnectTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -692,13 +698,15 @@
410D0FDB2C6D21B0009B0E26 /* CallSetterWithSerializableValueSenderTests.swift in Sources */,
410D0FE72C6D3BBC009B0E26 /* ConnectWebViewTests.swift in Sources */,
410D0FD02C6D0319009B0E26 /* PageDidLoadMessageHandlerTests.swift in Sources */,
E65691022CA3B50B00E0DB00 /* LogoutSenderTests.swift in Sources */,
41814EED2C6BED8C0014EB5E /* FetchClientSecretMessageHandlerTests.swift in Sources */,
41814EE82C6BC8800014EB5E /* ScriptWebTestBase.swift in Sources */,
41BCCFF02C8B3C8900797E01 /* AppearanceWrapper+Default.swift in Sources */,
416E9E822C76994C00A0B917 /* WebView+Tests.swift in Sources */,
41BCCFFB2C8B95BB00797E01 /* CustomFontSourceTests.swift in Sources */,
4161C28C2CA1B54E005BD67C /* OnSetterFunctionCalledMessageHandlerTests.swift in Sources */,
41814EF32C6BFA4B0014EB5E /* OnLoaderStartMessageHandlerTests.swift in Sources */,
E65691082CA3C3F000E0DB00 /* EmbeddedComponentManagerTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ConnectComponentWebView: ConnectWebView {
var componentManager: EmbeddedComponentManager

/// The component type that should be loaded.
private var componentType: ComponentType
let componentType: ComponentType

/// The content controller that registers JS -> Swift message handlers
private let contentController: WKUserContentController
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// EmbeddedComponentManagerTests.swift
// StripeConnectTests
//
// Created by Mel Ludowise on 9/24/24.
//

@_spi(PrivateBetaConnect) @testable import StripeConnect
import XCTest

class EmbeddedComponentManagerTests: XCTestCase {
var componentManager = EmbeddedComponentManager {
return nil
}

@MainActor
func testLogout() async throws {
// Expect a logout proxy
let logoutProxy = try XCTUnwrap(componentManager.childWebViews.allObjects.first)
XCTAssertEqual(componentManager.childWebViews.count, 1)
XCTAssertEqual(logoutProxy.componentType, .logoutProxy)

let expectation = try logoutProxy.expectationForMessageReceived(sender: LogoutSender())

componentManager.logout()

await fulfillment(of: [expectation], timeout: TestHelpers.defaultTimeout)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,18 @@ class ConnectComponentWebViewTests: XCTestCase {
{"appearance":{"variables":{"fontFamily":"-apple-system","fontSizeBase":"16px"}},"fonts":[{"family":".AppleSystemUIFont","src":"url(data:font\\/txt;charset=utf-8;base64,dGVzdAo=)","weight":"400"}],"locale":"fr-FR"}
""")
}

@MainActor
func testLogout() async throws {
let componentManager = componentManagerAssertingOnFetch()

let webView = ConnectComponentWebView(componentManager: componentManager,
componentType: .payouts,
webLocale: Locale(identifier: "fr_FR"),
loadContent: false)

let expectation = try webView.expectationForMessageReceived(sender: LogoutSender())
componentManager.logout()
await fulfillment(of: [expectation], timeout: TestHelpers.defaultTimeout)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// LogoutSenderTests.swift
// StripeConnectTests
//
// Created by Mel Ludowise on 9/24/24.
//

@testable import StripeConnect
import XCTest

class LogoutSenderTests: ScriptWebTestBase {
func testSendMessage() throws {
try validateMessageSent(sender: LogoutSender())
}

func testSenderSignature() {
XCTAssertEqual(
LogoutSender().javascriptMessage,
"""
window.logout({});
"""
)
}
}

0 comments on commit 737a3a9

Please sign in to comment.