Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Move breadcrumb tests to UITest #3038

Merged
merged 2 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -332,6 +333,8 @@
D8D7BB4D27501B9400044146 /* SpanObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpanObserver.swift; sourceTree = "<group>"; };
D8DBDA75274D591F00007380 /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = "<group>"; };
D8DBDA77274D5FC400007380 /* SplitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitViewController.swift; sourceTree = "<group>"; };
D8F01DE92A1376B5008F4996 /* InfoForBreadcrumbController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoForBreadcrumbController.swift; sourceTree = "<group>"; };
D8F01DF02A1377D0008F4996 /* SentryExposure.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryExposure.h; sourceTree = "<group>"; };
D8F3D04F274E572F00B56F8C /* DSNStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DSNStorage.swift; sourceTree = "<group>"; };
D8F3D051274E572F00B56F8C /* RandomErrors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RandomErrors.swift; sourceTree = "<group>"; };
D8F3D056274E574200B56F8C /* LoremIpsumViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoremIpsumViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -544,6 +547,7 @@
84FB811F283EEDB900F3A94A /* PerformanceViewController.swift */,
0AABE2E928855FF80057ED69 /* PermissionsViewController.swift */,
D8C33E1E29FBB1F70071B75A /* UIEventBreadcrumbsController.swift */,
D8F01DE92A1376B5008F4996 /* InfoForBreadcrumbController.swift */,
);
path = ViewControllers;
sourceTree = "<group>";
Expand All @@ -560,6 +564,7 @@
D8D7BB4D27501B9400044146 /* SpanObserver.swift */,
84FB812C2840021B00F3A94A /* iOS-Swift-Bridging-Header.h */,
7B5525B22938B5B5006A2932 /* DiskWriteException.swift */,
D8F01DF02A1377D0008F4996 /* SentryExposure.h */,
);
path = Tools;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
65 changes: 61 additions & 4 deletions Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,53 @@
</objects>
<point key="canvasLocation" x="2726" y="-625"/>
</scene>
<!--Info For Breadcrumb Controller-->
<scene sceneID="arS-SB-tPi">
<objects>
<viewController id="baS-wm-UQo" customClass="InfoForBreadcrumbController" customModule="iOS_Swift" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="kuq-y5-xKM">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" tag="1" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Gz6-bT-PrL">
<rect key="frame" x="65" y="85" width="190" height="35"/>
<accessibility key="accessibilityConfiguration" identifier="extractInfoButton"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="Extract Info from view"/>
<connections>
<action selector="buttonPressed:" destination="baS-wm-UQo" eventType="touchUpInside" id="PXn-G1-6hu"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="j1U-nc-cGt">
<rect key="frame" x="16" y="316" width="288" height="0.0"/>
<accessibility key="accessibilityConfiguration" identifier="infoLabel"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<viewLayoutGuide key="safeArea" id="ddq-ee-7Ns"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<accessibility key="accessibilityConfiguration" identifier="SOME IDENTIFIER"/>
<constraints>
<constraint firstItem="j1U-nc-cGt" firstAttribute="centerY" secondItem="ddq-ee-7Ns" secondAttribute="centerY" id="82P-hx-kSu"/>
<constraint firstItem="j1U-nc-cGt" firstAttribute="centerX" secondItem="ddq-ee-7Ns" secondAttribute="centerX" id="Wfx-cx-GyP"/>
<constraint firstItem="ddq-ee-7Ns" firstAttribute="trailing" secondItem="j1U-nc-cGt" secondAttribute="trailing" constant="16" id="lNx-HO-514"/>
<constraint firstItem="j1U-nc-cGt" firstAttribute="leading" secondItem="ddq-ee-7Ns" secondAttribute="leading" constant="16" id="qpD-rY-i4q"/>
<constraint firstItem="Gz6-bT-PrL" firstAttribute="top" secondItem="ddq-ee-7Ns" secondAttribute="top" constant="21" id="tIx-31-b6h"/>
<constraint firstItem="Gz6-bT-PrL" firstAttribute="centerX" secondItem="ddq-ee-7Ns" secondAttribute="centerX" id="ufo-QO-Dwx"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="HVa-fh-O6F"/>
<connections>
<outlet property="button" destination="Gz6-bT-PrL" id="ZR6-lQ-Uj5"/>
<outlet property="label" destination="j1U-nc-cGt" id="xgx-T0-PVu"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="CJw-J7-n7w" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="995.625" y="-1275"/>
</scene>
<!--Split View Controller-->
<scene sceneID="6Nq-cD-DlA">
<objects>
Expand Down Expand Up @@ -508,38 +555,48 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ckT-1E-GWZ">
<rect key="frame" x="0.0" y="42" width="152" height="28"/>
<rect key="frame" x="0.0" y="33.5" width="152" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="Close SDK"/>
<connections>
<action selector="close:" destination="VqS-l1-kwe" eventType="touchUpInside" id="UwB-2M-pCr"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="rpD-Rf-xbz">
<rect key="frame" x="0.0" y="84" width="152" height="28"/>
<rect key="frame" x="0.0" y="67" width="152" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="ANR fully blocking"/>
<connections>
<action selector="anrFullyBlocking:" destination="VqS-l1-kwe" eventType="touchUpInside" id="PLh-oH-8oF"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="2e4-48-rLl">
<rect key="frame" x="0.0" y="126" width="152" height="28"/>
<rect key="frame" x="0.0" y="101" width="152" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="ANR filling run loop"/>
<connections>
<action selector="anrFillingRunLoop:" destination="VqS-l1-kwe" eventType="touchUpInside" id="ON6-DV-3Tz"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="F0l-xf-cQd">
<rect key="frame" x="0.0" y="168" width="152" height="28"/>
<rect key="frame" x="0.0" y="134.5" width="152" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" title="Start 100 threads"/>
<connections>
<action selector="start100Threads:" destination="VqS-l1-kwe" eventType="touchUpInside" id="9KO-KS-85G"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Evt-B9-zEC">
<rect key="frame" x="0.0" y="168" width="152" height="28"/>
<accessibility key="accessibilityConfiguration" identifier="breadcrumbInfoButton"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" title="Breadcrumb info test"/>
<connections>
<segue destination="baS-wm-UQo" kind="show" id="P5B-LG-XhB"/>
</connections>
</button>
</subviews>
</stackView>
</subviews>
Expand Down
8 changes: 8 additions & 0 deletions Samples/iOS-Swift/iOS-Swift/Tools/SentryExposure.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface SentryBreadcrumbTracker : NSObject

+ (NSDictionary *)extractDataFromView:(UIView *)view;

@end
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#import "SentryBenchmarking.h"
#import "SentryExposure.h"
#import <Sentry/PrivateSentrySDKOnly.h>
Original file line number Diff line number Diff line change
@@ -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"
}
}
11 changes: 11 additions & 0 deletions Samples/iOS-Swift/iOS-SwiftUITests/UIEventBreadcrumbTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

}