diff --git a/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj b/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj index 48d9063fbe4..11723ed773a 100644 --- a/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj +++ b/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj @@ -89,6 +89,7 @@ D8D7BB4E27501B9400044146 /* SpanObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8D7BB4D27501B9400044146 /* SpanObserver.swift */; }; D8DBDA76274D591F00007380 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8DBDA75274D591F00007380 /* TableViewController.swift */; }; D8DBDA78274D5FC400007380 /* SplitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8DBDA77274D5FC400007380 /* SplitViewController.swift */; }; + D8F01DEA2A1376B5008F4996 /* InfoForBreadcrumbController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F01DE92A1376B5008F4996 /* InfoForBreadcrumbController.swift */; }; D8F3D052274E572F00B56F8C /* DSNStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F3D04F274E572F00B56F8C /* DSNStorage.swift */; }; D8F3D053274E572F00B56F8C /* DSNStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F3D04F274E572F00B56F8C /* DSNStorage.swift */; }; D8F3D054274E572F00B56F8C /* RandomErrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F3D051274E572F00B56F8C /* RandomErrors.swift */; }; @@ -332,6 +333,8 @@ D8D7BB4D27501B9400044146 /* SpanObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpanObserver.swift; sourceTree = ""; }; D8DBDA75274D591F00007380 /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; D8DBDA77274D5FC400007380 /* SplitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitViewController.swift; sourceTree = ""; }; + D8F01DE92A1376B5008F4996 /* InfoForBreadcrumbController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoForBreadcrumbController.swift; sourceTree = ""; }; + D8F01DF02A1377D0008F4996 /* SentryExposure.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryExposure.h; sourceTree = ""; }; D8F3D04F274E572F00B56F8C /* DSNStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DSNStorage.swift; sourceTree = ""; }; D8F3D051274E572F00B56F8C /* RandomErrors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RandomErrors.swift; sourceTree = ""; }; D8F3D056274E574200B56F8C /* LoremIpsumViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoremIpsumViewController.swift; sourceTree = ""; }; @@ -544,6 +547,7 @@ 84FB811F283EEDB900F3A94A /* PerformanceViewController.swift */, 0AABE2E928855FF80057ED69 /* PermissionsViewController.swift */, D8C33E1E29FBB1F70071B75A /* UIEventBreadcrumbsController.swift */, + D8F01DE92A1376B5008F4996 /* InfoForBreadcrumbController.swift */, ); path = ViewControllers; sourceTree = ""; @@ -560,6 +564,7 @@ D8D7BB4D27501B9400044146 /* SpanObserver.swift */, 84FB812C2840021B00F3A94A /* iOS-Swift-Bridging-Header.h */, 7B5525B22938B5B5006A2932 /* DiskWriteException.swift */, + D8F01DF02A1377D0008F4996 /* SentryExposure.h */, ); path = Tools; sourceTree = ""; @@ -885,6 +890,7 @@ 637AFDAA243B02760034958B /* AppDelegate.swift in Sources */, D8F57BC527BBD787000D09D4 /* CoreDataViewController.swift in Sources */, D8D7BB4E27501B9400044146 /* SpanObserver.swift in Sources */, + D8F01DEA2A1376B5008F4996 /* InfoForBreadcrumbController.swift in Sources */, D8DBDA76274D591F00007380 /* TableViewController.swift in Sources */, D8C33E1F29FBB1F70071B75A /* UIEventBreadcrumbsController.swift in Sources */, 8E8C57AF25EF16E6001CEEFA /* TraceTestViewController.swift in Sources */, diff --git a/Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard b/Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard index 83e7383e9f7..f96c14a2d76 100644 --- a/Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard +++ b/Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard @@ -223,6 +223,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -508,7 +555,7 @@ + diff --git a/Samples/iOS-Swift/iOS-Swift/Tools/SentryExposure.h b/Samples/iOS-Swift/iOS-Swift/Tools/SentryExposure.h new file mode 100644 index 00000000000..dc681526390 --- /dev/null +++ b/Samples/iOS-Swift/iOS-Swift/Tools/SentryExposure.h @@ -0,0 +1,8 @@ +#import +#import + +@interface SentryBreadcrumbTracker : NSObject + ++ (NSDictionary *)extractDataFromView:(UIView *)view; + +@end diff --git a/Samples/iOS-Swift/iOS-Swift/Tools/iOS-Swift-Bridging-Header.h b/Samples/iOS-Swift/iOS-Swift/Tools/iOS-Swift-Bridging-Header.h index 44fe01477e4..13155ce93ac 100644 --- a/Samples/iOS-Swift/iOS-Swift/Tools/iOS-Swift-Bridging-Header.h +++ b/Samples/iOS-Swift/iOS-Swift/Tools/iOS-Swift-Bridging-Header.h @@ -1,2 +1,3 @@ #import "SentryBenchmarking.h" +#import "SentryExposure.h" #import diff --git a/Samples/iOS-Swift/iOS-Swift/ViewControllers/InfoForBreadcrumbController.swift b/Samples/iOS-Swift/iOS-Swift/ViewControllers/InfoForBreadcrumbController.swift new file mode 100644 index 00000000000..334de2f1bb1 --- /dev/null +++ b/Samples/iOS-Swift/iOS-Swift/ViewControllers/InfoForBreadcrumbController.swift @@ -0,0 +1,29 @@ +import Foundation +import Sentry +import UIKit + +class InfoForBreadcrumbController: UIViewController { + + @IBOutlet var button: UIButton! + @IBOutlet var label: UILabel! + + @IBAction func buttonPressed(_ sender: Any) { + guard let view = self.view, + let viewInfo = SentryBreadcrumbTracker.extractData(from: view), + let buttonInfo = SentryBreadcrumbTracker.extractData(from: button) + else { + label?.text = "ERROR" + return + } + + let hasCorrectData = String(describing: view) == viewInfo["view"] as? String && + viewInfo["tag"] == nil && + viewInfo["accessibilityIdentifier"] as? String == "SOME IDENTIFIER" && + viewInfo["title"] == nil && + buttonInfo["tag"] as? Int == 1 && + buttonInfo["accessibilityIdentifier"] as? String == "extractInfoButton" && + buttonInfo["title"] as? String == button.title(for: .normal) + + label?.text = hasCorrectData ? [viewInfo, buttonInfo].debugDescription : "ERROR" + } +} diff --git a/Samples/iOS-Swift/iOS-SwiftUITests/UIEventBreadcrumbTests.swift b/Samples/iOS-Swift/iOS-SwiftUITests/UIEventBreadcrumbTests.swift index db5a14a7069..5558b04757b 100644 --- a/Samples/iOS-Swift/iOS-SwiftUITests/UIEventBreadcrumbTests.swift +++ b/Samples/iOS-Swift/iOS-SwiftUITests/UIEventBreadcrumbTests.swift @@ -34,6 +34,17 @@ class UIEventBreadcrumbTests: XCTestCase { app.staticTexts["textFieldEndChanging:"].waitForExistence("textFieldEndChanging: not called") } + func testExtractInfoFromView() { + app.buttons["Extra"].tap() + app.buttons["breadcrumbInfoButton"].tap() + app.buttons["extractInfoButton"].waitForExistence("Extract Info Button not found") + app.buttons["extractInfoButton"].tap() + + let info = app.staticTexts["infoLabel"].label + + XCTAssertNotEqual(info, "ERROR") + } + func waitForExistenceOfMainScreen() { app.waitForExistence( "Home Screen doesn't exist.") } diff --git a/Tests/SentryTests/Integrations/Breadcrumbs/SentryBreadcrumbTrackerTests.swift b/Tests/SentryTests/Integrations/Breadcrumbs/SentryBreadcrumbTrackerTests.swift index 95e55d31e18..655c14aba69 100644 --- a/Tests/SentryTests/Integrations/Breadcrumbs/SentryBreadcrumbTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Breadcrumbs/SentryBreadcrumbTrackerTests.swift @@ -60,48 +60,6 @@ class SentryBreadcrumbTrackerTests: XCTestCase { clearTestState() } - - func testExtractDataFrom_View() { - let view = UIView() - let result = Dynamic(SentryBreadcrumbTracker.self).extractDataFromView(view) as [String: Any?]? - - XCTAssertEqual(result?["view"] as? String, String(describing: view)) - XCTAssertNil(result?["title"] as Any?) - XCTAssertNil(result?["tag"] as Any?) - XCTAssertNil(result?["accessibilityIdentifier"] as Any?) - } - - func testExtractDataFrom_ViewWith_Tag_accessibilityIdentifier() { - let view = UIView() - view.tag = 2 - view.accessibilityIdentifier = "SOME IDENTIFIER" - - let result = Dynamic(SentryBreadcrumbTracker.self).extractDataFromView(view) as [String: Any?]? - - XCTAssertEqual(result?["view"] as? String, String(describing: view)) - XCTAssertEqual(result?["tag"] as? Int, 2) - XCTAssertEqual(result?["accessibilityIdentifier"] as? String, "SOME IDENTIFIER") - XCTAssertNil(result?["title"] as Any?) - } - - func testExtractDataFrom_ButtonWith_Title() { - let view = UIButton() - view.setTitle("BUTTON TITLE", for: .normal) - - let result = Dynamic(SentryBreadcrumbTracker.self).extractDataFromView(view) as [String: Any?]? - - XCTAssertEqual(result?["view"] as? String, String(describing: view)) - XCTAssertEqual(result?["title"] as? String, "BUTTON TITLE") - } - - func testExtractDataFrom_ButtonWithout_Title() { - let view = UIButton() - - let result = Dynamic(SentryBreadcrumbTracker.self).extractDataFromView(view) as [String: Any?]? - - XCTAssertEqual(result?["view"] as? String, String(describing: view)) - XCTAssertNil(result?["title"] as Any?) - } #endif }