26bb583f10
Keep Settings navigation independent while preserving shell actions and destination-specific state. Add the reviewed chat, run-entry, layout, and regression-test updates needed by the destination behavior.
163 lines
6.5 KiB
Dart
163 lines
6.5 KiB
Dart
import '../features/settings/settings_section_test_helper.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/application/pipelines_app.dart';
|
|
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
|
import 'package:pipelines_app/features/settings/settings_screen.dart';
|
|
import 'package:pipelines_app/features/walkthrough/walkthrough_store.dart';
|
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
|
import '../features/pipelines/fixtures.dart';
|
|
import 'pipelines_app_test.dart' show webServer;
|
|
import 'pipelines_replies.dart';
|
|
|
|
/// Settings is a navigation destination: the phone's bar and the wide rail
|
|
/// offer it, and the floating tab bar's width (between the list-detail and rail
|
|
/// widths) keeps the Pipelines bar's gear. Settings reached from a nav control
|
|
/// has no Back; reached as a pushed page (the gear, the /settings deep link) it
|
|
/// has Back, which returns to Pipelines.
|
|
void main() {
|
|
Future<PlatformRouteInformationProvider> pumpApp(
|
|
WidgetTester tester, {
|
|
required String location,
|
|
required Size size,
|
|
}) async {
|
|
SharedPreferences.setMockInitialValues({walkthroughSeenKey: true});
|
|
tester.view.physicalSize = size;
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
final channel = FakeChannel()..readyCompleter.complete();
|
|
final provider = PlatformRouteInformationProvider(
|
|
initialRouteInformation: RouteInformation(uri: Uri.parse(location)),
|
|
);
|
|
addTearDown(provider.dispose);
|
|
await tester.pumpWidget(
|
|
PipelinesApp(
|
|
androidSupported: false,
|
|
server: webServer(),
|
|
client: PipelinesClient(channelFactory: (_) => channel),
|
|
routeInformationProvider: provider,
|
|
),
|
|
);
|
|
await tester.pump();
|
|
if (location == '/pipelines') {
|
|
await replyPipelines(tester, channel, PipelineFixture());
|
|
}
|
|
return provider;
|
|
}
|
|
|
|
// The phone's bar marks the destination shown: Settings while it is open.
|
|
int selectedTab(WidgetTester tester) =>
|
|
tester.widget<NavigationBar>(find.byType(NavigationBar)).selectedIndex;
|
|
|
|
testWidgets('390: the bar offers Settings and no gear; Settings from the bar '
|
|
'has no Back and the Pipelines item leaves it', (tester) async {
|
|
final provider = await pumpApp(
|
|
tester,
|
|
location: '/pipelines',
|
|
size: const Size(390, 844),
|
|
);
|
|
// Four tabs and Settings as the bar's last destination.
|
|
expect(
|
|
tester
|
|
.widget<NavigationBar>(find.byType(NavigationBar))
|
|
.destinations
|
|
.map((item) => (item as NavigationDestination).label),
|
|
['Pipelines', 'Runs', 'Chat', 'Search', 'Settings'],
|
|
);
|
|
expect(find.byKey(const Key('pipelines-open-settings')), findsNothing);
|
|
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
|
|
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
|
|
await tester.pumpAndSettle();
|
|
expect(provider.value.uri.path, '/settings');
|
|
expect(find.byType(SettingsScreen), findsOneWidget);
|
|
expect(find.text('Quick switch animation'), findsOneWidget);
|
|
await openSettingsSection(tester, 'Connection');
|
|
expect(find.text('Server URL'), findsOneWidget);
|
|
// A destination: no Back, and Settings is the selected item of the bar.
|
|
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
|
|
expect(find.byKey(const ValueKey('shell.search')), findsNothing);
|
|
expect(selectedTab(tester), 4);
|
|
expect(tester.takeException(), isNull);
|
|
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.pipelines')));
|
|
await tester.pumpAndSettle();
|
|
expect(provider.value.uri.path, '/pipelines');
|
|
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump();
|
|
});
|
|
|
|
testWidgets('1200: the rail offers Settings at its foot and no gear is '
|
|
'left in the Pipelines toolbar; Settings from the rail has no Back', (
|
|
tester,
|
|
) async {
|
|
final provider = await pumpApp(
|
|
tester,
|
|
location: '/pipelines',
|
|
size: const Size(1200, 800),
|
|
);
|
|
expect(find.byType(NavigationRail), findsOneWidget);
|
|
expect(find.byKey(const Key('pipelines-open-settings')), findsNothing);
|
|
expect(find.byType(FloatingDestinationBar), findsNothing);
|
|
final rail = tester.widget<NavigationRail>(find.byType(NavigationRail));
|
|
expect(rail.selectedIndex, 0);
|
|
for (final label in ['Pipelines', 'Runs', 'Chat', 'Search', 'Settings']) {
|
|
expect(
|
|
find.descendant(
|
|
of: find.byType(NavigationRail),
|
|
matching: find.text(label),
|
|
),
|
|
findsOneWidget,
|
|
reason: label,
|
|
);
|
|
}
|
|
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
|
|
await tester.pumpAndSettle();
|
|
expect(provider.value.uri.path, '/settings');
|
|
expect(find.byType(SettingsScreen), findsOneWidget);
|
|
// Settings is a destination: the rail marks Settings, not a tab.
|
|
expect(
|
|
tester.widget<NavigationRail>(find.byType(NavigationRail)).selectedIndex,
|
|
isNull,
|
|
);
|
|
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
|
|
expect(tester.takeException(), isNull);
|
|
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.pipelines')));
|
|
await tester.pumpAndSettle();
|
|
expect(provider.value.uri.path, '/pipelines');
|
|
expect(find.byKey(const Key('pipelines-open-settings')), findsNothing);
|
|
expect(
|
|
tester.widget<NavigationRail>(find.byType(NavigationRail)).selectedIndex,
|
|
0,
|
|
);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump();
|
|
});
|
|
|
|
testWidgets('the /settings deep link opens Settings as a pushed page with '
|
|
'Back, and the system Back closes it to Pipelines', (tester) async {
|
|
final provider = await pumpApp(
|
|
tester,
|
|
location: '/settings',
|
|
size: const Size(390, 844),
|
|
);
|
|
await tester.pump();
|
|
expect(find.byType(SettingsScreen), findsOneWidget);
|
|
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
|
|
expect(selectedTab(tester), 4);
|
|
|
|
final handled = await tester.binding.handlePopRoute();
|
|
expect(handled, isTrue, reason: 'Back closes the page, not the app');
|
|
await tester.pumpAndSettle();
|
|
expect(provider.value.uri.path, '/pipelines');
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump();
|
|
});
|
|
}
|