From 97ab95466ededebe2ce5e4725b0d20e83ea03b1c Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 12 Dec 2024 11:40:41 -0900 Subject: [PATCH 1/5] prefill user info --- .../xcshareddata/xcschemes/iOS-Swift.xcscheme | 4 ++++ Samples/iOS-Swift/iOS-Swift/AppDelegate.swift | 1 + .../UserFeedback/SentryUserFeedbackForm.swift | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme b/Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme index 75721f0cd2a..ee025e48e4e 100644 --- a/Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme +++ b/Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme @@ -73,6 +73,10 @@ argument = "--disable-file-io-tracing" isEnabled = "NO"> + + diff --git a/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift b/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift index 523bdd81d85..bac656e65ff 100644 --- a/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift +++ b/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift @@ -174,6 +174,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { return } config.animations = !args.contains("--io.sentry.feedback.no-animations") + config.useSentryUser = args.contains("--io.sentry.feedback.use-sentry-user") config.useShakeGesture = true config.showFormForScreenshots = true config.configureWidget = { widget in diff --git a/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift b/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift index b49555afcef..cde3ee3de82 100644 --- a/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift +++ b/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift @@ -261,6 +261,10 @@ class SentryUserFeedbackForm: UIViewController { field.accessibilityLabel = config.formConfig.nameTextFieldAccessibilityLabel field.accessibilityIdentifier = "io.sentry.feedback.form.name" field.delegate = self + field.autocapitalizationType = .words + if config.useSentryUser { + field.text = SentrySDK.currentHub().scope.userObject?.name + } return field }() @@ -277,6 +281,10 @@ class SentryUserFeedbackForm: UIViewController { field.accessibilityIdentifier = "io.sentry.feedback.form.email" field.delegate = self field.keyboardType = .emailAddress + field.autocapitalizationType = .none + if config.useSentryUser { + field.text = SentrySDK.currentHub().scope.userObject?.email + } return field }() From 8a9fe4909bca74db249d6f39d9a578822acec227 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 12 Dec 2024 12:27:17 -0900 Subject: [PATCH 2/5] fix build and add ui test --- .../iOS-Swift-UITests/UserFeedbackUITests.swift | 13 +++++++++++++ .../xcshareddata/xcschemes/iOS-Swift.xcscheme | 9 +++++++++ Samples/iOS-Swift/iOS-Swift/AppDelegate.swift | 1 + Sources/Sentry/include/SentryPrivate.h | 2 ++ 4 files changed, 25 insertions(+) diff --git a/Samples/iOS-Swift/iOS-Swift-UITests/UserFeedbackUITests.swift b/Samples/iOS-Swift/iOS-Swift-UITests/UserFeedbackUITests.swift index 4ca524f2ee9..bd8cf37ae3a 100644 --- a/Samples/iOS-Swift/iOS-Swift-UITests/UserFeedbackUITests.swift +++ b/Samples/iOS-Swift/iOS-Swift-UITests/UserFeedbackUITests.swift @@ -54,7 +54,9 @@ class UserFeedbackUITests: BaseUITest { // Input field placeholders XCTAssertEqual(try XCTUnwrap(nameField.placeholderValue), "Your Name") + XCTAssertNil(nameField.value) XCTAssertEqual(try XCTUnwrap(emailField.placeholderValue), "your.email@example.org") + XCTAssertNil(emailField.value) XCTAssert(app.staticTexts["What's the bug? What did you expect?"].exists) // Input field labels @@ -97,6 +99,17 @@ class UserFeedbackUITests: BaseUITest { XCTAssertFalse(app.staticTexts["Thy name (Required)"].exists) } + func testPrefilledUserInformation() throws { + launchApp(args: ["--io.sentry.feedback.use-sentry-user"], env: [ + "--io.sentry.user.name": "ui test user", + "--io.sentry.user.email": "ui-testing@sentry.io" + ]) + + widgetButton.tap() + XCTAssertEqual(try XCTUnwrap(nameField.value as? String), "ui test user") + XCTAssertEqual(try XCTUnwrap(emailField.value as? String), "ui-testing@sentry.io") + } + // MARK: Tests validating happy path / successful submission func testSubmitFullyFilledForm() throws { diff --git a/Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme b/Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme index ee025e48e4e..a091d4c0abb 100644 --- a/Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme +++ b/Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme @@ -69,6 +69,10 @@ + + @@ -240,6 +244,11 @@ value = "" isEnabled = "NO"> + + Date: Thu, 12 Dec 2024 15:52:56 -0900 Subject: [PATCH 3/5] dont assert nil value bc it uses the placeholder string when empty --- Samples/iOS-Swift/iOS-Swift-UITests/UserFeedbackUITests.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Samples/iOS-Swift/iOS-Swift-UITests/UserFeedbackUITests.swift b/Samples/iOS-Swift/iOS-Swift-UITests/UserFeedbackUITests.swift index bd8cf37ae3a..a5f1eb50b69 100644 --- a/Samples/iOS-Swift/iOS-Swift-UITests/UserFeedbackUITests.swift +++ b/Samples/iOS-Swift/iOS-Swift-UITests/UserFeedbackUITests.swift @@ -54,9 +54,7 @@ class UserFeedbackUITests: BaseUITest { // Input field placeholders XCTAssertEqual(try XCTUnwrap(nameField.placeholderValue), "Your Name") - XCTAssertNil(nameField.value) XCTAssertEqual(try XCTUnwrap(emailField.placeholderValue), "your.email@example.org") - XCTAssertNil(emailField.value) XCTAssert(app.staticTexts["What's the bug? What did you expect?"].exists) // Input field labels From a2764d80ee5718b243ff35450b68f211e799cb93 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 12 Dec 2024 17:05:20 -0900 Subject: [PATCH 4/5] default user.name in addition to user.username --- Samples/iOS-Swift/iOS-Swift/AppDelegate.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift b/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift index c5d4c1a2cc6..3db52b6b001 100644 --- a/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift +++ b/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift @@ -152,9 +152,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { user.email = env["--io.sentry.user.email"] ?? "tony@example.com" // first check if the username has been overridden in the scheme for testing purposes; then try to use the system username so each person gets an automatic way to easily filter things on the dashboard; then fall back on a hardcoded value if none of these are present let username = env["--io.sentry.user.username"] ?? (env["SIMULATOR_HOST_HOME"] as? NSString)? - .lastPathComponent ?? "cocoa developer" + .lastPathComponent ?? "cocoadev" user.username = username - user.name = env["--io.sentry.user.name"] + user.name = env["--io.sentry.user.name"] ?? "cocoa developer" scope.setUser(user) if let path = Bundle.main.path(forResource: "Tongariro", ofType: "jpg") { From e04eaa3d9c4a8075c46cced920b8d8d695b8975b Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 12 Dec 2024 17:49:38 -0900 Subject: [PATCH 5/5] Update Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme --- .../xcshareddata/xcschemes/iOS-Swift.xcscheme | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme b/Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme index a091d4c0abb..090c3ca5e59 100644 --- a/Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme +++ b/Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme @@ -69,10 +69,6 @@ - -