Skip to content

Commit 2ab4058

Browse files
authored
test: more override config (#5201)
1 parent a88b320 commit 2ab4058

File tree

11 files changed

+371
-296
lines changed

11 files changed

+371
-296
lines changed
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if !os(macOS) && !os(tvOS) && !os(watchOS)
1+
#if !os(macOS) && !os(tvOS) && !os(watchOS) && !os(visionOS)
22
import UIKit
33

44
class EnvironmentVariableTableViewCell: UITableViewCell, UITextFieldDelegate {
@@ -10,7 +10,6 @@ class EnvironmentVariableTableViewCell: UITableViewCell, UITextFieldDelegate {
1010
return field
1111
}()
1212

13-
var float: Bool = false
1413
var override: (any SentrySDKOverride)?
1514

1615
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
@@ -27,30 +26,31 @@ class EnvironmentVariableTableViewCell: UITableViewCell, UITextFieldDelegate {
2726
fatalError("init(coder:) has not been implemented")
2827
}
2928

30-
func configure(with override: any SentrySDKOverride, float: Bool) {
31-
titleLabel.text = override.rawValue as? String
29+
func textFieldDidEndEditing(_ textField: UITextField) {
30+
if override?.overrideType == .float {
31+
override?.floatValue = textField.text.flatMap { Float($0) }
32+
} else {
33+
override?.stringValue = textField.text
34+
}
35+
SentrySDKWrapper.shared.startSentry()
36+
}
37+
}
38+
39+
extension EnvironmentVariableTableViewCell: FeatureFlagCell {
40+
func configure(with override: any SentrySDKOverride) {
41+
titleLabel.text = override.rawValue
3242

3343
var text: String
34-
if let value = override.floatValue {
44+
if override.overrideType == .float, let value = override.floatValue {
3545
text = String(format: "%.2f", value)
36-
} else if let value = override.stringValue {
46+
} else if override.overrideType == .string, let value = override.stringValue {
3747
text = value
3848
} else {
3949
text = "nil"
4050
}
4151
valueField.text = text
4252

43-
self.float = float
4453
self.override = override
4554
}
46-
47-
func textFieldDidEndEditing(_ textField: UITextField) {
48-
if self.float {
49-
override?.floatValue = textField.text.flatMap { Float($0) }
50-
} else {
51-
override?.stringValue = textField.text
52-
}
53-
SentrySDKWrapper.shared.startSentry()
54-
}
5555
}
56-
#endif // !os(macOS) && !os(tvOS) && !os(watchOS)
56+
#endif // !os(macOS) && !os(tvOS) && !os(watchOS) && !os(visionOS)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#if !os(macOS) && !os(tvOS) && !os(watchOS) && !os(visionOS)
2+
3+
import UIKit
4+
5+
protocol FeatureFlagCell: UITableViewCell {
6+
func configure(with override: any SentrySDKOverride)
7+
}
8+
9+
#endif // !os(macOS) && !os(tvOS) && !os(watchOS) && !os(visionOS)

Samples/SentrySampleShared/SentrySampleShared/FeaturesViewController.swift

Lines changed: 16 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#if !os(macOS) && !os(tvOS) && !os(watchOS) && !os(visionOS)
2+
23
import UIKit
34

45
public class FeaturesViewController: UIViewController {
@@ -45,90 +46,38 @@ public class FeaturesViewController: UIViewController {
4546

4647
@objc func resetDefaults() {
4748
SentrySDKOverrides.resetDefaults()
49+
SentrySDKWrapper.shared.startSentry()
4850
tableView.reloadData()
4951
}
5052
}
5153

5254
extension FeaturesViewController: UITableViewDataSource {
5355
public func numberOfSections(in tableView: UITableView) -> Int {
54-
6
56+
SentrySDKOverrides.allCases.count
5557
}
5658

5759
public func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
58-
if section == 0 {
59-
return "Special"
60-
} else if section == 1 {
61-
return "Performance"
62-
} else if section == 2 {
63-
return "Tracing"
64-
} else if section == 3 {
65-
return "Profiling"
66-
} else if section == 4 {
67-
return "Feedback"
68-
} else if section == 5 {
69-
return "Other"
70-
}
71-
return nil
60+
SentrySDKOverrides.allCases[section].rawValue
7261
}
7362

7463
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
75-
if section == 0 {
76-
return SentrySDKOverrides.Special.allCases.count
77-
} else if section == 1 {
78-
return SentrySDKOverrides.Performance.allCases.count
79-
} else if section == 2 {
80-
return SentrySDKOverrides.Tracing.allCases.count
81-
} else if section == 3 {
82-
return SentrySDKOverrides.Profiling.allCases.count
83-
} else if section == 4 {
84-
return SentrySDKOverrides.Feedback.allCases.count
85-
} else if section == 5 {
86-
return SentrySDKOverrides.Other.allCases.count
87-
}
88-
return 0
64+
SentrySDKOverrides.allCases[section].featureFlags.count
8965
}
9066

9167
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
92-
if indexPath.section == 2 {
93-
if SentrySDKOverrides.Tracing.boolValues.contains(SentrySDKOverrides.Tracing.allCases[indexPath.row]) {
94-
let cell = tableView.dequeueReusableCell(withIdentifier: "launchArgumentCell", for: indexPath) as! LaunchArgumentTableViewCell
95-
cell.configure(with: SentrySDKOverrides.Tracing.allCases[indexPath.row])
96-
return cell
97-
} else {
98-
let cell = tableView.dequeueReusableCell(withIdentifier: "environmentVariableCell", for: indexPath) as! EnvironmentVariableTableViewCell
99-
cell.configure(with: SentrySDKOverrides.Tracing.allCases[indexPath.row], float: true)
100-
return cell
101-
}
102-
} else if indexPath.section == 3 {
103-
if SentrySDKOverrides.Profiling.boolValues.contains(SentrySDKOverrides.Profiling.allCases[indexPath.row]) {
104-
let cell = tableView.dequeueReusableCell(withIdentifier: "launchArgumentCell", for: indexPath) as! LaunchArgumentTableViewCell
105-
cell.configure(with: SentrySDKOverrides.Profiling.allCases[indexPath.row])
106-
return cell
107-
} else {
108-
let cell = tableView.dequeueReusableCell(withIdentifier: "environmentVariableCell", for: indexPath) as! EnvironmentVariableTableViewCell
109-
cell.configure(with: SentrySDKOverrides.Profiling.allCases[indexPath.row], float: true)
110-
return cell
111-
}
112-
} else if indexPath.section == 5 {
113-
if SentrySDKOverrides.Other.boolValues.contains(SentrySDKOverrides.Other.allCases[indexPath.row]) {
114-
let cell = tableView.dequeueReusableCell(withIdentifier: "launchArgumentCell", for: indexPath) as! LaunchArgumentTableViewCell
115-
cell.configure(with: SentrySDKOverrides.Other.allCases[indexPath.row])
116-
return cell
117-
} else {
118-
let cell = tableView.dequeueReusableCell(withIdentifier: "environmentVariableCell", for: indexPath) as! EnvironmentVariableTableViewCell
119-
cell.configure(with: SentrySDKOverrides.Other.allCases[indexPath.row], float: false)
120-
return cell
121-
}
68+
let featureType = SentrySDKOverrides.allCases[indexPath.section]
69+
let featureFlag = featureType.featureFlags[indexPath.row]
70+
71+
let reuseIdentifier: String
72+
switch featureFlag.overrideType {
73+
case .boolean:
74+
reuseIdentifier = "launchArgumentCell"
75+
case .float, .string:
76+
reuseIdentifier = "environmentVariableCell"
12277
}
12378

124-
let cell = tableView.dequeueReusableCell(withIdentifier: "launchArgumentCell", for: indexPath) as! LaunchArgumentTableViewCell
125-
if indexPath.section == 0 {
126-
cell.configure(with: SentrySDKOverrides.Special.allCases[indexPath.row])
127-
} else if indexPath.section == 1 {
128-
cell.configure(with: SentrySDKOverrides.Performance.allCases[indexPath.row])
129-
} else if indexPath.section == 4 {
130-
cell.configure(with: SentrySDKOverrides.Feedback.allCases[indexPath.row])
131-
}
79+
let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath) as! FeatureFlagCell
80+
cell.configure(with: featureFlag)
13281
return cell
13382
}
13483
}

Samples/SentrySampleShared/SentrySampleShared/LaunchArgumentTableViewCell.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if !os(macOS) && !os(tvOS) && !os(watchOS)
1+
#if !os(macOS) && !os(tvOS) && !os(watchOS) && !os(visionOS)
22
import UIKit
33

44
class LaunchArgumentTableViewCell: UITableViewCell {
@@ -26,11 +26,13 @@ class LaunchArgumentTableViewCell: UITableViewCell {
2626
required init?(coder: NSCoder) {
2727
fatalError("init(coder:) has not been implemented")
2828
}
29+
}
2930

31+
extension LaunchArgumentTableViewCell: FeatureFlagCell {
3032
func configure(with override: any SentrySDKOverride) {
31-
titleLabel.text = override.rawValue as? String
33+
titleLabel.text = override.rawValue
3234
flagSwitch.isOn = override.boolValue
3335
self.override = override
3436
}
3537
}
36-
#endif // !os(macOS) && !os(tvOS) && !os(watchOS)
38+
#endif // !os(macOS) && !os(tvOS) && !os(watchOS) && !os(visionOS)

Samples/SentrySampleShared/SentrySampleShared/SampleAppDebugMenu.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import UIKit
44
public class SampleAppDebugMenu: NSObject {
55
public static let shared = SampleAppDebugMenu()
66

7-
static var displayingForm = false
7+
static var displayingMenu = false
88

99
let window = {
1010
if #available(iOS 13.0, *) {
@@ -42,8 +42,11 @@ public class SampleAppDebugMenu: NSObject {
4242
}
4343

4444
@objc func displayDebugMenu() {
45-
SampleAppDebugMenu.displayingForm = true
46-
rootVC.present(FeaturesViewController(nibName: nil, bundle: nil), animated: true)
45+
SampleAppDebugMenu.displayingMenu = true
46+
47+
let listVC = FeaturesViewController(nibName: nil, bundle: nil)
48+
listVC.presentationController?.delegate = self
49+
rootVC.present(listVC, animated: true)
4750
}
4851

4952
class Window: UIWindow {
@@ -68,7 +71,7 @@ public class SampleAppDebugMenu: NSObject {
6871
}
6972

7073
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
71-
guard !SampleAppDebugMenu.displayingForm else {
74+
guard !SampleAppDebugMenu.displayingMenu else {
7275
return super.hitTest(point, with: event)
7376
}
7477

@@ -86,7 +89,7 @@ public class SampleAppDebugMenu: NSObject {
8689
extension SampleAppDebugMenu: UIAdaptivePresentationControllerDelegate {
8790
public func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
8891
rootVC.dismiss(animated: true)
89-
SampleAppDebugMenu.displayingForm = false
92+
SampleAppDebugMenu.displayingMenu = false
9093
}
9194
}
9295
#endif // !os(macOS) && !os(tvOS) && !os(watchOS) && !os(visionOS)

0 commit comments

Comments
 (0)