import 'package:flutter/material.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'; const _openConnectionKey = ValueKey('walkthrough.open-connection'); /// The walkthrough acts as well as directs: Open Connection on the connect /// page (skipped once connected) and a labelled Copy command. void main() { Future launch( WidgetTester tester, { required bool connected, required VoidCallback onOpenConnection, }) async { tester.view.physicalSize = const Size(390, 844); tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); await tester.pumpWidget( MaterialApp( home: Scaffold( body: Builder( builder: (context) => TextButton( onPressed: () => showFirstRunWalkthrough( context, connected: connected, onOpenConnection: onOpenConnection, ), child: const Text('Open'), ), ), ), ), ); await tester.tap(find.text('Open')); await tester.pumpAndSettle(); } testWidgets('Open Connection closes the walkthrough and opens it', ( tester, ) async { var opened = 0; await launch(tester, connected: false, onOpenConnection: () => opened++); expect(find.textContaining('enter the Server URL'), findsOneWidget); await tester.tap(find.byKey(_openConnectionKey)); await tester.pumpAndSettle(); expect(opened, 1); expect(find.text('Step 1 of 4'), findsNothing); }); testWidgets('a connected app skips the connect directions', (tester) async { await launch(tester, connected: true, onOpenConnection: () {}); expect(find.text('Step 1 of 4'), findsOneWidget); expect(find.textContaining('this app is connected'), findsOneWidget); expect(find.textContaining('enter the Server URL'), findsNothing); expect(find.byKey(_openConnectionKey), findsNothing); expect(walkthroughStepsFor(connected: true), hasLength(4)); }); testWidgets('the harness page labels its copy action', (tester) async { await launch(tester, connected: true, onOpenConnection: () {}); await tester.tap(find.byKey(const ValueKey('walkthrough.next'))); await tester.pumpAndSettle(); expect( find.descendant( of: find.byKey(const ValueKey('walkthrough.copy')), matching: find.text('Copy command'), ), findsOneWidget, ); }); }