Merge branch 'main' into flutter/chat-cmd-stop

This commit is contained in:
2026-10-22 22:22:44 +01:00
48 changed files with 3777 additions and 89 deletions
@@ -0,0 +1,101 @@
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/application/app_route.dart';
import 'package:pipelines_app/features/attention/notify/chat_question_notices.dart';
import 'notification_test_support.dart';
class _Gateway implements ApiGateway {
final controller = StreamController<JsonMap>.broadcast();
@override
Stream<JsonMap> get frames => controller.stream;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async => {};
}
Map<String, dynamic> _event({
String id = 'form-1',
String session = 'session_1',
String kind = 'question',
bool resolved = false,
bool cancelled = false,
}) => {
'type': 'chat_event',
'chat_event': {
'session_id': session,
'kind': 'form',
'form': {
'id': id,
'kind': kind,
'title': 'Choose an option',
'resolved': resolved,
'cancelled': cancelled,
},
},
};
void main() {
late _Gateway gateway;
late FakeNotificationBridge bridge;
late bool allowed;
late String? active;
late List<AppRoute> opened;
late ChatQuestionNotices notices;
setUp(() {
gateway = _Gateway();
bridge = FakeNotificationBridge(permission: 'granted');
allowed = true;
active = null;
opened = [];
notices = ChatQuestionNotices(
gateway: gateway,
canNotify: () => allowed,
activeChatSessionId: () => active,
sessionTitle: (id) async => id == 'session_1' ? ' Design chat ' : null,
openChat: (id) => opened.add(AppRoute.chatSession(id)),
bridge: bridge,
);
});
tearDown(() async {
notices.dispose();
await gateway.controller.close();
});
test('notifies titled and unknown sessions; tap opens the chat route', () async {
gateway.controller.add(_event());
await Future<void>.delayed(Duration.zero);
gateway.controller.add(_event(id: 'form-2', session: 'unknown'));
await Future<void>.delayed(Duration.zero);
expect(bridge.shown.map((message) => message.title), [
'Design chat needs your answer',
'Chat needs your answer',
]);
expect(bridge.shown.first.body, 'Choose an option');
expect(bridge.shown.first.tag, 'chat-question:form-1');
bridge.taps.first?.call();
expect(opened, [AppRoute.chatSession('session_1')]);
});
test('suppresses active, unavailable, resolved, cancelled and non-question frames', () async {
active = 'session_1';
gateway.controller.add(_event());
await Future<void>.delayed(Duration.zero);
active = null;
allowed = false;
gateway.controller.add(_event(id: 'form-2'));
await Future<void>.delayed(Duration.zero);
allowed = true;
gateway.controller.add(_event(id: 'form-3', resolved: true));
await Future<void>.delayed(Duration.zero);
gateway.controller.add(_event(id: 'form-4', cancelled: true));
await Future<void>.delayed(Duration.zero);
gateway.controller.add(_event(id: 'form-5', kind: 'approval'));
await Future<void>.delayed(Duration.zero);
expect(bridge.shown, isEmpty);
});
}
@@ -152,7 +152,7 @@ void main() {
(tester) async {
final gateway = _ScreenGateway()
..sessions = [
{'id': 's', 'title': 'Wire chat', 'backend': 'claude'},
{'id': 's', 'title': 'Wire chat', 'backend': 'other'},
];
await _pumpScreen(tester, gateway, initialSessionId: 's');
@@ -0,0 +1,340 @@
import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
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 'package:pipelines_app/features/chat/domain/chat_clipboard_paste.dart';
import 'chat_composer_bar_fixtures.dart';
/// A host paste source driven by the test. [paste] mirrors the web listener:
/// it asks [canAccept] before it hands files to the composer.
class _FakePaste {
ChatPasteFiles? onFiles;
ChatPasteCanAccept? canAccept;
ChatPasteFailed? onError;
int listens = 0;
int stops = 0;
ChatClipboardPaste get source => ChatClipboardPaste(
subscribe: (onFiles, canAccept, onError) {
listens += 1;
this.onFiles = onFiles;
this.canAccept = canAccept;
this.onError = onError;
return () {
stops += 1;
this.onFiles = null;
this.canAccept = null;
this.onError = null;
};
},
);
void paste(List<ChatPickedFile> files) {
final handler = onFiles;
if (handler == null) return;
if (!(canAccept?.call() ?? false)) return;
handler(files);
}
}
ChatPickedFile _file(
String name,
List<int> bytes, {
String mime = 'text/plain',
}) => ChatPickedFile(name: name, mime: mime, bytes: Uint8List.fromList(bytes));
Finder get _field => find.byKey(const Key('chat-composer-field'));
Finder get _chips => find.byKey(const Key('chat-composer-attachments'));
void main() {
late ComposerBarGateway gateway;
late ChatComposerController composer;
late List<ChatComposerController> controllers;
setUp(() {
gateway = ComposerBarGateway();
controllers = [];
});
tearDown(() {
for (final controller in controllers) {
controller.dispose();
}
gateway.close();
});
/// Rebuilds the same composer with a different paste source, so a test can
/// tell a replaced listener from a disposed one.
Future<void> pumpWith(
WidgetTester tester, {
ChatClipboardPaste? paste,
}) async {
await tester.pumpWidget(
materialHost(
ChatComposerBar(composer: composer, running: false, paste: paste),
),
);
await tester.pump();
}
Future<void> pumpBar(
WidgetTester tester, {
ChatClipboardPaste? paste,
ChatDraftStore? drafts,
}) async {
composer = ChatComposerController(
gateway,
's',
drafts: drafts ?? MemoryChatDraftStore(),
newOperationId: () => 'op/1',
);
controllers.add(composer);
await pumpWith(tester, paste: paste);
}
Future<void> focusField(WidgetTester tester) async {
await tester.showKeyboard(_field);
await tester.pump();
}
testWidgets('a pasted file makes the same chip as a picked file', (
tester,
) async {
final fake = _FakePaste();
await pumpBar(tester, paste: fake.source);
await focusField(tester);
fake.paste([
_file('shot.png', [1, 2, 3], mime: 'image/png'),
]);
await tester.pump();
expect(_chips, findsOneWidget);
expect(find.text('shot.png'), findsOneWidget);
expect(fake.listens, 1);
expect(fake.stops, 0);
});
testWidgets('pasting several files keeps clipboard order', (tester) async {
final fake = _FakePaste();
await pumpBar(tester, paste: fake.source);
await focusField(tester);
fake.paste([
_file('first.png', [1], mime: 'image/png'),
_file('second.txt', [2]),
]);
await tester.pump();
expect(find.text('first.png'), findsOneWidget);
expect(find.text('second.txt'), findsOneWidget);
expect(
tester.getTopLeft(find.text('first.png')).dx,
lessThan(tester.getTopLeft(find.text('second.txt')).dx),
);
});
testWidgets('an over-limit paste shows the draft refusal and adds nothing', (
tester,
) async {
final fake = _FakePaste();
await pumpBar(tester, paste: fake.source);
await focusField(tester);
fake.paste([
_file(
'huge.bin',
List<int>.filled(ChatAttachmentDraft.maxTotalBytes + 1, 0),
mime: 'application/octet-stream',
),
]);
await tester.pump();
expect(
find.text(ChatAttachmentRefusal.totalTooLarge.message),
findsOneWidget,
);
expect(_chips, findsNothing);
expect(find.text('huge.bin'), findsNothing);
});
testWidgets('a refused paste keeps the files already in the draft', (
tester,
) async {
final fake = _FakePaste();
await pumpBar(tester, paste: fake.source);
await focusField(tester);
fake.paste([
_file('kept.txt', [1]),
_file(
'huge.bin',
List<int>.filled(ChatAttachmentDraft.maxTotalBytes, 0),
mime: 'application/octet-stream',
),
]);
await tester.pump();
expect(find.text('kept.txt'), findsOneWidget);
expect(find.text('huge.bin'), findsNothing);
expect(
find.text(ChatAttachmentRefusal.totalTooLarge.message),
findsOneWidget,
);
});
testWidgets('a pasted attachment sends its exact name, type and bytes', (
tester,
) async {
final fake = _FakePaste();
await pumpBar(tester, paste: fake.source);
await focusField(tester);
fake.paste([
_file('shot.png', [9, 8, 7], mime: 'image/png'),
]);
await tester.pump();
await tester.enterText(_field, 'look');
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-composer-primary')));
await tester.pumpAndSettle();
expect(gateway.promptBodies.single['attachments'], [
{
'name': 'shot.png',
'mime': 'image/png',
'data': base64Encode([9, 8, 7]),
},
]);
expect(_chips, findsNothing);
});
testWidgets('pasted text keeps its caret, selection and draft', (
tester,
) async {
final drafts = MemoryChatDraftStore();
final fake = _FakePaste();
await pumpBar(tester, paste: fake.source, drafts: drafts);
await focusField(tester);
await tester.enterText(_field, 'hello world');
await tester.pumpAndSettle();
final editable = tester.widget<EditableText>(
find.descendant(of: _field, matching: find.byType(EditableText)),
);
editable.controller.selection = const TextSelection.collapsed(offset: 5);
// The platform's text update for a paste between "hello" and " world".
tester.testTextInput.updateEditingValue(
const TextEditingValue(
text: 'hello there world',
selection: TextSelection.collapsed(offset: 11),
),
);
await tester.pumpAndSettle();
expect(editable.controller.text, 'hello there world');
expect(
editable.controller.selection,
const TextSelection.collapsed(offset: 11),
);
expect(composer.draft, 'hello there world');
expect(drafts.entries, {'s': 'hello there world'});
});
testWidgets('paste is only taken while this composer owns the field', (
tester,
) async {
final fake = _FakePaste();
await pumpBar(tester, paste: fake.source);
expect(fake.canAccept!(), isFalse);
await focusField(tester);
expect(fake.canAccept!(), isTrue);
tester.binding.focusManager.primaryFocus?.unfocus();
await tester.pump();
expect(fake.canAccept!(), isFalse);
});
testWidgets('a paste during an in-flight prompt adds nothing', (
tester,
) async {
final reply = Completer<JsonMap>();
gateway.prompt = (_, _) => reply.future;
final fake = _FakePaste();
await pumpBar(tester, paste: fake.source);
await focusField(tester);
await tester.enterText(_field, 'hello');
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-composer-primary')));
await tester.pump();
expect(fake.canAccept!(), isFalse);
fake.paste([
_file('late.png', [1], mime: 'image/png'),
]);
await tester.pump();
expect(_chips, findsNothing);
reply.complete(const {});
await tester.pumpAndSettle();
});
testWidgets('an unreadable clipboard file is reported', (tester) async {
final fake = _FakePaste();
await pumpBar(tester, paste: fake.source);
await focusField(tester);
fake.onError!(StateError('clipboard read failed'));
await tester.pump();
expect(find.textContaining('clipboard read failed'), findsOneWidget);
});
testWidgets('a partial clipboard read shows its files and the failure', (
tester,
) async {
final fake = _FakePaste();
await pumpBar(tester, paste: fake.source);
await focusField(tester);
// The web source delivers readable files before a partial read's failure.
fake.paste([
_file('readable.png', [1], mime: 'image/png'),
]);
fake.onError!(StateError('second file failed'));
await tester.pump();
expect(find.text('readable.png'), findsOneWidget);
expect(find.textContaining('second file failed'), findsOneWidget);
});
testWidgets(
'a replaced source stops listening and dispose stops the new one',
(tester) async {
final first = _FakePaste();
await pumpBar(tester, paste: first.source);
expect(first.listens, 1);
final second = _FakePaste();
await pumpWith(tester, paste: second.source);
expect(first.stops, 1);
expect(second.listens, 1);
await tester.pumpWidget(const SizedBox());
expect(second.stops, 1);
},
);
}
@@ -380,7 +380,7 @@ void main() {
await _openThread(
tester,
gateway,
session: _withSession({'backend': 'claude'}),
session: _withSession({'backend': 'other'}),
);
expect(find.byKey(const Key('chat-model')), findsNothing);
@@ -110,7 +110,7 @@ void main() {
gateway: gateway,
sessionId: 's',
title: _title,
session: {..._session, 'backend': 'claude'},
session: {..._session, 'backend': 'other'},
onBack: () {},
),
cupertino: false,
@@ -0,0 +1,47 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/domain/chat_clipboard_paste.dart';
void main() {
test('a nameless clipboard file takes the web client name for its type', () {
expect(chatPastedAttachmentName('image/png', 1), 'pasted-1.png');
expect(chatPastedAttachmentName('image/jpeg', 2), 'pasted-2.jpg');
expect(
chatPastedAttachmentName('application/octet-stream', 3),
'pasted-3.octetstream',
);
expect(chatPastedAttachmentName('', 4), 'pasted-4.bin');
});
test('the unsupported host keeps text paste and reports the gap', () {
const paste = ChatClipboardPaste.unsupported('no files here');
expect(paste.isSupported, isFalse);
expect(
() =>
paste.listen(onFiles: (_) {}, canAccept: () => true, onError: (_) {}),
throwsUnsupportedError,
);
});
test('a supported host subscribes once and returns its unsubscribe', () {
var listens = 0;
var stops = 0;
final paste = ChatClipboardPaste(
subscribe: (onFiles, canAccept, onError) {
listens += 1;
return () => stops += 1;
},
);
final stop = paste.listen(
onFiles: (_) {},
canAccept: () => true,
onError: (_) {},
);
expect(paste.isSupported, isTrue);
expect(listens, 1);
stop();
expect(stops, 1);
});
}
@@ -86,6 +86,30 @@ void main() {
expect(find.text('Viewing v1 (latest v2).'), findsNothing);
});
testWidgets('detail Runs action names and opens that pipeline filter', (
tester,
) async {
final fixture = PipelineFixture();
final gateway = gatewayFor(fixture);
final opened = <int>[];
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
home: PipelinesScreen(gateway: gateway, onViewPipelineRuns: opened.add),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pumpAndSettle();
expect(find.bySemanticsLabel('View runs of Alpha review'), findsOneWidget);
await tester.tap(find.byKey(const Key('pipeline-view-runs')));
expect(opened, [1]);
});
testWidgets('refresh keeps the selected row and its detail', (tester) async {
final fixture = PipelineFixture();
final gateway = gatewayFor(fixture);
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/transport/connection_state.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
@@ -28,6 +29,10 @@ FakeGateway launchGateway(
)!,
),
'list_schedules' => {'type': 'schedules', 'schedules': <dynamic>[]},
'chat_directories' => {
'type': 'chat_directories',
'chat_directories': ['/work/recent', 'relative', '/work/other'],
},
'run_pipeline' => onLaunch(fields),
'get_run' when onLookup != null => onLookup(fields),
_ => errorReply('unexpected $type'),
@@ -74,6 +79,45 @@ Future<void> fillFields(
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
SharedPreferences.setMockInitialValues({});
testWidgets(
'workspace directory suggestions load on open and selection is local',
(tester) async {
final fixture = PipelineFixture();
final gateway = launchGateway(fixture, onLaunch: (_) => acceptedRun(76));
await pumpScreen(tester, gateway, <int>[]);
await openDetail(tester);
await tester.tap(find.byKey(runPipelineActionKey));
await tester.pumpAndSettle();
expect(gateway.callsOf('chat_directories'), hasLength(1));
expect(find.text(runPipelineDirectoriesLoading), findsNothing);
expect(
tester
.widget<TextField>(find.byKey(runPipelineWorkspaceKey))
.controller
?.text,
'/work/recent',
);
await tester.tap(find.byKey(runPipelineWorkspaceSuggestionsKey));
await tester.pumpAndSettle();
expect(find.text('/work/other'), findsOneWidget);
expect(find.text('relative'), findsNothing);
await tester.tap(find.text('/work/other'));
await tester.pumpAndSettle();
expect(
tester
.widget<TextField>(find.byKey(runPipelineWorkspaceKey))
.controller
?.text,
'/work/other',
);
expect(gateway.callsOf('run_pipeline'), isEmpty);
expect(gateway.callsOf('chat_directories'), hasLength(1));
},
);
testWidgets('the detail Run action sends the web request for the pinned '
'version and opens only the reply run', (tester) async {
final fixture = PipelineFixture();
@@ -93,6 +137,8 @@ void main() {
expect(find.text(runPipelinePromptLabel), findsOneWidget);
expect(find.text(runPipelineWorkspaceLabel), findsOneWidget);
expect(find.text(runPipelineNotifyLabel), findsOneWidget);
expect(find.text(runPipelineOutputFormatLabel), findsOneWidget);
expect(find.text(runPipelineOutputFormatHelper), findsOneWidget);
expect(find.text(runPipelineCancelLabel), findsOneWidget);
expect(
find.descendant(
@@ -104,14 +150,15 @@ void main() {
expect(gateway.callsOf('run_pipeline'), isEmpty);
await fillFields(tester, prompt: ' Review the change. ');
await tester.enterText(
find.byKey(runPipelineWorkspaceKey),
'/work/alpha ',
);
await tester.enterText(find.byKey(runPipelineWorkspaceKey), '/work/alpha ');
await tester.tap(find.byKey(runPipelineNotifyKey));
await tester.pumpAndSettle();
await tester.tap(find.text('Silent').last);
await tester.pumpAndSettle();
await tester.tap(find.byKey(runPipelineOutputFormatKey));
await tester.pumpAndSettle();
await tester.tap(find.text('HTML report').last);
await tester.pumpAndSettle();
await tester.tap(find.byKey(runPipelineConfirmKey));
await tester.pumpAndSettle();
@@ -123,6 +170,7 @@ void main() {
'workspace': '/work/alpha',
'input': {'prompt': 'Review the change.'},
'notify_mode': 'off',
'output_format': 'html',
});
expect(fields['request_key'], startsWith('app-run-1-2-'));
expect('${fields['request_key']}'.length, lessThanOrEqualTo(128));
@@ -317,6 +365,12 @@ void main() {
// The fields stay locked while admission is unknown.
final prompt = tester.widget<TextField>(find.byKey(runPipelinePromptKey));
expect(prompt.enabled, isFalse);
expect(
tester.widget<DropdownButtonFormField<dynamic>>(
find.byKey(runPipelineOutputFormatKey),
).onChanged,
isNull,
);
await tester.tap(find.byKey(runPipelineConfirmKey));
await tester.pumpAndSettle();
@@ -495,13 +549,7 @@ void main() {
final helper = tester
.widget<Text>(find.text(runPipelineWorkspaceHelper))
.style;
expect(
helper?.color,
CupertinoColors.secondaryLabel.resolveFrom(context),
);
expect(
helper?.fontSize,
theme.textTheme.tabLabelTextStyle.fontSize,
);
expect(helper?.color, CupertinoColors.secondaryLabel.resolveFrom(context));
expect(helper?.fontSize, theme.textTheme.tabLabelTextStyle.fontSize);
});
}
@@ -0,0 +1,38 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/runs/domain/run_models.dart';
void main() {
group('run day grouping', () {
final today = DateTime(2026, 10, 22, 12);
test('labels local days and invalid dates', () {
expect(runDayLabel('2026-10-22T08:00:00', today), 'Today');
expect(runDayLabel('2026-10-21T08:00:00', today), 'Yesterday');
expect(runDayLabel('2026-10-17T08:00:00', today), '17 Oct 2026');
expect(runDayLabel('', today), 'Unknown date');
expect(localDayKey(DateTime(2026, 1, 2)), '2026-01-02');
});
test('retains encounter order and groups adjacent equal labels', () {
final runs = [
{'id': 3, 'created_at': '2026-10-22T09:00:00'},
{'id': 2, 'created_at': '2026-10-21T09:00:00'},
{'id': 1, 'created_at': '2026-10-21T08:00:00'},
{'id': 0, 'created_at': ''},
];
final groups = groupRunsByDay(runs, today);
expect(groups.map((group) => group.label), [
'Today',
'Yesterday',
'Unknown date',
]);
expect(groups.expand((group) => group.runs).map((run) => run['id']), [
3,
2,
1,
0,
]);
});
});
}
@@ -46,17 +46,21 @@ const _runs = [
Widget _materialScreen(
_Gateway gateway, {
int? initialRunId,
int? initialPipelineId,
int syncToken = 0,
ValueChanged<int>? onRunSelected,
VoidCallback? onBack,
ValueChanged<int?>? onBack,
ValueChanged<int?>? onPipelineFilterChanged,
}) => MaterialApp(
home: Scaffold(
body: RunsScreen(
gateway: gateway,
initialRunId: initialRunId,
initialPipelineId: initialPipelineId,
syncToken: syncToken,
onRunSelected: onRunSelected,
onBack: onBack,
onPipelineFilterChanged: onPipelineFilterChanged,
),
),
);
@@ -149,12 +153,12 @@ void main() {
tester,
) async {
int? selected;
var backs = 0;
int? backedPipeline;
await tester.pumpWidget(
_materialScreen(
gateway,
onRunSelected: (id) => selected = id,
onBack: () => backs++,
onBack: (id) => backedPipeline = id,
),
);
await _mountList(tester, gateway);
@@ -167,10 +171,60 @@ void main() {
await tester.tap(find.text('Back to list'));
await tester.pump();
expect(backs, 1);
expect(backedPipeline, isNull);
expect(find.text('Alpha run'), findsOneWidget);
});
testWidgets(
'pipeline route shows its chip and clearing reports the URL change',
(tester) async {
int? changedPipeline = 3;
await tester.pumpWidget(
_materialScreen(
gateway,
initialPipelineId: 3,
onPipelineFilterChanged: (id) => changedPipeline = id,
),
);
await _mountList(tester, gateway);
expect(find.text('Pipeline 3'), findsOneWidget);
expect(changedPipeline, 3);
await tester.tap(find.byTooltip('Clear filter: Pipeline 3'));
await tester.pump();
expect(changedPipeline, isNull);
expect(find.text('Pipeline 3'), findsNothing);
},
);
testWidgets('run detail keeps the pipeline filter for Back routing', (
tester,
) async {
int? backPipeline;
await tester.pumpWidget(
_materialScreen(
gateway,
initialPipelineId: 3,
onBack: (id) => backPipeline = id,
),
);
await _mountList(tester, gateway);
await tester.pumpWidget(
_materialScreen(
gateway,
initialRunId: 2,
onBack: (id) => backPipeline = id,
),
);
await tester.pump();
gateway.replyDetail(2, 0, {'id': 2, 'title': 'Beta run'});
await tester.pump();
await tester.tap(find.text('Back to list'));
await tester.pump();
expect(backPipeline, 3);
});
testWidgets('a route change opens and closes the named run', (tester) async {
await tester.pumpWidget(_materialScreen(gateway, initialRunId: 2));
await _mountList(tester, gateway);
@@ -38,8 +38,21 @@ void main() {
Future<void> mount(WidgetTester tester, {required bool cupertino}) async {
gateway.reply = {
'runs': [
{'id': 1, 'name': 'Alpha', 'status': 'running', 'scheduled': true},
{'id': 2, 'name': 'Beta', 'status': 'failed', 'scheduled': false},
{
'id': 1,
'pipeline_id': 9,
'name': 'Alpha',
'status': 'running',
'created_at': DateTime.now().toIso8601String(),
'scheduled': true,
},
{
'id': 2,
'pipeline_id': 10,
'name': 'Beta',
'status': 'failed',
'created_at': DateTime.now().toIso8601String(),
},
],
};
await controller.load();
@@ -68,8 +81,42 @@ void main() {
await tester.tap(find.text('Filter'));
await tester.pumpAndSettle();
expect(find.text('queued'), findsOneWidget);
expect(find.text('Pipeline'), findsOneWidget);
expect(find.text('Any pipeline'), findsOneWidget);
expect(find.text('Time range'), findsOneWidget);
expect(find.text('Last 7 days'), findsOneWidget);
expect(find.text('Any trigger'), findsOneWidget);
expect(
find.text(
'Some records have no scheduling provenance; they stay unclassified.',
),
findsOneWidget,
);
final pipelineItem = find.ancestor(
of: find.text('Alpha'),
matching: find.byWidgetPredicate((widget) => widget is PopupMenuItem),
);
await tester.ensureVisible(pipelineItem);
await tester.tap(pipelineItem);
await tester.pumpAndSettle();
expect(controller.pipelineId, 9);
await tester.tap(find.text('Filter (1)'));
await tester.pumpAndSettle();
final timeItem = find.ancestor(
of: find.text('Last 7 days'),
matching: find.byWidgetPredicate((widget) => widget is PopupMenuItem),
);
await tester.ensureVisible(timeItem);
await tester.tap(timeItem);
await tester.pumpAndSettle();
expect(controller.timeRange, 'last_7_days');
expect(find.text('Filter (2)'), findsOneWidget);
expect(find.byTooltip('Clear filter: Last 7 days'), findsOneWidget);
await tester.tap(find.text('Filter (2)'));
await tester.pumpAndSettle();
final failedItem = find.ancestor(
of: find.text('failed'),
matching: find.byWidgetPredicate((widget) => widget is PopupMenuItem),
@@ -77,11 +124,10 @@ void main() {
await tester.tap(failedItem);
await tester.pumpAndSettle();
expect(controller.statuses, {'failed'});
expect(find.text('Filter (1)'), findsOneWidget);
expect(find.byType(InputChip), findsOneWidget);
expect(find.text('Filter (3)'), findsOneWidget);
expect(find.byType(InputChip), findsNWidgets(3));
expect(find.text('failed'), findsWidgets);
expect(find.text('Alpha'), findsNothing);
expect(find.text('Beta'), findsOneWidget);
expect(controller.visibleRuns, isEmpty);
await tester.tap(find.textContaining('Sort:'));
await tester.pumpAndSettle();
@@ -97,6 +143,8 @@ void main() {
await tester.tap(find.byTooltip('Clear filter: failed'));
await tester.pumpAndSettle();
expect(controller.statuses, isEmpty);
controller.clearFilters();
await tester.pumpAndSettle();
expect(find.byType(InputChip), findsNothing);
expect(find.text('Filter'), findsOneWidget);
expect(find.text('Alpha'), findsOneWidget);
@@ -122,6 +170,8 @@ void main() {
await tester.pumpAndSettle();
expect(controller.statuses, {'failed'});
expect(find.text('✓ failed'), findsOneWidget);
expect(find.text('Pipeline'), findsOneWidget);
expect(find.text('Last 7 days'), findsOneWidget);
expect(find.text('Filter (1)'), findsOneWidget);
await tester.tap(find.text('Done'));