Skip to content

Commit

Permalink
SentryUserInteractionWidget: add support for PopupMenuButton and Popu…
Browse files Browse the repository at this point in the history
…pMenuItem (#1361)

Co-authored-by: Manoel Aranda Neto <marandaneto@gmail.com>
Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 28, 2023
1 parent 8e133ad commit 0be962b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
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

0 comments on commit 0be962b

Please sign in to comment.