Merge commit 'f2a74adb75b035a5a732d11e7e8117314e511150' into pipelines/run-20261112-0157-reliable-android-notifications-while-clo-880f

This commit is contained in:
2026-11-12 02:40:31 +00:00
82 changed files with 3398 additions and 608 deletions
@@ -50,7 +50,7 @@ Future<void> _pumpShell(WidgetTester tester, Size size) async {
void main() {
for (final size in [const Size(1280, 800), const Size(800, 830)]) {
testWidgets('a wide window keeps the tab bar and list beside the open chat '
testWidgets('a wide window keeps the rail and list beside the open chat '
'at $size', (tester) async {
await _pumpShell(tester, size);
expect(
@@ -68,8 +68,10 @@ void main() {
find.byType(Navigator).first,
);
expect(navigator.canPop(), isFalse, reason: 'No page covers the shell');
expect(find.byType(NavigationRail), findsNothing);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
// Both sizes are wide enough for the rail (the shell's own bar and list
// beside the open chat sit to its right).
expect(find.byType(NavigationRail), findsOneWidget);
expect(find.byType(FloatingDestinationBar), findsNothing);
expect(find.byKey(const ValueKey('chat-thread-a')), findsOneWidget);
expect(find.text('Second chat'), findsOneWidget);
expect(
@@ -11,7 +11,7 @@ void main() {
testWidgets('chat list stays above labeled navigation ($scale)', (
tester,
) async {
tester.view.physicalSize = const Size(1200, 900);
tester.view.physicalSize = const Size(640, 900);
tester.view.devicePixelRatio = 1;
tester.platformDispatcher.textScaleFactorTestValue = scale;
addTearDown(tester.view.reset);
@@ -87,7 +87,13 @@ void main() {
),
same(scrollable),
);
expect(scrollable.position.pixels, closeTo(retainedOffset, .5));
// The list is narrower at 640 (no rail) than beside the rail, so its
// rows re-wrap into a shorter scroll extent: the offset is kept up to
// that extent, and no further.
final kept = retainedOffset < scrollable.position.maxScrollExtent
? retainedOffset
: scrollable.position.maxScrollExtent;
expect(scrollable.position.pixels, closeTo(kept, .5));
expect(tester.takeException(), isNull);
});
}
@@ -106,7 +106,16 @@ void main() {
expect(find.text('Menu'), findsOneWidget);
await tester.tap(find.text('Menu'));
await tester.pumpAndSettle();
await tester.tap(find.text('Runs'));
// The menu's own row: the rail labels Runs too, so take the text that
// is not in the rail.
await tester.tap(
find.byElementPredicate(
(element) =>
element.widget is Text &&
(element.widget as Text).data == 'Runs' &&
element.findAncestorWidgetOfExactType<NavigationRail>() == null,
),
);
await tester.pumpAndSettle();
expect(find.text('Runs destination'), findsOneWidget);
await tester.tap(find.byTooltip('Chat'));
@@ -244,10 +244,9 @@ void main() {
await tester.pumpAndSettle();
expect(find.text('No input recorded.'), findsOneWidget);
// Output starts open, so its empty sentence shows without a tap.
await tester.ensureVisible(find.text('Output'));
await tester.pumpAndSettle();
await tester.tap(find.text('Output'));
await tester.pumpAndSettle();
expect(find.text('No output recorded.'), findsOneWidget);
});
@@ -266,5 +265,35 @@ void main() {
await tester.pumpAndSettle();
expect(find.text('ship it'), findsOneWidget);
});
testWidgets('${platform.name} summary output starts expanded and '
'collapses for this view', (tester) async {
await pumpRunDetail(
tester,
platform,
run: recordedRunFixture(),
size: const Size(900, 1600),
);
final output = find.byKey(const ValueKey('run-detail-summary-output'));
final outputTitle = find.descendant(
of: output,
matching: find.text('Output'),
);
final outputBody = find.descendant(of: output, matching: find.text('ok'));
// Output opens with its recorded value; Input stays closed.
expect(outputBody, findsOneWidget);
expect(find.text('ship it'), findsNothing);
await tester.ensureVisible(outputTitle.first);
await tester.pumpAndSettle();
await tester.tap(outputTitle.first);
await tester.pumpAndSettle();
expect(outputBody, findsNothing);
await tester.tap(outputTitle.first);
await tester.pumpAndSettle();
expect(outputBody, findsOneWidget);
});
}
}
@@ -49,21 +49,77 @@ void main() {
}
});
testWidgets('${platform.name} visit Output starts expanded and collapses', (
tester,
) async {
await openVisit(tester, platform);
final output = find.byKey(const ValueKey('run-visit-section-Output'));
final outputTitle = find.descendant(
of: output,
matching: find.text('Output'),
);
final outputBody = find.descendant(of: output, matching: find.text('ok'));
final input = find.byKey(const ValueKey('run-visit-section-Input'));
// Output opens expanded; Input stays closed.
expect(find.text('result'), findsOneWidget);
expect(outputBody, findsOneWidget);
expect(find.text('Ship it.'), findsNothing);
// The operator can collapse Output, and open it again.
await tester.ensureVisible(outputTitle.first);
await tester.tap(outputTitle.first);
await tester.pumpAndSettle();
expect(outputBody, findsNothing);
expect(find.text('result'), findsNothing);
await tester.tap(outputTitle.first);
await tester.pumpAndSettle();
expect(outputBody, findsOneWidget);
expect(input, findsOneWidget);
});
testWidgets('${platform.name} long visit Output opens lazily and still '
'scrolls to its last field', (tester) async {
final run = visitRunFixture();
firstVisitStep(run)['output'] = <String, dynamic>{
for (var i = 0; i < 500; i++) 'field$i': 'value $i',
};
await openVisit(tester, platform, run: run);
// Open by default, yet only the fields on screen are built.
expect(find.text('value 0'), findsOneWidget);
expect(find.text('value 499'), findsNothing);
// Scrolling the page reaches the rest of the Output.
await tester.scrollUntilVisible(
find.text('value 499'),
500,
// The page's own scroll view is the outermost of its scrollables.
scrollable: find
.descendant(
of: find.byKey(const Key('run-visit-body-summary')),
matching: find.byType(Scrollable),
)
.first,
);
expect(find.text('value 499'), findsOneWidget);
});
testWidgets('${platform.name} tabs show recorded values and exact empty '
'wording', (tester) async {
await openVisit(tester, platform);
// Each field by name with its value, never raw JSON.
// Each field by name with its value, never raw JSON. Output is open at
// once; Input's value shows only after its tap.
expect(find.text('Ship it.'), findsNothing);
expect(find.text('ok'), findsNothing);
expect(find.text('ok'), findsOneWidget);
await tester.tap(find.text('Input'));
await tester.pumpAndSettle();
expect(find.text('prompt'), findsOneWidget);
expect(find.text('Ship it.'), findsOneWidget);
expect(find.textContaining('"prompt"'), findsNothing);
// Output is open as the visit opens; no tap is needed to read it.
await openVisitTab(tester, RunVisitSection.output);
await tester.tap(find.text('Output'));
await tester.pumpAndSettle();
expect(find.text('result'), findsOneWidget);
expect(find.text('ok'), findsOneWidget);
@@ -127,13 +183,12 @@ void main() {
await openVisit(tester, platform, run: run);
expect(find.text(visitEmptyInput), findsNothing);
expect(find.text(visitEmptyOutput), findsNothing);
// Output is open, so its empty sentence is already there.
expect(find.text(visitEmptyOutput), findsOneWidget);
await tester.tap(find.text('Input'));
await tester.pumpAndSettle();
expect(find.text(visitEmptyInput), findsOneWidget);
await openVisitTab(tester, RunVisitSection.output);
await tester.tap(find.text('Output'));
await tester.pumpAndSettle();
expect(find.text(visitEmptyOutput), findsOneWidget);
await openVisitTab(tester, RunVisitSection.artifacts);
expect(
@@ -172,7 +172,17 @@ void main() {
expect(find.text('alpha=1, items=1, 2'), findsOneWidget);
expect(find.textContaining('"alpha"'), findsNothing);
await openSummarySection('Output');
// Output starts open: its value is there to scroll to, without a tap.
await tester.scrollUntilVisible(
find.text('ok=true'),
200,
scrollable: find
.descendant(
of: find.byKey(const Key('run-detail-tab-body-summary')),
matching: find.byType(Scrollable),
)
.first,
);
expect(find.text('ok=true'), findsOneWidget);
await tapTab('Timeline');
@@ -263,7 +263,7 @@ void main() {
});
for (final platform in RunDetailTestPlatform.values) {
testWidgets('${platform.name} input field expands only the input section', (
testWidgets('${platform.name} input field expands the input section', (
tester,
) async {
await pumpSelection(
@@ -277,7 +277,8 @@ void main() {
findsOneWidget,
);
expect(find.text('ship it'), findsOneWidget);
expect(find.text('ok'), findsNothing);
// Output keeps its default: open, as every Summary opens.
expect(find.text('ok'), findsOneWidget);
});
testWidgets(
@@ -310,8 +311,9 @@ void main() {
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
// The plain Summary shows its default sections: Output open, Input closed.
expect(find.text('ship it'), findsNothing);
expect(find.text('ok'), findsNothing);
expect(find.text('ok'), findsOneWidget);
});
for (final platform in RunDetailTestPlatform.values) {
@@ -337,8 +339,9 @@ void main() {
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
// The Summary's default sections: Output open, Input closed.
expect(find.text('ship it'), findsNothing);
expect(find.text('ok'), findsNothing);
expect(find.text('ok'), findsOneWidget);
},
);
}
@@ -40,6 +40,19 @@ void main() {
},
);
test('Runs and Pipelines switch is Ctrl+A on every platform', () {
for (final platform in TargetPlatform.values) {
final entry = KeyboardShortcutRegistry(platform: platform, web: false)
.entries
.firstWhere(
(entry) => entry.action == 'Switch between Runs and Pipelines',
);
expect(entry.keys, 'Ctrl+A', reason: platform.name);
expect(entry.caveat, contains('Pipelines'));
expect(entry.caveat, contains('text field'));
}
});
test('uses the shell primary modifier rule on iOS', () {
final entries = const KeyboardShortcutRegistry(
platform: TargetPlatform.iOS,
@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/settings/settings_keys.dart';
import 'package:pipelines_app/features/settings/settings_walkthrough_section.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
void main() {
testWidgets('Settings reopens the walkthrough on the first page', (
tester,
) async {
tester.view.devicePixelRatio = 1;
tester.view.physicalSize = const Size(390, 844);
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
theme: appLightTheme(),
home: const Scaffold(body: SettingsWalkthroughSection()),
),
);
expect(find.text('Show the walkthrough'), findsOneWidget);
expect(find.text('Welcome to Pipelines'), findsNothing);
await tester.tap(find.byKey(SettingsKeys.walkthrough));
await tester.pumpAndSettle();
expect(find.text('Welcome to Pipelines'), findsOneWidget);
expect(find.text('Step 1 of 4'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey<String>('walkthrough.skip')));
await tester.pumpAndSettle();
expect(find.text('Welcome to Pipelines'), findsNothing);
});
}
@@ -0,0 +1,202 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/walkthrough/first_run_walkthrough.dart';
import 'package:pipelines_app/features/walkthrough/walkthrough_steps.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
const _nextKey = ValueKey<String>('walkthrough.next');
const _backKey = ValueKey<String>('walkthrough.back');
const _skipKey = ValueKey<String>('walkthrough.skip');
const _copyKey = ValueKey<String>('walkthrough.copy');
const _commandKey = ValueKey<String>('walkthrough.command');
const _launchKey = ValueKey<String>('launch');
Widget _launcher({ThemeMode mode = ThemeMode.light, double textScale = 1}) =>
MaterialApp(
theme: appLightTheme(),
darkTheme: appDarkTheme(),
themeMode: mode,
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(textScale)),
child: child!,
),
home: Scaffold(
body: Builder(
builder: (context) => Center(
child: FilledButton(
key: _launchKey,
onPressed: () => showFirstRunWalkthrough(context),
child: const Text('Open'),
),
),
),
),
);
Future<void> _open(WidgetTester tester) async {
await tester.tap(find.byKey(_launchKey));
await tester.pumpAndSettle();
}
void _useViewport(WidgetTester tester, Size size) {
tester.view.devicePixelRatio = 1;
tester.view.physicalSize = size;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
}
void main() {
group('phone layout', () {
testWidgets('opens as a bottom sheet with the first page', (tester) async {
_useViewport(tester, const Size(390, 844));
await tester.pumpWidget(_launcher());
await _open(tester);
expect(find.byType(BottomSheet), findsOneWidget);
expect(find.byType(Dialog), findsNothing);
expect(find.text('Step 1 of 4'), findsOneWidget);
expect(find.text(walkthroughSteps.first.title), findsOneWidget);
});
testWidgets('Back is disabled on the first page; Next advances', (
tester,
) async {
_useViewport(tester, const Size(390, 844));
await tester.pumpWidget(_launcher());
await _open(tester);
expect(tester.widget<TextButton>(find.byKey(_backKey)).onPressed, isNull);
await tester.tap(find.byKey(_nextKey));
await tester.pumpAndSettle();
expect(find.text('Step 2 of 4'), findsOneWidget);
expect(
tester.widget<TextButton>(find.byKey(_backKey)).onPressed,
isNotNull,
);
await tester.tap(find.byKey(_backKey));
await tester.pumpAndSettle();
expect(find.text('Step 1 of 4'), findsOneWidget);
});
testWidgets('walks four pages, Done on the last, Skip on every page', (
tester,
) async {
_useViewport(tester, const Size(390, 844));
await tester.pumpWidget(_launcher());
await _open(tester);
for (var page = 0; page < 3; page++) {
expect(find.byKey(_skipKey), findsOneWidget);
expect(find.text('Next'), findsOneWidget);
await tester.tap(find.byKey(_nextKey));
await tester.pumpAndSettle();
}
expect(find.text('Step 4 of 4'), findsOneWidget);
expect(find.text('Done'), findsOneWidget);
expect(find.byKey(_skipKey), findsOneWidget);
expect(find.text(walkthroughSteps.last.title), findsOneWidget);
await tester.tap(find.text('Done'));
await tester.pumpAndSettle();
expect(find.text(walkthroughSteps.last.title), findsNothing);
});
testWidgets('Skip closes from the middle of the walkthrough', (
tester,
) async {
_useViewport(tester, const Size(390, 844));
await tester.pumpWidget(_launcher());
await _open(tester);
await tester.tap(find.byKey(_nextKey));
await tester.pumpAndSettle();
await tester.tap(find.byKey(_skipKey));
await tester.pumpAndSettle();
expect(find.byType(BottomSheet), findsNothing);
});
});
testWidgets('wide windows open the walkthrough as a dialog', (tester) async {
_useViewport(tester, const Size(1280, 900));
await tester.pumpWidget(_launcher());
await _open(tester);
expect(find.byType(Dialog), findsOneWidget);
expect(find.byType(BottomSheet), findsNothing);
expect(find.text('Step 1 of 4'), findsOneWidget);
await tester.tap(find.byKey(_nextKey));
await tester.pumpAndSettle();
expect(find.text(walkthroughSteps[1].title), findsOneWidget);
});
testWidgets('the harness page offers each agent and copies its command', (
tester,
) async {
_useViewport(tester, const Size(390, 844));
final copied = <String>[];
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform, (call) async {
if (call.method == 'Clipboard.setData') {
copied.add((call.arguments as Map)['text'] as String);
}
return null;
});
addTearDown(
() => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform, null),
);
await tester.pumpWidget(_launcher());
await _open(tester);
await tester.tap(find.byKey(_nextKey));
await tester.pumpAndSettle();
expect(
tester.widget<SelectableText>(find.byKey(_commandKey)).data,
'pipelines harness setup claude',
);
await tester.tap(
find.byKey(const ValueKey<String>('walkthrough.agent.pi')),
);
await tester.pumpAndSettle();
expect(
tester.widget<SelectableText>(find.byKey(_commandKey)).data,
'pipelines harness setup pi',
);
await tester.tap(find.byKey(_copyKey));
await tester.pumpAndSettle();
expect(copied, ['pipelines harness setup pi']);
expect(
find.descendant(
of: find.byKey(_copyKey),
matching: find.byIcon(Icons.check),
),
findsOneWidget,
);
});
testWidgets('large text and dark mode lay out without overflow', (
tester,
) async {
_useViewport(tester, const Size(360, 740));
await tester.pumpWidget(_launcher(mode: ThemeMode.dark, textScale: 2));
await _open(tester);
for (var page = 0; page < walkthroughSteps.length; page++) {
expect(tester.takeException(), isNull, reason: 'page $page');
expect(find.text(walkthroughSteps[page].title), findsOneWidget);
if (page < walkthroughSteps.length - 1) {
// At 2x text the phone sheet scrolls, so Next can start off screen.
await tester.ensureVisible(find.byKey(_nextKey));
await tester.tap(find.byKey(_nextKey));
await tester.pumpAndSettle();
}
}
expect(tester.takeException(), isNull);
});
}
@@ -0,0 +1,341 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/walkthrough/walkthrough_gate.dart';
import 'package:pipelines_app/features/walkthrough/walkthrough_store.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
import 'package:shared_preferences/shared_preferences.dart';
const _welcome = 'Welcome to Pipelines';
Future<SharedPreferences?> _noPreferences() async => null;
/// A gateway that answers the three empty-server list calls from fixed lists.
class _FakeGateway implements ApiGateway {
_FakeGateway({this.runs = const <Object>[], this.failing = false});
/// Runs the server reports; pipelines and chats are always empty here.
final List<Object> runs;
bool failing;
final calls = <String>[];
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
calls.add(type);
if (failing) throw StateError('offline');
return switch (type) {
'list_pipelines' => <String, dynamic>{'pipelines': const <Object>[]},
'list_runs' => <String, dynamic>{'runs': runs},
'chat_sessions' => <String, dynamic>{'chat_sessions': const <Object>[]},
_ => <String, dynamic>{'type': 'error'},
};
}
@override
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
}
/// Delegates to [inner], but holds [isSeen] until [release] so a test can
/// change the page visibility while an offer is still in flight.
class _HeldStore implements WalkthroughStore {
_HeldStore(this.inner);
final MemoryWalkthroughStore inner;
Completer<void>? _gate;
void hold() => _gate = Completer<void>();
void release() {
_gate?.complete();
_gate = null;
}
@override
Future<bool> isSeen() async {
await _gate?.future;
return inner.isSeen();
}
@override
Future<void> markSeen() => inner.markSeen();
@override
Future<bool> wasOffered(String serverScope) =>
inner.wasOffered(serverScope);
@override
Future<void> markOffered(String serverScope) =>
inner.markOffered(serverScope);
}
/// [link] stands in for the session: its value is whether the server connected,
/// and notifying it is the connection transition. Defaults to connected.
Widget _host({
required WalkthroughStore store,
ApiGateway? gateway,
bool enabled = true,
ValueNotifier<bool>? link,
}) {
final session = link ?? ValueNotifier<bool>(true);
return MaterialApp(
theme: appLightTheme(),
darkTheme: appDarkTheme(),
home: Scaffold(
body: FirstRunWalkthroughGate(
store: store,
enabled: enabled,
serverScope: 'server-a',
connection: session,
connected: () => session.value,
gateway: gateway,
child: const Text('Pipelines page'),
),
),
);
}
Future<void> _finishWalkthrough(WidgetTester tester) async {
for (var page = 0; page < 3; page++) {
await tester.tap(find.byKey(const ValueKey<String>('walkthrough.next')));
await tester.pumpAndSettle();
}
await tester.tap(find.text('Done'));
await tester.pumpAndSettle();
}
void main() {
testWidgets('first launch shows the walkthrough once per device', (
tester,
) async {
final store = MemoryWalkthroughStore();
await tester.pumpWidget(_host(store: store));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
await _finishWalkthrough(tester);
expect(find.text(_welcome), findsNothing);
expect(store.seen, isTrue);
// A later launch on the same device does not show it again.
await tester.pumpWidget(const SizedBox());
await tester.pumpWidget(_host(store: store));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(find.text('Pipelines page'), findsOneWidget);
});
testWidgets('Done persists the seen record and no server query runs', (
tester,
) async {
final store = MemoryWalkthroughStore();
final gateway = _FakeGateway();
await tester.pumpWidget(_host(store: store, gateway: gateway));
await tester.pumpAndSettle();
await _finishWalkthrough(tester);
expect(store.seen, isTrue);
expect(
gateway.calls,
isEmpty,
reason: 'first launch needs no server check',
);
});
testWidgets('Skip on the first page persists the seen record', (
tester,
) async {
final store = MemoryWalkthroughStore();
await tester.pumpWidget(_host(store: store));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey<String>('walkthrough.skip')));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(store.seen, isTrue);
});
testWidgets('a seen device on an empty server is offered it once', (
tester,
) async {
final store = MemoryWalkthroughStore(seen: true);
final gateway = _FakeGateway();
await tester.pumpWidget(_host(store: store, gateway: gateway));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
expect(store.offered, {'server-a'});
expect(
gateway.calls,
containsAll(['list_pipelines', 'list_runs', 'chat_sessions']),
);
await tester.tap(find.byKey(const ValueKey<String>('walkthrough.skip')));
await tester.pumpAndSettle();
// The server was offered already, so a fresh mount stays quiet.
await tester.pumpWidget(const SizedBox());
await tester.pumpWidget(_host(store: store, gateway: gateway));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
});
testWidgets(
'a seen device that starts disconnected is offered once it connects',
(tester) async {
// Startup order in the app: the Pipelines page mounts before the session
// has connected. The server must not be asked yet, and the offer must
// still happen after the connection arrives.
final store = MemoryWalkthroughStore(seen: true);
final gateway = _FakeGateway();
final link = ValueNotifier<bool>(false);
await tester.pumpWidget(
_host(store: store, gateway: gateway, link: link),
);
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(
gateway.calls,
isEmpty,
reason: 'no server call while disconnected',
);
expect(store.offered, isEmpty);
link.value = true;
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
expect(store.offered, {'server-a'});
expect(
gateway.calls,
containsAll(['list_pipelines', 'list_runs', 'chat_sessions']),
);
},
);
testWidgets('an unreadable check is retried on the next connection', (
tester,
) async {
final store = MemoryWalkthroughStore(seen: true);
final gateway = _FakeGateway(failing: true);
final link = ValueNotifier<bool>(true);
await tester.pumpWidget(_host(store: store, gateway: gateway, link: link));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(store.offered, isEmpty);
final callsAfterFailure = gateway.calls.length;
// A repeated notification while still connected does not re-query.
link.notifyListeners();
await tester.pumpAndSettle();
expect(gateway.calls.length, callsAfterFailure);
// The server recovers; a fresh connection runs the check and offers it.
gateway.failing = false;
link.value = false;
await tester.pumpAndSettle();
link.value = true;
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
expect(store.offered, {'server-a'});
});
testWidgets('a seen device on a server with work is not offered', (
tester,
) async {
final store = MemoryWalkthroughStore(seen: true);
final gateway = _FakeGateway(
runs: <Object>[
<String, dynamic>{'id': 'run-1'},
],
);
await tester.pumpWidget(_host(store: store, gateway: gateway));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(store.offered, isEmpty);
});
testWidgets('an unreadable server never triggers the walkthrough', (
tester,
) async {
final store = MemoryWalkthroughStore(seen: true);
await tester.pumpWidget(
_host(store: store, gateway: _FakeGateway(failing: true)),
);
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(store.offered, isEmpty);
});
testWidgets('the Pipelines page being hidden defers the check', (
tester,
) async {
final store = MemoryWalkthroughStore();
await tester.pumpWidget(_host(store: store, enabled: false));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(store.seen, isFalse);
await tester.pumpWidget(_host(store: store, enabled: true));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
});
testWidgets(
'hiding Pipelines while an offer is pending keeps the walkthrough closed',
(tester) async {
final inner = MemoryWalkthroughStore();
final store = _HeldStore(inner)..hold();
await tester.pumpWidget(_host(store: store));
await tester.pump();
// The Pipelines page is hidden while the offer is still reading the store.
await tester.pumpWidget(_host(store: store, enabled: false));
store.release();
await tester.pumpAndSettle();
expect(find.text(_welcome), findsNothing);
expect(inner.seen, isFalse);
// Showing Pipelines again offers it once, on the same mount.
await tester.pumpWidget(_host(store: store, enabled: true));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
},
);
test('an unavailable preference store reports seen and offered', () async {
// The opener yields no preferences, as when the platform store is absent:
// every read reports "seen" and every write is quietly dropped.
const store = SharedPreferencesWalkthroughStore(open: _noPreferences);
expect(await store.isSeen(), isTrue);
expect(await store.wasOffered('server-a'), isTrue);
await store.markSeen();
await store.markOffered('server-a');
expect(await store.isSeen(), isTrue);
});
test(
'SharedPreferences store records seen and offered under the keys',
() async {
SharedPreferences.setMockInitialValues(<String, Object>{});
const store = SharedPreferencesWalkthroughStore();
expect(await store.isSeen(), isFalse);
await store.markSeen();
expect(await store.isSeen(), isTrue);
expect(await store.wasOffered('server-a'), isFalse);
await store.markOffered('server-a');
expect(await store.wasOffered('server-a'), isTrue);
expect(await store.wasOffered('server-b'), isFalse);
},
);
}