Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- Tag all spans with thread info on non-web platforms ([#3101](https://github.com/getsentry/sentry-dart/pull/3101), [#3144](https://github.com/getsentry/sentry-dart/pull/3144))
- feat(feedback): Add option to disable keyboard resize ([#3154](https://github.com/getsentry/sentry-dart/pull/3154))

### Fixes

- Implement prefill logic in `SentryFeedbackWidget` for `useSentryUser` parameter to populate fields with current user data ([#3180](https://github.com/getsentry/sentry-dart/pull/3180))

### Enhancements

- Add `DioException` response data to error breadcrumb ([#3164](https://github.com/getsentry/sentry-dart/pull/3164))
Expand Down
25 changes: 25 additions & 0 deletions packages/flutter/lib/src/feedback/sentry_feedback_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class _SentryFeedbackWidgetState extends State<SentryFeedbackWidget> {
void initState() {
super.initState();

if(widget.options.useSentryUser) {
_setSentryUserData();
}
_restorePreservedData();
_captureReplay();

Expand Down Expand Up @@ -407,6 +410,28 @@ class _SentryFeedbackWidgetState extends State<SentryFeedbackWidget> {
}
}

SentryUser? _getUser() {
SentryUser? user;
widget._hub.configureScope((scope) {
user = scope.user;
});
return user;
}

void _setSentryUserData() {
final user = _getUser();
if(user == null) return;

final userName = user.name;
if(userName != null) {
_nameController.text = userName;
}
final userEmail = user.email;
if(userEmail != null) {
_emailController.text = userEmail;
}
}

void _restorePreservedData() {
final preservedName = SentryFeedbackWidget.preservedName;
if (preservedName != null) {
Expand Down
73 changes: 67 additions & 6 deletions packages/flutter/test/feedback/sentry_feedback_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ void main() {
final mockBinding = MockSentryNativeBinding();
when(mockBinding.supportsReplay).thenReturn(true);
when(fixture.hub.scope).thenReturn(fixture.scope);
when(fixture.hub.configureScope(any)).thenAnswer((invocation) {
final callback = invocation.positionalArguments.first;
callback(fixture.scope);
return null;
});

final replayId = SentryId.fromId('1988bb1b6f0d4c509e232f0cb9aaeaea');
when(mockBinding.captureReplay()).thenAnswer((_) async => replayId);

Expand Down Expand Up @@ -228,6 +224,59 @@ void main() {
});
});

group('$SentryFeedbackWidget prefills fields from sentryUser', () {
late Fixture fixture;

setUp(() {
fixture = Fixture();
});

testWidgets('prefills form data if useSentryUser is true', (tester) async {
fixture.options.feedback.useSentryUser = true;
fixture.hub.configureScope((scope) {
scope.setUser(fixture.sentryUser);
});

await fixture.pumpFeedbackWidget(
tester,
(hub) => SentryFeedbackWidget(hub: hub),
);

final nameField = tester.widget<TextFormField>(
find.byKey(ValueKey('sentry_feedback_name_textfield')),
);
final emailField = tester.widget<TextFormField>(
find.byKey(ValueKey('sentry_feedback_email_textfield')),
);

expect(nameField.controller?.text, "fixture-name");
expect(emailField.controller?.text, "[email protected]");
});

testWidgets('does not prefill form data if useSentryUser is false', (tester) async {
fixture.options.feedback.useSentryUser = false;
fixture.hub.configureScope((scope) {
scope.setUser(fixture.sentryUser);
});

await fixture.pumpFeedbackWidget(
tester,
(hub) => SentryFeedbackWidget(hub: hub),
);

final nameField = tester.widget<TextFormField>(
find.byKey(ValueKey('sentry_feedback_name_textfield')),
);
final emailField = tester.widget<TextFormField>(
find.byKey(ValueKey('sentry_feedback_email_textfield')),
);

expect(nameField.controller?.text, isEmpty);
expect(emailField.controller?.text, isEmpty);
});

});

group('$SentryFeedbackWidget uses naming from options', () {
late Fixture fixture;

Expand Down Expand Up @@ -759,6 +808,7 @@ class Fixture {
var options = SentryFlutterOptions();
var hub = MockHub();
late var scope = Scope(options);
late SentryUser sentryUser;

Fixture() {
when(hub.options).thenReturn(options);
Expand All @@ -768,9 +818,20 @@ class Fixture {
hint: anyNamed('hint'),
withScope: anyNamed('withScope'),
)).thenAnswer((_) async => SentryId.empty());

when(hub.configureScope(any)).thenAnswer((invocation) {
final callback = invocation.positionalArguments.first;
callback(scope);
return null;
});
SentryFeedbackWidget.pendingAssociatedEventId = null;
SentryFeedbackWidget.clearPreservedData();

sentryUser = SentryUser(
id: 'fixture-id',
username: 'fixture-username',
name: 'fixture-name',
email: '[email protected]',
);
}

Future<void> pumpFeedbackWidget(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ void main() {
options.navigatorKey = navigatorKey;

var hub = mocks.MockHub();
late var scope = Scope(options);

when(hub.options).thenReturn(options);
when(hub.configureScope(any)).thenAnswer((invocation) {
final callback = invocation.positionalArguments.first;
callback(scope);
return null;
});

await tester.pumpWidget(
MaterialApp(
Expand Down
Loading