mirror of
https://github.com/block/buzz.git
synced 2026-11-27 19:52:31 +00:00
feat(mobile): add screen breadcrumbs to diagnostic reports
Adds screen breadcrumbs to mobile diagnostic reports, so a hang or error
report shows which screens the person was on before it happened. Today
the only breadcrumbs are foreground and background changes.
## Changes
- **Observers:** one `DiagnosticScreenTrail` is shared by an observer on
the root navigator and one on each conversation pane's nested navigator,
where channels, threads, search and activity open. A breadcrumb is left
on push, replace, and when a page is shown again after a pop, a frame
later and only for the page that ends up visible.
- **The screen the person is on:** a route that hosts a pane with a page
open past its first (a phone conversation over the channel list, or a
wide conversation beside it) is named by that page. So closing a
full-screen cover, such as a huddle, over an open channel records
`channel`, not `channelList`.
- **No repeats:** a screen equal to the last one is skipped. A pane host
and its pane's empty first page both name the host, and wide Settings
sections all show Settings, so these leave one crumb. The empty first
page still gives Home its crumb after sign-in.
- **Names come from a fixed list owned by the app:**
`lib/diagnostic_screens.dart` maps page widgets to names such as
`channelList`, `channel`, `thread`, `settings` or `addCommunity`, and
reaches the observers through `diagnosticScreenClassifierProvider`,
which the root scope overrides. Any other page is `other`. Route
settings and page content are never read, so no channel name, ID or text
can reach a breadcrumb.
- **Dialogs, sheets and menus are skipped:** popup routes leave nothing,
and the Duo channel sheet, which is a page route, opts out with
`DiagnosticSheetRoute`.
- **Filter:** adds a `navigation` category to the breadcrumb list. A
navigation breadcrumb leaves with only its screen name, and it is
dropped if that name isn't on the list.
- **No destination:** a build without a reporting destination does
nothing; the observers don't even inspect routes.
- **Spec:** the breadcrumb list, user story 7, and the out-of-scope line
about behavior data.
## Regressions
- **Architecture:** the screen list lives with the app, so `shared/`
gains no imports from features. The shared conversation pane's import
closure is unchanged from main.
- **Performance:** the route walk costs well under a millisecond per
navigation (28 to 155 µs measured, against 58 to 143 ms for the push
frame). Rebuild counts are unchanged with reporting on and off, and
nothing new goes over the network.
- **Confined to reporting builds:** in a build without a destination the
observers return before touching a route.
## Validation
New tests in
[`diagnostic_navigation_test.dart`](https://github.com/block/buzz/blob/tomb/mobile-diag-screen-breadcrumbs/mobile/test/shared/diagnostics/diagnostic_navigation_test.dart):
- the app's list, including `addCommunity` for adding a community and an
unlisted page;
- a root journey: a route whose settings carry an ID records only the
plain name, a dialog and a sheet route leave nothing, and two pops at
once leave only where they end;
- a phone journey with the real pane: Home once, channel, thread and
back, a cover closing back onto the open channel, closing the channel,
and a page with its own pane named once;
- a wide Settings pane where changing sections adds nothing;
- a build with no reporting destination.
Plus filter rows for nameless, unlisted and valid navigation
breadcrumbs.
Full-app run on an iOS simulator at 85a72de, signed in to a test
community: channel list, a channel and its details page, a message's
actions sheet, a thread and back, Search, Activity, Agents, Settings and
its status sheet, the identity-to-desktop confirmation, and the
community switcher's Add Community page. Every flow opened and closed
normally with no Flutter exceptions or error screens.
---------
Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
315 lines
9.9 KiB
Dart
315 lines
9.9 KiB
Dart
import 'package:buzz/diagnostic_screens.dart';
|
|
import 'package:buzz/features/pairing/pairing_page.dart';
|
|
import 'package:buzz/features/settings/theme_picker_page.dart';
|
|
import 'package:buzz/onboarding_app_entry.dart';
|
|
import 'package:buzz/shared/diagnostics/diagnostic_navigation_observer.dart';
|
|
import 'package:buzz/shared/diagnostics/diagnostic_reporter.dart';
|
|
import 'package:buzz/shared/widgets/adaptive_conversation_pane.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
void main() {
|
|
group('the screen a page is named', () {
|
|
final rows = <(Widget, DiagnosticScreen?)>[
|
|
(const ThemePickerPage(), DiagnosticScreen.appearance),
|
|
(const OnboardingAppEntry(), DiagnosticScreen.onboarding),
|
|
(
|
|
const OnboardingAppEntry(addingCommunity: true),
|
|
DiagnosticScreen.addCommunity,
|
|
),
|
|
(const PairingPage(addingCommunity: true), DiagnosticScreen.addCommunity),
|
|
// Send to Desktop recovers an identity; it adds no community.
|
|
(
|
|
const PairingPage(addingCommunity: true, identityRecoveryOnly: true),
|
|
DiagnosticScreen.onboarding,
|
|
),
|
|
// Not on the list: never named by its own type.
|
|
(const Text('unlisted'), null),
|
|
];
|
|
for (final (page, screen) in rows) {
|
|
test('$screen for $page', () {
|
|
expect(diagnosticScreenOf(page), screen);
|
|
});
|
|
}
|
|
});
|
|
|
|
group('screen breadcrumbs', () {
|
|
const channelId = 'c0ffee-secret-channel-id';
|
|
late _RecordingReporter reporter;
|
|
late GlobalKey<NavigatorState> root;
|
|
|
|
Future<void> pumpApp(
|
|
WidgetTester tester, {
|
|
bool reporting = true,
|
|
Widget home = const _Page(DiagnosticScreen.channelList),
|
|
}) async {
|
|
reporter = _RecordingReporter(reporting: reporting);
|
|
root = GlobalKey<NavigatorState>();
|
|
final container = ProviderContainer(
|
|
overrides: [
|
|
diagnosticReporterProvider.overrideWithValue(reporter),
|
|
diagnosticScreenClassifierProvider.overrideWithValue(
|
|
(page) => page is _Page ? page.screen : null,
|
|
),
|
|
],
|
|
);
|
|
addTearDown(container.dispose);
|
|
final observer = container.read(diagnosticScreenTrailProvider).observer();
|
|
addTearDown(observer.dispose);
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(
|
|
container: container,
|
|
child: MaterialApp(
|
|
navigatorKey: root,
|
|
navigatorObservers: [observer],
|
|
home: home,
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
List<String> trail() => [
|
|
for (final screen in reporter.screens) screen.name,
|
|
];
|
|
|
|
testWidgets('a push and a pop leave the screens the person was on', (
|
|
tester,
|
|
) async {
|
|
await pumpApp(tester);
|
|
|
|
// A route whose settings carry an ID is still named by its page.
|
|
root.currentState!.push(
|
|
MaterialPageRoute<void>(
|
|
settings: const RouteSettings(name: '/channels/$channelId'),
|
|
builder: (_) => const _Page(DiagnosticScreen.appearance),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
// An unlisted page is "other", whatever its settings say.
|
|
root.currentState!.push(
|
|
MaterialPageRoute<void>(
|
|
settings: const RouteSettings(name: '/channels/$channelId'),
|
|
builder: (_) => const Scaffold(body: Text('unlisted')),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
// A dialog is not a screen: opening and closing it leaves nothing.
|
|
final dialog = showDialog<void>(
|
|
context: root.currentContext!,
|
|
builder: (_) => const AlertDialog(content: Text('dialog')),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
root.currentState!.pop();
|
|
await dialog;
|
|
await tester.pumpAndSettle();
|
|
// Nor is a sheet presented as a page route.
|
|
root.currentState!.push(_SheetRoute());
|
|
await tester.pumpAndSettle();
|
|
root.currentState!.pop();
|
|
await tester.pumpAndSettle();
|
|
// Two pops at once leave only the screen they end on.
|
|
root.currentState!.popUntil((route) => route.isFirst);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(trail(), ['channelList', 'appearance', 'other', 'channelList']);
|
|
expect(
|
|
reporter.crumbs.map((crumb) => crumb.toString()).join(),
|
|
isNot(contains(channelId)),
|
|
);
|
|
});
|
|
|
|
testWidgets('a page that leaves from under a sheet names the one shown', (
|
|
tester,
|
|
) async {
|
|
await pumpApp(tester);
|
|
|
|
// Like an Android notification opening a channel over Home's actions
|
|
// sheet: Back leaves the channel, revealing the sheet over Home.
|
|
final sheet = showModalBottomSheet<void>(
|
|
context: root.currentContext!,
|
|
builder: (_) => const Text('actions'),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
root.currentState!.push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => const _Page(DiagnosticScreen.channel),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
root.currentState!.pop();
|
|
await tester.pumpAndSettle();
|
|
root.currentState!.pop();
|
|
await sheet;
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(trail(), ['channelList', 'channel', 'channelList']);
|
|
});
|
|
|
|
testWidgets('a phone pane names the screen the person is on', (
|
|
tester,
|
|
) async {
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(390, 844);
|
|
addTearDown(tester.view.reset);
|
|
final controller = ConversationPaneController();
|
|
addTearDown(controller.dispose);
|
|
final search = ConversationPaneController();
|
|
addTearDown(search.dispose);
|
|
await pumpApp(
|
|
tester,
|
|
home: _Page(
|
|
DiagnosticScreen.channelList,
|
|
child: AdaptiveConversationPane(
|
|
controller: controller,
|
|
list: const Text('list'),
|
|
),
|
|
),
|
|
);
|
|
NavigatorState pane() =>
|
|
Navigator.of(tester.element(find.text('channel')));
|
|
|
|
// The pane's empty first page shows its host, Home, once.
|
|
expect(trail(), ['channelList']);
|
|
|
|
controller.open('one', (_) => const _Page(DiagnosticScreen.channel));
|
|
await tester.pumpAndSettle();
|
|
pane().push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => const _Page(DiagnosticScreen.thread),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
Navigator.of(tester.element(find.text('thread'))).pop();
|
|
await tester.pumpAndSettle();
|
|
|
|
// A full-screen cover, such as a huddle, closes back onto the open
|
|
// channel rather than the list under it.
|
|
root.currentState!.push(
|
|
MaterialPageRoute<void>(builder: (_) => const Text('huddle')),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
root.currentState!.pop();
|
|
await tester.pumpAndSettle();
|
|
|
|
pane().pop();
|
|
await tester.pumpAndSettle();
|
|
|
|
// A page that hosts its own pane is named once.
|
|
root.currentState!.push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => _Page(
|
|
DiagnosticScreen.search,
|
|
child: AdaptiveConversationPane(
|
|
controller: search,
|
|
list: const Text('results'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
root.currentState!.pop();
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(trail(), [
|
|
'channelList',
|
|
'channel',
|
|
'thread',
|
|
'channel',
|
|
'other',
|
|
'channel',
|
|
'channelList',
|
|
'search',
|
|
'channelList',
|
|
]);
|
|
});
|
|
|
|
testWidgets('a wide section change stays on its screen', (tester) async {
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(1000, 800);
|
|
addTearDown(tester.view.reset);
|
|
final controller = ConversationPaneController();
|
|
addTearDown(controller.dispose);
|
|
await pumpApp(tester);
|
|
root.currentState!.push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => _Page(
|
|
DiagnosticScreen.settings,
|
|
child: AdaptiveConversationPane(
|
|
controller: controller,
|
|
persistentSelection: true,
|
|
list: const Text('sections'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
controller.open('status', (_) => const Text('status'));
|
|
await tester.pumpAndSettle();
|
|
controller.open('profile', (_) => const Text('profile'));
|
|
await tester.pumpAndSettle();
|
|
controller.open(
|
|
'appearance',
|
|
(_) => const _Page(DiagnosticScreen.appearance),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(trail(), ['channelList', 'settings', 'appearance']);
|
|
});
|
|
|
|
testWidgets('a build without a destination looks at nothing', (
|
|
tester,
|
|
) async {
|
|
await pumpApp(tester, reporting: false);
|
|
root.currentState!.push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => const _Page(DiagnosticScreen.appearance),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
root.currentState!.pop();
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(reporter.crumbs, isEmpty);
|
|
});
|
|
});
|
|
}
|
|
|
|
/// A page the test's list names [screen].
|
|
class _Page extends StatelessWidget {
|
|
const _Page(this.screen, {this.child});
|
|
|
|
final DiagnosticScreen screen;
|
|
final Widget? child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) =>
|
|
Scaffold(body: child ?? Text(screen.name));
|
|
}
|
|
|
|
class _SheetRoute extends PageRouteBuilder<void>
|
|
with DiagnosticSheetRoute<void> {
|
|
_SheetRoute()
|
|
: super(
|
|
opaque: false,
|
|
pageBuilder: (_, _, _) => const _Page(DiagnosticScreen.channelDetails),
|
|
);
|
|
}
|
|
|
|
class _RecordingReporter extends NoopDiagnosticReporter {
|
|
_RecordingReporter({required this.reporting});
|
|
|
|
@override
|
|
final bool reporting;
|
|
|
|
final crumbs = <DiagnosticBreadcrumb>[];
|
|
|
|
Iterable<DiagnosticScreen> get screens =>
|
|
crumbs.whereType<ScreenBreadcrumb>().map((crumb) => crumb.screen);
|
|
|
|
@override
|
|
void leaveBreadcrumb(DiagnosticBreadcrumb breadcrumb) =>
|
|
crumbs.add(breadcrumb);
|
|
}
|