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

SentryUserInteractionWidget: add support for PopupMenuButton and PopupMenuItem #1361

Merged
merged 5 commits into from
Mar 28, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- SentryUserInteractionWidget: add support for PopupMenuButton and PopupMenuItem ([#1361](https://github.com/getsentry/sentry-dart/pull/1361))

### Fixes

- Fix `SentryUserInteractionWidget` throwing when Sentry is not enabled ([#1363](https://github.com/getsentry/sentry-dart/pull/1363))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ Element? _clickTrackerElement;
///
/// It's supported by the most common [Widget], for example:
/// [ButtonStyleButton], [MaterialButton], [CupertinoButton], [InkWell],
/// and [IconButton].
/// [IconButton], [PopupMenuButton] and [PopupMenuItem].
/// Mostly for onPressed, onTap, and onLongPress events
///
/// Example on how to set up:
Expand Down Expand Up @@ -542,6 +542,24 @@ class _SentryUserInteractionWidgetState
eventType: 'onPressed',
);
}
} else if (widget is PopupMenuButton) {
if (widget.enabled) {
return UserInteractionWidget(
element: element,
description: _findDescriptionOf(element, false),
type: 'PopupMenuButton',
eventType: 'onTap',
);
}
} else if (widget is PopupMenuItem) {
if (widget.enabled) {
return UserInteractionWidget(
element: element,
description: _findDescriptionOf(element, false),
type: 'PopupMenuItem',
eventType: 'onTap',
);
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,42 @@ void main() {
expect(crumb?.data?['label'], 'Button 5');
});
});

testWidgets('Add crumb for PopupMenuButton', (tester) async {
await tester.runAsync(() async {
final sut = fixture.getSut();

await tapMe(tester, sut, 'popup_menu_button');

Breadcrumb? crumb;
fixture.hub.configureScope((scope) {
crumb = scope.breadcrumbs.last;
});
expect(crumb?.category, 'ui.click');
expect(crumb?.data?['view.id'], 'popup_menu_button');
expect(crumb?.data?['view.class'], 'PopupMenuButton');
});
});

testWidgets('Add crumb for PopupMenuItem', (tester) async {
await tester.runAsync(() async {
final sut = fixture.getSut();

// open the popup menu and wait for the animation to complete
await tapMe(tester, sut, 'popup_menu_button');
await tester.pumpAndSettle();

await tapMe(tester, sut, 'popup_menu_item_1');

Breadcrumb? crumb;
fixture.hub.configureScope((scope) {
crumb = scope.breadcrumbs.last;
});
expect(crumb?.category, 'ui.click');
expect(crumb?.data?['view.id'], 'popup_menu_item_1');
expect(crumb?.data?['view.class'], 'PopupMenuItem');
});
});
});

group('$SentryUserInteractionWidget performance', () {
Expand Down Expand Up @@ -363,6 +399,15 @@ class Page1 extends StatelessWidget {
},
child: const Text('Go to page 2'),
),
PopupMenuButton(
key: ValueKey('popup_menu_button'),
itemBuilder: (_) => [
PopupMenuItem<void>(
key: ValueKey('popup_menu_item_1'),
child: Text('first item'),
),
],
),
],
),
),
Expand Down