30ba70ade8
Guide new users through connecting a server, configuring an agent harness, starting runs, and chatting with agents. Persist completion per device and offer the walkthrough again for empty servers or from Settings, with widget coverage and implementation notes.
203 lines
6.8 KiB
Dart
203 lines
6.8 KiB
Dart
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);
|
|
});
|
|
}
|