Files
buzz/mobile/test/features/onboarding/known_communities_refresh_test.dart
klopez4212 9c3ba83adb Simplify signed-in mobile community onboarding (#8852)
Replace the signed-in mobile welcome screen with **Add a community**: QR
scan first, then grey secondary actions for community links, finding
saved communities, and creation. Hide **Find my communities** when none
are known; refresh on entry/resume and every 30 seconds while active,
retaining results on transient failure.

Community switcher → Add keeps its two-action flow and uses the same
grey secondary link button.

Validation: Flutter analysis, full mobile suite (4,014 tests),
Builderlab-enabled full suite (4,036 tests), widget interactions, and
independent agent review. Draft pending native sign-in and human
testing. Snapshots render the production Flutter widgets; native
navigation/status bars are omitted.

| Communities available | No communities | Switcher → Add |
|---|---|---|
| ![Onboarding with
communities](https://github.com/user-attachments/assets/444b05c5-711f-41df-9c50-293ad9e13767)
| ![Onboarding without
communities](https://github.com/user-attachments/assets/db78a490-bd8e-4d78-97b4-a391b52290d8)
| ![Switcher Add with grey secondary
button](https://github.com/user-attachments/assets/de9e42d2-dd53-462b-98c7-da87223e5dd4)
|

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
2026-10-31 07:46:44 -07:00

118 lines
3.5 KiB
Dart

import 'dart:async';
import 'package:buzz/shared/hosted/use_known_communities.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('discovery refreshes, retains results on error and pauses', (
tester,
) async {
var calls = 0;
var active = true;
var fail = false;
Future<bool> load() async {
calls++;
if (fail) throw StateError('offline');
return calls > 1;
}
Widget page() => MaterialApp(
home: HookBuilder(
builder: (_) {
final found = useKnownCommunities(
accountKey: 'a',
active: active,
load: load,
);
return Text(found ? 'found' : 'empty');
},
),
);
await tester.pumpWidget(page());
await tester.pump();
expect(calls, 1);
expect(find.text('empty'), findsOneWidget);
await tester.pump(const Duration(seconds: 30));
await tester.pump();
expect(find.text('found'), findsOneWidget);
fail = true;
await tester.pump(const Duration(seconds: 30));
await tester.pump();
expect(find.text('found'), findsOneWidget);
active = false;
await tester.pumpWidget(page());
final pausedCalls = calls;
await tester.pump(const Duration(minutes: 1));
expect(calls, pausedCalls);
await tester.pumpWidget(const SizedBox());
});
testWidgets('account change discards old results and in-flight responses', (
tester,
) async {
var account = 'a';
final first = Completer<bool>();
Widget page() => MaterialApp(
home: HookBuilder(
builder: (_) {
final found = useKnownCommunities(
accountKey: account,
active: true,
load: () => account == 'a' ? first.future : Future.value(false),
);
return Text(found ? 'found' : 'empty');
},
),
);
await tester.pumpWidget(page());
await tester.pump(const Duration(seconds: 30));
account = 'b';
await tester.pumpWidget(page());
await tester.pump();
first.complete(true);
await tester.pump();
expect(find.text('empty'), findsOneWidget);
await tester.pumpWidget(const SizedBox());
});
testWidgets('backgrounding stops requests and resuming refreshes', (
tester,
) async {
var calls = 0;
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
await tester.pumpWidget(
MaterialApp(
home: HookBuilder(
builder: (_) {
useKnownCommunities(
accountKey: 'a',
active: true,
load: () async {
calls++;
return true;
},
);
return const SizedBox();
},
),
),
);
await tester.pump();
expect(calls, 1);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);
await tester.pump();
await tester.pump(const Duration(minutes: 1));
expect(calls, 1);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
await tester.pump();
expect(calls, 2);
await tester.pumpWidget(const SizedBox());
});
}