Merge branch 'main' into flutter/pipeline-stage-deeplink
This commit is contained in:
@@ -49,4 +49,55 @@ void main() {
|
||||
router.closeTemplates();
|
||||
expect(router.route, AppRoute.settings);
|
||||
});
|
||||
|
||||
test('the parser keeps a query and restores it as a query', () async {
|
||||
const parser = AppRouteParser();
|
||||
final route = await parser.parseRouteInformation(
|
||||
RouteInformation(uri: Uri.parse('/runs/77/stage/plan?visit=1')),
|
||||
);
|
||||
expect(route, AppRoute.run.stage(77, 'plan', visit: 1));
|
||||
|
||||
final restored = parser.restoreRouteInformation(route).uri;
|
||||
expect(restored.path, '/runs/77/stage/plan');
|
||||
expect(restored.query, 'visit=1');
|
||||
expect(restored.toString(), '/runs/77/stage/plan?visit=1');
|
||||
// A reload or Back/Forward feeds the restored location straight back in.
|
||||
expect(AppRoute.parse(restored.toString()), route);
|
||||
});
|
||||
|
||||
test('every query route survives a restore and reparse', () {
|
||||
const parser = AppRouteParser();
|
||||
for (final route in [
|
||||
AppRoute.runsForPipeline(7),
|
||||
AppRoute.run.decide(3),
|
||||
AppRoute.run.stage(3, 'plan', visit: 0),
|
||||
AppRoute.run.stage(5, 'build ✓', visit: 4),
|
||||
]) {
|
||||
final uri = parser.restoreRouteInformation(route).uri;
|
||||
expect(uri.toString(), route.path, reason: route.path);
|
||||
expect(uri.path, isNot(contains('%3F')), reason: route.path);
|
||||
expect(AppRoute.parse(uri.toString()), route, reason: route.path);
|
||||
}
|
||||
});
|
||||
|
||||
test('a web launch keeps the path and its query', () {
|
||||
final visit = routeInformationForLocation(
|
||||
Uri.parse('https://example.test/runs/7/stage/plan?visit=2'),
|
||||
);
|
||||
expect(visit.uri.toString(), '/runs/7/stage/plan?visit=2');
|
||||
expect(visit.uri.path, '/runs/7/stage/plan');
|
||||
expect(visit.uri.query, 'visit=2');
|
||||
|
||||
final decide = routeInformationForLocation(
|
||||
Uri.parse('https://example.test/runs/9?action=decide'),
|
||||
);
|
||||
expect(decide.uri.toString(), '/runs/9?action=decide');
|
||||
|
||||
expect(
|
||||
routeInformationForLocation(
|
||||
Uri.parse('https://example.test/'),
|
||||
).uri.toString(),
|
||||
'/',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/app_route.dart';
|
||||
import 'package:pipelines_app/application/app_router.dart';
|
||||
import 'package:pipelines_app/application/pipelines_app.dart';
|
||||
import 'package:pipelines_app/application/server_endpoint.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
@@ -84,6 +86,57 @@ Future<void> replyDetail(
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
/// A run whose plan visits are deliberately not in sequence order, so a route
|
||||
/// visit index must follow the recorded sequence, not the reply's row order.
|
||||
Future<void> replyVisitDetail(
|
||||
WidgetTester tester,
|
||||
FakeChannel channel,
|
||||
num id,
|
||||
) async {
|
||||
for (
|
||||
var attempt = 0;
|
||||
attempt < 40 && requestOf(channel, 'get_run') == null;
|
||||
attempt++
|
||||
) {
|
||||
await tester.pump(const Duration(milliseconds: 5));
|
||||
}
|
||||
final request = requestOf(channel, 'get_run')!;
|
||||
expect(request['run_id'], id);
|
||||
channel.incoming.add(
|
||||
jsonEncode({
|
||||
'id': request['id'],
|
||||
'type': 'run',
|
||||
'run_detail': {
|
||||
'id': id,
|
||||
'title': 'Deep link run',
|
||||
'name': 'release',
|
||||
'status': 'succeeded',
|
||||
'graph': {
|
||||
'stages': [
|
||||
{
|
||||
'key': 'plan',
|
||||
'type': 'model',
|
||||
'edges': {'success': 'build'},
|
||||
},
|
||||
{
|
||||
'key': 'build',
|
||||
'type': 'model',
|
||||
'edges': {'success': '#success'},
|
||||
},
|
||||
],
|
||||
},
|
||||
'steps': [
|
||||
{'stage': 'plan', 'sequence': 5, 'status': 'completed'},
|
||||
{'stage': 'build', 'sequence': 2, 'status': 'completed'},
|
||||
{'stage': 'plan', 'sequence': 1, 'status': 'completed'},
|
||||
],
|
||||
},
|
||||
}),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('a /runs/1 boot link opens that run and Back returns to /runs', (
|
||||
tester,
|
||||
@@ -195,4 +248,47 @@ void main() {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pump();
|
||||
});
|
||||
|
||||
testWidgets('a queried stage boot link opens that exact recorded visit', (
|
||||
tester,
|
||||
) async {
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(
|
||||
uri: Uri.parse('/runs/77/stage/plan?visit=0'),
|
||||
),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
|
||||
await pumpApp(tester, channel: channel, client: client, provider: provider);
|
||||
await replyList(
|
||||
tester,
|
||||
channel,
|
||||
runs: [
|
||||
{'id': 77, 'name': 'Deep link run', 'status': 'succeeded'},
|
||||
],
|
||||
);
|
||||
await replyVisitDetail(tester, channel, 77);
|
||||
|
||||
// The query reached the detail: visit 0 is the earlier plan visit (seq 1),
|
||||
// not the latest one the pane would show without a visit.
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
|
||||
expect(find.text('plan · visit 1'), findsOneWidget);
|
||||
expect(find.text('plan · visit 5'), findsNothing);
|
||||
expect(provider.value.uri.toString(), '/runs/77/stage/plan?visit=0');
|
||||
|
||||
// A history entry the app itself writes is parsed back as a query, so
|
||||
// Back/Forward (and a reload) open the visit instead of a bogus stage key.
|
||||
final restored = const AppRouteParser()
|
||||
.restoreRouteInformation(AppRoute.run.stage(77, 'plan', visit: 1))
|
||||
.uri;
|
||||
expect(restored.toString(), '/runs/77/stage/plan?visit=1');
|
||||
await provider.didPushRouteInformation(RouteInformation(uri: restored));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.text('plan · visit 5'), findsOneWidget);
|
||||
expect(provider.value.uri.path, '/runs/77/stage/plan');
|
||||
expect(provider.value.uri.query, 'visit=1');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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/chat/conversation/chat_composer_bar.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_attachment_draft.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_attachment_picker.dart';
|
||||
|
||||
import 'chat_composer_bar_fixtures.dart';
|
||||
|
||||
/// A picker whose selections are supplied by the test, one call at a time.
|
||||
class _FakePicker {
|
||||
_FakePicker(this.results);
|
||||
|
||||
final List<List<ChatPickedFile>?> results;
|
||||
int calls = 0;
|
||||
|
||||
ChatAttachmentPicker get picker => ChatAttachmentPicker(
|
||||
select: () async {
|
||||
calls += 1;
|
||||
return results.isEmpty ? null : results.removeAt(0);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
ChatPickedFile _file(String name, {int size = 3, String mime = 'text/plain'}) =>
|
||||
ChatPickedFile(name: name, mime: mime, bytes: Uint8List(size));
|
||||
|
||||
Widget _host(Widget bar, {required bool cupertino}) => cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: bar))
|
||||
: materialHost(bar);
|
||||
|
||||
void main() {
|
||||
late ComposerBarGateway gateway;
|
||||
late ChatComposerController composer;
|
||||
late List<ChatComposerController> controllers;
|
||||
|
||||
setUp(() {
|
||||
gateway = ComposerBarGateway();
|
||||
controllers = [];
|
||||
});
|
||||
|
||||
/// Created inside the test body so the controller's futures belong to the
|
||||
/// widget tester's clock rather than to `setUp`'s.
|
||||
ChatComposerController newComposer() {
|
||||
final controller = ChatComposerController(
|
||||
gateway,
|
||||
's',
|
||||
drafts: MemoryChatDraftStore(),
|
||||
);
|
||||
controllers.add(controller);
|
||||
composer = controller;
|
||||
return controller;
|
||||
}
|
||||
|
||||
tearDown(() {
|
||||
for (final controller in controllers) {
|
||||
controller.dispose();
|
||||
}
|
||||
gateway.close();
|
||||
});
|
||||
|
||||
Future<void> pumpBar(
|
||||
WidgetTester tester, {
|
||||
ChatAttachmentPicker? picker,
|
||||
bool cupertino = false,
|
||||
}) async {
|
||||
newComposer();
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ChatComposerBar(composer: composer, running: false, picker: picker),
|
||||
cupertino: cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('picking a file shows its recorded name and removes it '
|
||||
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
|
||||
final fake = _FakePicker([
|
||||
[_file('notes.txt')],
|
||||
]);
|
||||
await pumpBar(tester, picker: fake.picker, cupertino: cupertino);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-composer-attach')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(fake.calls, 1);
|
||||
expect(
|
||||
find.byKey(const Key('chat-composer-attachments')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('notes.txt'), findsOneWidget);
|
||||
|
||||
if (cupertino) {
|
||||
await tester.tap(
|
||||
find.byKey(const Key('chat-composer-attachment-remove-0')),
|
||||
);
|
||||
} else {
|
||||
await tester.tap(find.byTooltip('Remove notes.txt'));
|
||||
}
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('notes.txt'), findsNothing);
|
||||
expect(find.byKey(const Key('chat-composer-attachments')), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('a file over the draft budget shows the draft refusal line', (
|
||||
tester,
|
||||
) async {
|
||||
final fake = _FakePicker([
|
||||
[
|
||||
_file(
|
||||
'huge.bin',
|
||||
size: ChatAttachmentDraft.maxTotalBytes + 1,
|
||||
mime: 'application/octet-stream',
|
||||
),
|
||||
],
|
||||
]);
|
||||
await pumpBar(tester, picker: fake.picker);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-composer-attach')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.text(ChatAttachmentRefusal.totalTooLarge.message),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byKey(const Key('chat-composer-attachments')), findsNothing);
|
||||
expect(find.text('huge.bin'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('attachments survive a normal parent rebuild', (tester) async {
|
||||
newComposer();
|
||||
final fake = _FakePicker([
|
||||
[_file('keep me.pdf', mime: 'application/pdf')],
|
||||
]);
|
||||
var rebuilt = false;
|
||||
late StateSetter rebuild;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
rebuild = setState;
|
||||
return ChatComposerBar(
|
||||
composer: composer,
|
||||
running: rebuilt,
|
||||
picker: fake.picker,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-composer-attach')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('keep me.pdf'), findsOneWidget);
|
||||
|
||||
rebuild(() => rebuilt = true);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('keep me.pdf'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-composer-attachments')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the attach control is disabled while a prompt is in flight', (
|
||||
tester,
|
||||
) async {
|
||||
final reply = Completer<JsonMap>();
|
||||
gateway.prompt = (_, _) => reply.future;
|
||||
final fake = _FakePicker([
|
||||
[_file('notes.txt')],
|
||||
]);
|
||||
await pumpBar(tester, picker: fake.picker);
|
||||
|
||||
IconButton attach() => tester.widget<IconButton>(
|
||||
find.byKey(const Key('chat-composer-attach')),
|
||||
);
|
||||
expect(attach().onPressed, isNotNull);
|
||||
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
'hello',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(attach().onPressed, isNull);
|
||||
expect(gateway.promptBodies, hasLength(1));
|
||||
|
||||
reply.complete(const {});
|
||||
await tester.pumpAndSettle();
|
||||
expect(attach().onPressed, isNotNull);
|
||||
});
|
||||
|
||||
testWidgets('the attach control is disabled without a host picker', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpBar(tester);
|
||||
|
||||
final attach = tester.widget<IconButton>(
|
||||
find.byKey(const Key('chat-composer-attach')),
|
||||
);
|
||||
expect(attach.onPressed, isNull);
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('a long attachment name fits a narrow 2x composer '
|
||||
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
|
||||
tester.view.physicalSize = const Size(640, 1200);
|
||||
tester.view.devicePixelRatio = 2;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
|
||||
final name =
|
||||
'a-very-long-recorded-attachment-name-that-must-not-overflow.pdf';
|
||||
final fake = _FakePicker([
|
||||
[_file(name)],
|
||||
]);
|
||||
await pumpBar(tester, picker: fake.picker, cupertino: cupertino);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-composer-attach')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.text(name), findsOneWidget);
|
||||
expect(
|
||||
find.byKey(const Key('chat-composer-attachments')),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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/chat/conversation/chat_thread_view.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
Widget _host(Widget child) => MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
|
||||
Widget _cupertinoHost(Widget child) => CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
||||
home: CupertinoPageScaffold(child: child),
|
||||
);
|
||||
|
||||
JsonMap _usageFrame(JsonMap usage) => {
|
||||
'session_id': 's',
|
||||
'kind': 'usage',
|
||||
'usage': usage,
|
||||
};
|
||||
|
||||
Future<FakeChatGateway> _thread(
|
||||
WidgetTester tester, {
|
||||
bool cupertino = false,
|
||||
}) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => chatPage([]);
|
||||
final thread = ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: 's',
|
||||
onBack: () {},
|
||||
);
|
||||
await tester.pumpWidget(cupertino ? _cupertinoHost(thread) : _host(thread));
|
||||
await tester.pumpAndSettle();
|
||||
return gateway;
|
||||
}
|
||||
|
||||
Future<void> _openInfo(WidgetTester tester) async {
|
||||
await tester.tap(find.byKey(const Key('chat-info')));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('reports the recorded facts with the web labels', (tester) async {
|
||||
final gateway = await _thread(tester);
|
||||
gateway.emitEvent(
|
||||
_usageFrame({
|
||||
'scope': 'session',
|
||||
'total_tokens': 132408,
|
||||
'context_tokens': 42000,
|
||||
'context_window': 200000,
|
||||
'cost_usd': 0.1423,
|
||||
'output_tokens_per_second': 24.6,
|
||||
'rate_basis': 'generation',
|
||||
}),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
await _openInfo(tester);
|
||||
|
||||
expect(find.text('Chat information'), findsOneWidget);
|
||||
expect(find.text('Output rate'), findsOneWidget);
|
||||
expect(find.text('24.6 tok/s'), findsOneWidget);
|
||||
expect(find.text('Total tokens'), findsOneWidget);
|
||||
expect(find.text('132,408'), findsOneWidget);
|
||||
expect(find.text('Context'), findsOneWidget);
|
||||
expect(find.text('42,000 / 200,000'), findsOneWidget);
|
||||
expect(find.text('Reported cost'), findsOneWidget);
|
||||
expect(find.text('\$0.1423'), findsOneWidget);
|
||||
expect(
|
||||
find.text(
|
||||
'Last reported by the harness. '
|
||||
'Unavailable values are not estimated.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// A snapshot that arrives while the panel is open replaces the shown one.
|
||||
gateway.emitEvent(
|
||||
_usageFrame({
|
||||
'scope': 'turn',
|
||||
'total_tokens': 133000,
|
||||
'context_tokens': 3000,
|
||||
'context_window': 200000,
|
||||
'cost_usd': 0.2,
|
||||
'output_tokens_per_second': 10,
|
||||
'rate_basis': 'turn',
|
||||
}),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Turn tokens'), findsOneWidget);
|
||||
expect(find.text('133,000'), findsOneWidget);
|
||||
expect(find.text('Avg output rate'), findsOneWidget);
|
||||
expect(find.text('10 tok/s'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('unknown facts say Unavailable while reported zeros stay zero', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = await _thread(tester);
|
||||
gateway.emitEvent(_usageFrame({'scope': 'session'}));
|
||||
await tester.pump();
|
||||
|
||||
await _openInfo(tester);
|
||||
|
||||
expect(find.text('Unavailable'), findsNWidgets(4));
|
||||
expect(find.text('0'), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-info-close')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
gateway.emitEvent(
|
||||
_usageFrame({
|
||||
'scope': 'session',
|
||||
'total_tokens': 0,
|
||||
'context_tokens': 0,
|
||||
'context_window': 1000,
|
||||
'cost_usd': 0,
|
||||
'output_tokens_per_second': 0,
|
||||
}),
|
||||
);
|
||||
await tester.pump();
|
||||
await _openInfo(tester);
|
||||
|
||||
expect(find.text('Unavailable'), findsNothing);
|
||||
expect(find.text('0 tok/s'), findsOneWidget);
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
expect(find.text('0 / 1,000'), findsOneWidget);
|
||||
expect(find.text('\$0.0000'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the native sheet dismisses from Close and the barrier', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = await _thread(tester);
|
||||
gateway.emitEvent(_usageFrame({'scope': 'session', 'total_tokens': 5}));
|
||||
await tester.pump();
|
||||
|
||||
await _openInfo(tester);
|
||||
expect(find.byKey(const Key('chat-info-sheet')), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-info-close')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-info-sheet')), findsNothing);
|
||||
expect(find.byKey(const Key('chat-info')), findsOneWidget);
|
||||
|
||||
await _openInfo(tester);
|
||||
expect(find.byKey(const Key('chat-info-sheet')), findsOneWidget);
|
||||
|
||||
// The modal barrier above the sheet is the platform's dismiss target.
|
||||
await tester.tapAt(const Offset(8, 8));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-info-sheet')), findsNothing);
|
||||
expect(find.byKey(const Key('chat-info')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the Cupertino host opens and closes the native popup', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = await _thread(tester, cupertino: true);
|
||||
gateway.emitEvent(_usageFrame({'scope': 'session', 'total_tokens': 42}));
|
||||
await tester.pump();
|
||||
|
||||
await _openInfo(tester);
|
||||
expect(find.text('Chat information'), findsOneWidget);
|
||||
expect(find.text('42'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-info-close')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-info-sheet')), findsNothing);
|
||||
expect(find.byKey(const Key('chat-info')), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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/graph/widgets/run_graph_view.dart';
|
||||
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
|
||||
import 'package:pipelines_app/features/runs/screen.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_tab.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
|
||||
|
||||
import 'run_detail_graph_support.dart';
|
||||
|
||||
/// plan -> build -> audit, with two recorded plan visits and one build visit.
|
||||
///
|
||||
/// The steps are deliberately not in sequence order, so a stage visit index
|
||||
/// must follow the visit's recorded sequence while the row index follows the
|
||||
/// timeline's step order.
|
||||
JsonMap deepLinkRunFixture() => <String, dynamic>{
|
||||
'id': 77,
|
||||
'title': 'Deep link run',
|
||||
'name': 'release',
|
||||
'status': 'succeeded',
|
||||
'input': <String, dynamic>{'prompt': 'ship it'},
|
||||
'graph': <String, dynamic>{
|
||||
'stages': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'key': 'plan',
|
||||
'type': 'model',
|
||||
'edges': <String, String?>{'success': 'build', 'error': '#'},
|
||||
},
|
||||
<String, dynamic>{
|
||||
'key': 'build',
|
||||
'type': 'model',
|
||||
'edges': <String, String?>{'success': 'audit', 'error': '#'},
|
||||
},
|
||||
<String, dynamic>{
|
||||
'key': 'audit',
|
||||
'type': 'model',
|
||||
'edges': <String, String?>{'success': '#success'},
|
||||
},
|
||||
],
|
||||
},
|
||||
'steps': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'stage': 'plan',
|
||||
'sequence': 5,
|
||||
'status': 'completed',
|
||||
'outcome': 'success',
|
||||
},
|
||||
<String, dynamic>{
|
||||
'stage': 'build',
|
||||
'sequence': 2,
|
||||
'status': 'completed',
|
||||
'outcome': 'success',
|
||||
},
|
||||
<String, dynamic>{
|
||||
'stage': 'plan',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'outcome': 'success',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
Future<void> pumpDeepLink(
|
||||
WidgetTester tester,
|
||||
RunDetailTestPlatform platform, {
|
||||
String? stage,
|
||||
int? visit,
|
||||
JsonMap? run,
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(900, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = RunDetailFakeGateway(run ?? deepLinkRunFixture());
|
||||
final controller = RunsController(RunsRepository(gateway));
|
||||
addTearDown(controller.dispose);
|
||||
await controller.select(77);
|
||||
final view = RunDetailView(
|
||||
controller: controller,
|
||||
gateway: gateway,
|
||||
onBack: () {},
|
||||
initialStageKey: stage,
|
||||
initialVisit: visit,
|
||||
);
|
||||
final page = MediaQuery(
|
||||
data: MediaQueryData.fromView(tester.view),
|
||||
child: view,
|
||||
);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pumpWidget(
|
||||
platform == RunDetailTestPlatform.material
|
||||
? MaterialApp(home: Scaffold(body: page))
|
||||
: CupertinoApp(
|
||||
home: CupertinoPageScaffold(child: SafeArea(child: page)),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
/// The Runs screen's own request seam: a route-named run opens through the same
|
||||
/// list-then-detail read the shell performs.
|
||||
class _ScreenGateway implements ApiGateway {
|
||||
final _frames = StreamController<JsonMap>.broadcast();
|
||||
final listRequests = <Completer<JsonMap>>[];
|
||||
final detailRequests = <Completer<JsonMap>>[];
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => _frames.stream;
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
final request = Completer<JsonMap>();
|
||||
if (type == 'list_runs') {
|
||||
listRequests.add(request);
|
||||
} else if (type == 'get_run') {
|
||||
detailRequests.add(request);
|
||||
} else {
|
||||
request.completeError(UnsupportedError(type));
|
||||
}
|
||||
return request.future;
|
||||
}
|
||||
|
||||
void close() => _frames.close();
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final platform in RunDetailTestPlatform.values) {
|
||||
testWidgets('${platform.name} stage visit opens that recorded visit', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpDeepLink(tester, platform, stage: 'plan', visit: 0);
|
||||
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
|
||||
expect(find.text('plan · visit 1'), findsOneWidget);
|
||||
expect(find.text('plan · visit 5'), findsNothing);
|
||||
expect(
|
||||
find.byKey(const Key('run-detail-tab-body-timeline')),
|
||||
findsWidgets,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('${platform.name} unknown stage opens the plain detail', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpDeepLink(tester, platform, stage: 'missing', visit: 2);
|
||||
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsNothing);
|
||||
expect(
|
||||
find.byKey(const Key('run-detail-tab-body-summary')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Deep link run'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('${platform.name} no stage key keeps the plain detail', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpDeepLink(tester, platform);
|
||||
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsNothing);
|
||||
expect(
|
||||
find.byKey(const Key('run-detail-tab-body-summary')),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('a stage key without a visit opens that stage latest visit', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpDeepLink(tester, RunDetailTestPlatform.material, stage: 'plan');
|
||||
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
|
||||
expect(find.text('plan · visit 5'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a Graph click opens the same latest visit as the stage route', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpDeepLink(tester, RunDetailTestPlatform.material);
|
||||
await openRunDetailTab(tester, RunDetailTab.graph);
|
||||
await tapGraphNode(tester, 'plan');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The web client's graph click takes the last visit in sequence order, not
|
||||
// the last row in reply order, so both entry points agree.
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
|
||||
expect(find.text('plan · visit 5'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('an out-of-range visit is clamped to the stage last visit', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpDeepLink(
|
||||
tester,
|
||||
RunDetailTestPlatform.material,
|
||||
stage: 'plan',
|
||||
visit: 9,
|
||||
);
|
||||
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
|
||||
expect(find.text('plan · visit 5'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a declared but unvisited stage selects its graph node', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpDeepLink(tester, RunDetailTestPlatform.material, stage: 'audit');
|
||||
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsNothing);
|
||||
expect(find.byKey(const Key('run-detail-graph')), findsOneWidget);
|
||||
final graph = tester.widget<RunGraphView>(
|
||||
find.byKey(const Key('run-detail-graph')),
|
||||
);
|
||||
expect(graph.selectedStage, 'audit');
|
||||
});
|
||||
|
||||
testWidgets('the Runs screen forwards the route stage and visit', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _ScreenGateway();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunsScreen(
|
||||
gateway: gateway,
|
||||
initialRunId: 77,
|
||||
initialStageKey: 'plan',
|
||||
initialVisit: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
gateway.listRequests.single.complete({
|
||||
'runs': [
|
||||
{'id': 77, 'title': 'Deep link run', 'status': 'succeeded'},
|
||||
],
|
||||
});
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
gateway.detailRequests.single.complete({
|
||||
'run_detail': deepLinkRunFixture(),
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
|
||||
expect(find.text('plan · visit 5'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a route change applies its visit and a plain route closes it', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(900, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = RunDetailFakeGateway(deepLinkRunFixture());
|
||||
final controller = RunsController(RunsRepository(gateway));
|
||||
addTearDown(controller.dispose);
|
||||
await controller.select(77);
|
||||
String? stage = 'plan';
|
||||
int? visit = 0;
|
||||
late StateSetter rebuild;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
rebuild = setState;
|
||||
return MediaQuery(
|
||||
data: MediaQueryData.fromView(tester.view),
|
||||
child: RunDetailView(
|
||||
controller: controller,
|
||||
gateway: gateway,
|
||||
onBack: () {},
|
||||
initialStageKey: stage,
|
||||
initialVisit: visit,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('plan · visit 1'), findsOneWidget);
|
||||
|
||||
rebuild(() => visit = 1);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('plan · visit 5'), findsOneWidget);
|
||||
|
||||
rebuild(() => stage = null);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_session.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_session_state.dart';
|
||||
|
||||
import 'run_detail_graph_support.dart';
|
||||
import 'run_detail_visit_support.dart';
|
||||
|
||||
Future<void> pumpSessionExport(WidgetTester tester, JsonMap step) =>
|
||||
@@ -11,7 +12,10 @@ Future<void> pumpSessionExport(WidgetTester tester, JsonMap step) =>
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunVisitSession(
|
||||
run: visitRunFor(step),
|
||||
step: step,
|
||||
gateway: RunDetailFakeGateway(visitRunFor(step)),
|
||||
onRunChanged: (_) {},
|
||||
configuredEndpoint: 'ws://example.test/connect',
|
||||
),
|
||||
),
|
||||
|
||||
@@ -19,6 +19,8 @@ void main() {
|
||||
|
||||
expect(find.text('sess-1'), findsOneWidget);
|
||||
expect(find.text('Open session.html'), findsOneWidget);
|
||||
// No recorded export evidence, so the web offers no export-only repair.
|
||||
expect(find.text('Retry export only'), findsNothing);
|
||||
expect(
|
||||
find.textContaining('not available in the artifact inventory'),
|
||||
findsNothing,
|
||||
@@ -69,7 +71,13 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunVisitSession(step: step, configuredEndpoint: ''),
|
||||
body: RunVisitSession(
|
||||
run: visitRunFor(step),
|
||||
step: step,
|
||||
gateway: RunDetailFakeGateway(visitRunFor(step)),
|
||||
onRunChanged: (_) {},
|
||||
configuredEndpoint: '',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -79,6 +87,8 @@ void main() {
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.textContaining('Open '), findsNothing);
|
||||
// No openable document at all is the web's other repair branch.
|
||||
expect(find.text('Retry export only'), findsOneWidget);
|
||||
|
||||
step['session_export'] = <String, dynamic>{
|
||||
'html': 'session.html',
|
||||
@@ -88,7 +98,13 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunVisitSession(step: step, configuredEndpoint: ''),
|
||||
body: RunVisitSession(
|
||||
run: visitRunFor(step),
|
||||
step: step,
|
||||
gateway: RunDetailFakeGateway(visitRunFor(step)),
|
||||
onRunChanged: (_) {},
|
||||
configuredEndpoint: '',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -108,7 +124,10 @@ void main() {
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunVisitSession(
|
||||
run: visitRunFixture(),
|
||||
step: firstVisitStep(visitRunFixture()),
|
||||
gateway: RunDetailFakeGateway(visitRunFixture()),
|
||||
onRunChanged: (_) {},
|
||||
configuredEndpoint: 'ws://example.test/connect',
|
||||
openExternal: (uri) async {
|
||||
opened = uri;
|
||||
@@ -131,7 +150,10 @@ void main() {
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunVisitSession(
|
||||
run: visitRunFixture(),
|
||||
step: firstVisitStep(visitRunFixture()),
|
||||
gateway: RunDetailFakeGateway(visitRunFixture()),
|
||||
onRunChanged: (_) {},
|
||||
configuredEndpoint: 'ws://example.test/connect',
|
||||
openExternal: (uri) async => false,
|
||||
),
|
||||
|
||||
@@ -82,6 +82,14 @@ JsonMap visitRunFixture({
|
||||
JsonMap firstVisitStep(JsonMap run) =>
|
||||
(run['steps'] as List).first as Map<String, dynamic>;
|
||||
|
||||
/// The run that owns [step], for direct session-pane pumps outside the detail.
|
||||
JsonMap visitRunFor(JsonMap step, {String status = 'succeeded'}) =>
|
||||
<String, dynamic>{
|
||||
'id': 77,
|
||||
'status': status,
|
||||
'steps': <dynamic>[step],
|
||||
};
|
||||
|
||||
Future<void> openVisit(
|
||||
WidgetTester tester,
|
||||
RunDetailTestPlatform platform, {
|
||||
|
||||
@@ -95,7 +95,13 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunVisitSession(step: step, configuredEndpoint: ''),
|
||||
body: RunVisitSession(
|
||||
run: visitRunFor(step),
|
||||
step: step,
|
||||
gateway: RunDetailFakeGateway(visitRunFor(step)),
|
||||
onRunChanged: (_) {},
|
||||
configuredEndpoint: '',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,271 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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/runs/actions/session_export_repair_action.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_session.dart';
|
||||
|
||||
import 'run_detail_visit_support.dart';
|
||||
|
||||
typedef _RepairHandler = Future<JsonMap> Function(String type, JsonMap fields);
|
||||
|
||||
class _RepairGateway implements ApiGateway {
|
||||
_RepairGateway(this.handler);
|
||||
|
||||
final _RepairHandler handler;
|
||||
final List<({String type, JsonMap fields})> calls = [];
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
final copy = Map<String, dynamic>.from(fields);
|
||||
calls.add((type: type, fields: copy));
|
||||
return handler(type, copy);
|
||||
}
|
||||
|
||||
Iterable<({String type, JsonMap fields})> get repairs =>
|
||||
calls.where((call) => call.type == 'repair_session_export');
|
||||
}
|
||||
|
||||
/// A recorded visit whose export failed, so the repair option is offered.
|
||||
JsonMap partialRun() {
|
||||
final run = visitRunFixture();
|
||||
final step = firstVisitStep(run);
|
||||
step['session_export'] = <String, dynamic>{
|
||||
'html': 'session.html',
|
||||
'status': 'failed',
|
||||
'messages': 0,
|
||||
'diagnostic': 'The first export failed.',
|
||||
};
|
||||
return run;
|
||||
}
|
||||
|
||||
/// A reply whose recorded repair is verified complete and openable.
|
||||
JsonMap repairedRun() {
|
||||
final run = visitRunFixture();
|
||||
final step = firstVisitStep(run);
|
||||
step['session_export_repairs'] = <dynamic>[
|
||||
<String, dynamic>{
|
||||
'html': 'session-repair-1.html',
|
||||
'status': 'complete',
|
||||
'messages': 3,
|
||||
'html_bytes': 900,
|
||||
},
|
||||
];
|
||||
(step['artifacts'] as List).add(<String, dynamic>{
|
||||
'name': 'session-repair-1.html',
|
||||
'url': 'https://example.test/artifacts/session-repair-1.html',
|
||||
'content_type': 'text/html',
|
||||
'size_bytes': 900,
|
||||
});
|
||||
return run;
|
||||
}
|
||||
|
||||
class _SessionHost extends StatefulWidget {
|
||||
const _SessionHost({required this.run, required this.gateway});
|
||||
|
||||
final JsonMap run;
|
||||
final _RepairGateway gateway;
|
||||
|
||||
@override
|
||||
State<_SessionHost> createState() => _SessionHostState();
|
||||
}
|
||||
|
||||
class _SessionHostState extends State<_SessionHost> {
|
||||
late JsonMap _run = widget.run;
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant _SessionHost oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
// A test that swaps the recorded run must show the new visit, exactly as
|
||||
// the detail does when the operator selects another one.
|
||||
if (!identical(widget.run, oldWidget.run)) _run = widget.run;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => RunVisitSession(
|
||||
run: _run,
|
||||
step: firstVisitStep(_run),
|
||||
gateway: widget.gateway,
|
||||
onRunChanged: (detail) => setState(() => _run = detail),
|
||||
configuredEndpoint: 'ws://example.test/connect',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _pumpSession(
|
||||
WidgetTester tester,
|
||||
_RepairGateway gateway, {
|
||||
JsonMap? run,
|
||||
bool cupertino = false,
|
||||
}) {
|
||||
final host = _SessionHost(run: run ?? partialRun(), gateway: gateway);
|
||||
return tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
home: CupertinoPageScaffold(child: SafeArea(child: host)),
|
||||
)
|
||||
: MaterialApp(home: Scaffold(body: host)),
|
||||
);
|
||||
}
|
||||
|
||||
TextButton _materialButton(WidgetTester tester) => tester.widget<TextButton>(
|
||||
find.widgetWithText(TextButton, 'Retry export only'),
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets('sends the recorded run and visit exactly once', (tester) async {
|
||||
final reply = Completer<JsonMap>();
|
||||
final gateway = _RepairGateway((_, _) => reply.future);
|
||||
await _pumpSession(tester, gateway);
|
||||
|
||||
expect(find.text('Retry export only'), findsOneWidget);
|
||||
await tester.tap(find.text('Retry export only'));
|
||||
await tester.pump();
|
||||
|
||||
expect(gateway.repairs, hasLength(1));
|
||||
expect(gateway.repairs.single.fields, {'run_id': 77, 'export_sequence': 1});
|
||||
// Nothing but the one repair request is sent.
|
||||
expect(gateway.calls.map((call) => call.type), ['repair_session_export']);
|
||||
// The recorded export state is kept until the server replies.
|
||||
expect(find.text('partial'), findsOneWidget);
|
||||
expect(find.text('complete'), findsNothing);
|
||||
expect(find.text('Exporting…'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Exporting…'), warnIfMissed: false);
|
||||
await tester.pump();
|
||||
expect(gateway.repairs, hasLength(1));
|
||||
|
||||
reply.complete({'run_detail': repairedRun()});
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The accepted reply names the verified repair the pane must now show.
|
||||
expect(find.text('repair'), findsOneWidget);
|
||||
expect(find.text('complete · 3 messages.'), findsOneWidget);
|
||||
expect(find.text('Open session-repair-1.html'), findsOneWidget);
|
||||
expect(find.text('Retry export only'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a refusal is shown and the recorded state is unchanged', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _RepairGateway(
|
||||
(_, _) => Future<JsonMap>.error(StateError('The session is gone.')),
|
||||
);
|
||||
await _pumpSession(tester, gateway);
|
||||
|
||||
await tester.tap(find.text('Retry export only'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(sessionExportRepairErrorKey), findsOneWidget);
|
||||
expect(find.text('The session is gone.'), findsOneWidget);
|
||||
expect(find.text('partial'), findsOneWidget);
|
||||
expect(find.text('complete'), findsNothing);
|
||||
// The option is still available: a refusal is not a success.
|
||||
expect(find.text('Retry export only'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a legacy session.html with no recorded evidence keeps no '
|
||||
'control', (tester) async {
|
||||
final gateway = _RepairGateway(
|
||||
(_, _) => Future<JsonMap>.error(StateError('unexpected')),
|
||||
);
|
||||
final run = partialRun();
|
||||
firstVisitStep(run).remove('session_export');
|
||||
await _pumpSession(tester, gateway, run: run);
|
||||
|
||||
// The document still opens, but there is no evidence to repair.
|
||||
expect(find.text('Open session.html'), findsOneWidget);
|
||||
expect(find.text('Retry export only'), findsNothing);
|
||||
expect(gateway.calls, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('a verified complete export offers no repair', (tester) async {
|
||||
final gateway = _RepairGateway(
|
||||
(_, _) => Future<JsonMap>.error(StateError('unexpected')),
|
||||
);
|
||||
await _pumpSession(tester, gateway, run: visitRunFixture());
|
||||
|
||||
expect(find.text('complete'), findsOneWidget);
|
||||
expect(find.text('Retry export only'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the control is disabled while the visit or run is active', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _RepairGateway(
|
||||
(_, _) => Future<JsonMap>.error(StateError('unexpected')),
|
||||
);
|
||||
|
||||
final active = partialRun();
|
||||
firstVisitStep(active)['agent_active'] = true;
|
||||
await _pumpSession(tester, gateway, run: active);
|
||||
expect(find.text('Retry export only'), findsOneWidget);
|
||||
expect(_materialButton(tester).onPressed, isNull);
|
||||
|
||||
final waiting = partialRun();
|
||||
waiting['status'] = 'waiting';
|
||||
waiting['export_pending_sequence'] = 2;
|
||||
await _pumpSession(tester, gateway, run: waiting);
|
||||
expect(_materialButton(tester).onPressed, isNull);
|
||||
|
||||
// The same wait allows the repair when this visit's export is the pending
|
||||
// one, exactly as the web client's availability check does.
|
||||
waiting['export_pending_sequence'] = 1;
|
||||
await _pumpSession(tester, gateway, run: waiting);
|
||||
expect(_materialButton(tester).onPressed, isNotNull);
|
||||
});
|
||||
|
||||
testWidgets('changing visits clears a pending repair and its reply', (
|
||||
tester,
|
||||
) async {
|
||||
final first = Completer<JsonMap>();
|
||||
final second = Completer<JsonMap>();
|
||||
final gateway = _RepairGateway(
|
||||
(_, fields) =>
|
||||
fields['export_sequence'] == 1 ? first.future : second.future,
|
||||
);
|
||||
await _pumpSession(tester, gateway);
|
||||
|
||||
await tester.tap(find.text('Retry export only'));
|
||||
await tester.pump();
|
||||
expect(find.text('Exporting…'), findsOneWidget);
|
||||
|
||||
final next = partialRun();
|
||||
firstVisitStep(next)['sequence'] = 2;
|
||||
await _pumpSession(tester, gateway, run: next);
|
||||
expect(find.text('Retry export only'), findsOneWidget);
|
||||
expect(find.text('Exporting…'), findsNothing);
|
||||
|
||||
await tester.tap(find.text('Retry export only'));
|
||||
await tester.pump();
|
||||
expect(gateway.repairs.map((call) => call.fields['export_sequence']), [
|
||||
1,
|
||||
2,
|
||||
]);
|
||||
|
||||
// The first visit's late reply is not folded into the second visit.
|
||||
first.complete({'run_detail': repairedRun()});
|
||||
await tester.pump();
|
||||
expect(find.text('repair'), findsNothing);
|
||||
expect(find.text('partial'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the Cupertino host uses a native Cupertino button', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _RepairGateway(
|
||||
(_, _) => Future<JsonMap>.error(StateError('unexpected')),
|
||||
);
|
||||
await _pumpSession(tester, gateway, cupertino: true);
|
||||
|
||||
expect(
|
||||
find.widgetWithText(CupertinoButton, 'Retry export only'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.widgetWithText(TextButton, 'Retry export only'), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user