Files
pipelines/app/test/application/tab_location_navigation_test.dart
alan 9551eceaed Complete Material-only APIs and fixtures
Remove obsolete control-family flags and icon metadata across all callers, dead alternate themes and host helpers, obsolete test setup, and the unused icon-font dependency. Preserve native Material Back transitions. Make navigation fixtures independent of update plugins and answer auxiliary shell snapshots so the complete application suite can run deterministically.
2026-11-11 21:55:39 +00:00

220 lines
8.2 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pipelines_app/application/app_route.dart';
import 'package:pipelines_app/application/pipelines_app.dart';
import 'package:pipelines_app/application/tab_locations_store.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/settings/settings_screen.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
import 'package:pipelines_app/shell/destination.dart';
import '../bar_action.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';
import 'tab_locations_test.dart' show MemoryTabLocationsStore;
Future<({PlatformRouteInformationProvider provider, FakeChannel channel})>
mount(
WidgetTester tester, {
String route = '/pipelines',
TabLocationsStore? store,
}) async {
tester.view.physicalSize = const Size(560, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse(route)),
);
addTearDown(provider.dispose);
addTearDown(client.dispose);
await tester.pumpWidget(
PipelinesApp(
androidSupported: false,
server: webServer(),
client: client,
serverId: 'navigation-test',
routeInformationProvider: provider,
tabLocationsStore: store,
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
return (provider: provider, channel: channel);
}
Future<void> tab(WidgetTester tester, String name) async {
await tester.tap(find.byKey(ValueKey('shell.destination.$name')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
}
void main() {
setUp(() => SharedPreferences.setMockInitialValues({}));
testWidgets('Settings is retained inside Pipelines across tab switches', (
tester,
) async {
final app = await mount(tester);
await replyPipelines(tester, app.channel, PipelineFixture());
await tester.pumpAndSettle();
await tapBarAction(
tester,
find.byKey(const Key('pipelines-open-settings')),
'Settings',
);
await tester.pumpAndSettle();
expect(app.provider.value.uri.path, '/settings');
final settingsState = tester.state(find.byType(SettingsScreen));
await tab(tester, 'chat');
expect(app.provider.value.uri.path, '/chat');
await tab(tester, 'pipelines');
expect(app.provider.value.uri.path, '/settings');
expect(tester.state(find.byType(SettingsScreen)), same(settingsState));
await tab(tester, 'pipelines');
expect(
app.provider.value.uri.path,
'/settings',
reason: 'tab retap is not Back',
);
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(
app.provider.value.uri.path,
'/pipelines',
reason: 'explicit Back still exits Settings',
);
expect(tester.takeException(), isNull);
});
testWidgets(
'per-tab locations survive app recreation; an explicit deep link wins',
(tester) async {
final first = await mount(tester, route: '/settings');
await tester.pumpAndSettle();
expect(first.provider.value.uri.path, '/settings');
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
final restored = await mount(tester, route: '/');
await tester.pumpAndSettle();
expect(restored.provider.value.uri.path, '/settings');
expect(find.byType(SettingsScreen), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
final linked = await mount(tester, route: '/runs/8/stage/plan?visit=2');
expect(
linked.provider.value.uri.toString(),
'/runs/8/stage/plan?visit=2',
);
await tab(tester, 'chat');
await tab(tester, 'runs');
expect(
linked.provider.value.uri.toString(),
'/runs/8/stage/plan?visit=2',
);
await tab(tester, 'pipelines');
expect(linked.provider.value.uri.path, '/settings');
expect(tester.takeException(), isNull);
},
);
testWidgets(
'a delayed read merges locations without redirecting a user move',
(tester) async {
final store = MemoryTabLocationsStore()..read = Completer();
final app = await mount(tester, route: '/', store: store);
await tab(tester, 'chat');
expect(store.writes, isEmpty);
store.read!.complete(
const TabLocationsSnapshot(
active: AppDestination.pipelines,
routes: {AppDestination.pipelines: AppRoute.settings},
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(app.provider.value.uri.path, '/chat');
await tab(tester, 'pipelines');
expect(app.provider.value.uri.path, '/settings');
expect(tester.takeException(), isNull);
},
);
testWidgets('an explicit root URL does not restore a different active tab', (
tester,
) async {
final store = MemoryTabLocationsStore()
..value = TabLocationsSnapshot(
active: AppDestination.runs,
routes: {
AppDestination.runs: AppRoute.run(9),
AppDestination.pipelines: AppRoute.settings,
},
);
final app = await mount(tester, route: '/pipelines', store: store);
expect(app.provider.value.uri.path, '/pipelines');
await tab(tester, 'runs');
expect(app.provider.value.uri.path, '/runs/9');
await tab(tester, 'pipelines');
expect(app.provider.value.uri.path, '/pipelines');
expect(tester.takeException(), isNull);
});
testWidgets('Settings does not clear the mounted Pipelines detail', (
tester,
) async {
final app = await mount(tester);
tester.view.physicalSize = const Size(1100, 1000);
await tester.pump();
final fixture = PipelineFixture();
await replyPipelines(tester, app.channel, fixture);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pump();
await replyPipelineDetail(tester, app.channel, fixture);
await tester.pumpAndSettle();
expect(app.provider.value.uri.path, '/pipelines/1');
final before = tester.widget<PipelinesScreen>(find.byType(PipelinesScreen));
expect(before.initialPipelineId, 1);
final pipelineState = tester.state(find.byType(PipelinesScreen));
await tapBarAction(
tester,
find.byKey(const Key('pipelines-open-settings')),
'Settings',
);
await tester.pumpAndSettle();
expect(app.provider.value.uri.path, '/settings');
final hidden = find.byType(PipelinesScreen, skipOffstage: false);
expect(tester.widget<PipelinesScreen>(hidden).initialPipelineId, 1);
expect(tester.state(hidden), same(pipelineState));
await tab(tester, 'chat');
await tab(tester, 'pipelines');
expect(app.provider.value.uri.path, '/settings');
expect(tester.widget<PipelinesScreen>(hidden).initialPipelineId, 1);
await tester.tap(find.byKey(const Key('shell.back')));
await tester.pumpAndSettle();
expect(app.provider.value.uri.path, '/pipelines/1');
expect(tester.state(find.byType(PipelinesScreen)), same(pipelineState));
expect(
tester
.widget<PipelinesScreen>(find.byType(PipelinesScreen))
.initialPipelineId,
1,
);
expect(tester.takeException(), isNull);
});
testWidgets('ordinary root with query restores its tab', (tester) async {
final store = MemoryTabLocationsStore()
..value = const TabLocationsSnapshot(
routes: {AppDestination.pipelines: AppRoute.settings},
);
final app = await mount(tester, route: '/?preview=1', store: store);
await tester.pumpAndSettle();
expect(app.provider.value.uri.path, '/settings');
expect(find.byType(SettingsScreen), findsOneWidget);
expect(tester.takeException(), isNull);
});
}