feat(app): add read-only saved-schedules list screen
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/schedules/data/schedules_repository.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/list/schedule_list_controller.dart';
|
||||
|
||||
import 'schedule_list_test_support.dart';
|
||||
|
||||
SchedulesController controllerFor(ApiGateway gateway, {int? pipelineId}) =>
|
||||
SchedulesController(
|
||||
repository: SchedulesRepository(gateway),
|
||||
pipelineId: pipelineId,
|
||||
);
|
||||
|
||||
void main() {
|
||||
test('lists schedules with the optional pipeline envelope', () async {
|
||||
final gateway = FakeSchedulesGateway(
|
||||
(type, fields) async =>
|
||||
schedulesReply([scheduleRecord(), pausedRecord()]),
|
||||
);
|
||||
final controller = controllerFor(gateway, pipelineId: 4);
|
||||
addTearDown(controller.dispose);
|
||||
|
||||
await controller.refresh();
|
||||
|
||||
expect(gateway.calls.single.type, 'list_schedules');
|
||||
expect(gateway.calls.single.fields, {'pipeline_id': 4});
|
||||
expect(controller.schedules.map((schedule) => schedule.name), [
|
||||
'Research batteries',
|
||||
'Nightly report',
|
||||
]);
|
||||
expect(controller.hasLoaded, isTrue);
|
||||
expect(controller.failure, isNull);
|
||||
expect(controller.countLabel, '2 schedules');
|
||||
|
||||
final globalGateway = FakeSchedulesGateway(
|
||||
(type, fields) async => schedulesReply([scheduleRecord()]),
|
||||
);
|
||||
final global = controllerFor(globalGateway);
|
||||
addTearDown(global.dispose);
|
||||
await global.refresh();
|
||||
expect(globalGateway.calls.single.fields, isEmpty);
|
||||
});
|
||||
|
||||
test('an empty reply is loaded empty, not an unsupported server', () async {
|
||||
final gateway = FakeSchedulesGateway(
|
||||
(type, fields) async => {'type': 'schedules'},
|
||||
);
|
||||
final controller = controllerFor(gateway);
|
||||
addTearDown(controller.dispose);
|
||||
|
||||
await controller.refresh();
|
||||
|
||||
expect(controller.hasLoaded, isTrue);
|
||||
expect(controller.schedules, isEmpty);
|
||||
expect(controller.failure, isNull);
|
||||
expect(controller.countLabel, '0 schedules');
|
||||
});
|
||||
|
||||
test('an unsupported envelope is distinct from empty and errors', () async {
|
||||
final unsupported = controllerFor(
|
||||
FakeSchedulesGateway((type, fields) async => {'type': 'runs'}),
|
||||
);
|
||||
addTearDown(unsupported.dispose);
|
||||
await unsupported.refresh();
|
||||
expect(unsupported.failure?.unsupported, isTrue);
|
||||
expect(unsupported.failure?.message, contains('does not support'));
|
||||
expect(unsupported.failure?.message, contains('Upgrade the server'));
|
||||
expect(unsupported.hasLoaded, isFalse);
|
||||
|
||||
final failed = controllerFor(
|
||||
FakeSchedulesGateway(
|
||||
(type, fields) async => throw StateError('socket closed'),
|
||||
),
|
||||
);
|
||||
addTearDown(failed.dispose);
|
||||
await failed.refresh();
|
||||
expect(failed.failure?.unsupported, isFalse);
|
||||
expect(failed.failure?.message, contains('socket closed'));
|
||||
expect(failed.hasLoaded, isFalse);
|
||||
});
|
||||
|
||||
test(
|
||||
'an older server refusal gets the same upgrade guidance as web',
|
||||
() async {
|
||||
for (final text in [
|
||||
'unknown request: list_schedules',
|
||||
'UNKNOWN COMMAND list_schedules',
|
||||
'Unsupported schedules command',
|
||||
]) {
|
||||
final controller = controllerFor(
|
||||
FakeSchedulesGateway(
|
||||
(type, fields) async => throw SchedulesRepositoryException(text),
|
||||
),
|
||||
);
|
||||
addTearDown(controller.dispose);
|
||||
await controller.refresh();
|
||||
|
||||
expect(controller.failure?.unsupported, isTrue, reason: text);
|
||||
expect(controller.failure?.message, contains('Upgrade the server'));
|
||||
expect(controller.failure?.message, contains(text));
|
||||
}
|
||||
|
||||
final unrelated = controllerFor(
|
||||
FakeSchedulesGateway(
|
||||
(type, fields) async =>
|
||||
throw const SchedulesRepositoryException('Permission denied.'),
|
||||
),
|
||||
);
|
||||
addTearDown(unrelated.dispose);
|
||||
await unrelated.refresh();
|
||||
expect(unrelated.failure?.unsupported, isFalse);
|
||||
expect(unrelated.failure?.message, 'Permission denied.');
|
||||
},
|
||||
);
|
||||
|
||||
test('a failed refresh keeps the previously loaded schedules', () async {
|
||||
var fail = false;
|
||||
final gateway = FakeSchedulesGateway((type, fields) async {
|
||||
if (fail) throw StateError('refresh failed');
|
||||
return schedulesReply([scheduleRecord()]);
|
||||
});
|
||||
final controller = controllerFor(gateway);
|
||||
addTearDown(controller.dispose);
|
||||
|
||||
await controller.refresh();
|
||||
fail = true;
|
||||
await controller.refresh();
|
||||
|
||||
expect(controller.schedules.single.name, 'Research batteries');
|
||||
expect(controller.failure?.message, contains('refresh failed'));
|
||||
expect(controller.isLoading, isFalse);
|
||||
});
|
||||
|
||||
test('only the newest refresh may publish a reply', () async {
|
||||
final gateway = ControlledSchedulesGateway();
|
||||
final controller = controllerFor(gateway);
|
||||
addTearDown(controller.dispose);
|
||||
|
||||
final first = controller.refresh();
|
||||
final second = controller.refresh();
|
||||
expect(gateway.requests, hasLength(2));
|
||||
|
||||
gateway.complete(1, schedulesReply([scheduleRecord(name: 'Newest reply')]));
|
||||
await second;
|
||||
gateway.complete(0, schedulesReply([scheduleRecord(name: 'Stale reply')]));
|
||||
await first;
|
||||
|
||||
expect(controller.schedules.single.name, 'Newest reply');
|
||||
expect(controller.isLoading, isFalse);
|
||||
});
|
||||
|
||||
test('a reply arriving after dispose is ignored safely', () async {
|
||||
final gateway = ControlledSchedulesGateway();
|
||||
final controller = controllerFor(gateway);
|
||||
var notifications = 0;
|
||||
controller.addListener(() => notifications++);
|
||||
|
||||
final pending = controller.refresh();
|
||||
expect(notifications, 1);
|
||||
controller.dispose();
|
||||
gateway.complete(0, schedulesReply([scheduleRecord()]));
|
||||
|
||||
await expectLater(pending, completes);
|
||||
expect(notifications, 1);
|
||||
});
|
||||
|
||||
test('missing server fields stay visible as unavailable values', () async {
|
||||
final gateway = FakeSchedulesGateway(
|
||||
(type, fields) async => schedulesReply([sparseRecord()]),
|
||||
);
|
||||
final controller = controllerFor(gateway);
|
||||
addTearDown(controller.dispose);
|
||||
await controller.refresh();
|
||||
|
||||
final schedule = controller.schedules.single;
|
||||
expect(schedule.name, isEmpty);
|
||||
expect(schedule.pipelineId, isNull);
|
||||
expect(schedule.version, isNull);
|
||||
expect(schedule.workspace, isEmpty);
|
||||
expect(schedule.nextDue, isEmpty);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/schedules/data/schedules_repository.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/list/schedule_list_controller.dart';
|
||||
|
||||
import 'schedule_list_test_support.dart';
|
||||
|
||||
SchedulesController controllerFor(ApiGateway gateway) =>
|
||||
SchedulesController(repository: SchedulesRepository(gateway));
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'search covers name, prompt and pipeline; enabled filters rows',
|
||||
() async {
|
||||
final gateway = FakeSchedulesGateway(
|
||||
(type, fields) async =>
|
||||
schedulesReply([scheduleRecord(), pausedRecord()]),
|
||||
);
|
||||
final controller = controllerFor(gateway);
|
||||
addTearDown(controller.dispose);
|
||||
await controller.refresh();
|
||||
|
||||
controller.setQuery('research');
|
||||
expect(controller.visibleSchedules.single.name, 'Research batteries');
|
||||
|
||||
controller.setQuery('BATTERY CHEMISTRY');
|
||||
expect(controller.visibleSchedules.single.id, 8);
|
||||
|
||||
controller.setQuery('pipeline 7');
|
||||
expect(controller.visibleSchedules.single.name, 'Nightly report');
|
||||
expect(controller.countLabel, '1 of 2 schedules');
|
||||
|
||||
controller.setQuery('pipeline unavailable');
|
||||
expect(controller.visibleSchedules, isEmpty);
|
||||
|
||||
controller.clearQuery();
|
||||
controller.setFilter(ScheduleListFilter.enabled);
|
||||
expect(controller.visibleSchedules.single.name, 'Research batteries');
|
||||
expect(controller.emptyMessage, 'No enabled schedules.');
|
||||
|
||||
await controller.refresh();
|
||||
expect(controller.filter, ScheduleListFilter.enabled);
|
||||
expect(controller.visibleSchedules.single.name, 'Research batteries');
|
||||
|
||||
controller.setQuery('unmatched');
|
||||
expect(controller.visibleSchedules, isEmpty);
|
||||
expect(controller.countLabel, '0 of 2 schedules');
|
||||
expect(controller.emptyMessage, 'No schedules match this search.');
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'the filtered view is recomputed for query, filter and new replies',
|
||||
() async {
|
||||
var records = [scheduleRecord(), pausedRecord()];
|
||||
final gateway = FakeSchedulesGateway(
|
||||
(type, fields) async => schedulesReply(records),
|
||||
);
|
||||
final controller = controllerFor(gateway);
|
||||
addTearDown(controller.dispose);
|
||||
await controller.refresh();
|
||||
|
||||
expect(controller.visibleSchedules, hasLength(2));
|
||||
|
||||
controller.setQuery('nightly');
|
||||
expect(controller.visibleSchedules.single.name, 'Nightly report');
|
||||
|
||||
controller.clearQuery();
|
||||
controller.setFilter(ScheduleListFilter.enabled);
|
||||
expect(controller.visibleSchedules.single.name, 'Research batteries');
|
||||
|
||||
records = [
|
||||
scheduleRecord(id: 20, name: 'Renamed', enabled: false),
|
||||
scheduleRecord(id: 21, name: 'Fresh'),
|
||||
];
|
||||
await controller.refresh();
|
||||
expect(controller.visibleSchedules.single.name, 'Fresh');
|
||||
expect(controller.countLabel, '1 of 2 schedules');
|
||||
|
||||
controller.setFilter(ScheduleListFilter.all);
|
||||
expect(controller.visibleSchedules.map((schedule) => schedule.name), [
|
||||
'Renamed',
|
||||
'Fresh',
|
||||
]);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/schedules/domain/saved_schedule.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/list/schedule_list_format.dart';
|
||||
|
||||
import 'schedule_list_test_support.dart';
|
||||
|
||||
void main() {
|
||||
test('formats complete server values', () {
|
||||
final schedule = SavedSchedule(scheduleRecord());
|
||||
|
||||
expect(scheduleDisplayName(schedule), 'Research batteries');
|
||||
expect(scheduleStatusLabel(schedule), 'Enabled');
|
||||
expect(schedulePipelineVersionValue(schedule), 'Pipeline 4 · v2');
|
||||
expect(scheduleWorkspaceValue(schedule), '/srv/research');
|
||||
expect(scheduleTimerValue(schedule), 'Every 24h · mon, wed');
|
||||
expect(scheduleTimezoneValue(schedule), 'Europe/London');
|
||||
expect(scheduleNextDueValue(schedule), scheduleDueValue(schedule.nextDue));
|
||||
});
|
||||
|
||||
test('formats clock rules and the server timezone fallback', () {
|
||||
final schedule = SavedSchedule(pausedRecord());
|
||||
|
||||
expect(scheduleStatusLabel(schedule), 'Paused');
|
||||
expect(scheduleTimerValue(schedule), '10:00, 18:30');
|
||||
expect(scheduleTimezoneValue(schedule), 'Server timezone');
|
||||
expect(scheduleNextDueValue(schedule), 'Paused');
|
||||
});
|
||||
|
||||
test('missing server values are honest, never invented', () {
|
||||
final schedule = SavedSchedule(sparseRecord());
|
||||
|
||||
expect(scheduleDisplayName(schedule), 'Unnamed schedule');
|
||||
expect(
|
||||
schedulePipelineVersionValue(schedule),
|
||||
'Pipeline unavailable · Version unavailable',
|
||||
);
|
||||
expect(scheduleWorkspaceValue(schedule), 'Workspace unavailable');
|
||||
expect(scheduleTimerValue(schedule), 'Timer unavailable');
|
||||
expect(scheduleTimezoneValue(schedule), 'Server timezone');
|
||||
expect(scheduleNextDueValue(schedule), 'Paused');
|
||||
|
||||
final enabled = SavedSchedule(scheduleRecord(nextDue: null));
|
||||
expect(scheduleNextDueValue(enabled), 'Not scheduled');
|
||||
|
||||
final invalid = SavedSchedule(scheduleRecord(nextDue: 'tomorrow'));
|
||||
expect(scheduleNextDueValue(invalid), 'Next time unavailable');
|
||||
});
|
||||
|
||||
test('due values are shown in local time and keep invalid input honest', () {
|
||||
expect(
|
||||
scheduleDueValue('2026-10-22T09:00:00'),
|
||||
'2026-10-22 09:00 (your local time)',
|
||||
);
|
||||
|
||||
final value = scheduleDueValue('2026-10-22T09:00:00Z');
|
||||
final local = DateTime.parse('2026-10-22T09:00:00Z').toLocal();
|
||||
String two(int part) => part.toString().padLeft(2, '0');
|
||||
expect(
|
||||
value,
|
||||
'${local.year}-${two(local.month)}-${two(local.day)} '
|
||||
'${two(local.hour)}:${two(local.minute)} (your local time)',
|
||||
);
|
||||
expect(scheduleDueValue('not a date'), 'Next time unavailable');
|
||||
});
|
||||
|
||||
test('count wording covers single, plural, filtered and empty lists', () {
|
||||
expect(scheduleCountLabel(1, 1), '1 schedule');
|
||||
expect(scheduleCountLabel(2, 2), '2 schedules');
|
||||
expect(scheduleCountLabel(1, 2), '1 of 2 schedules');
|
||||
expect(scheduleCountLabel(0, 0), '0 schedules');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
|
||||
typedef ScheduleHandler = Future<JsonMap> Function(String type, JsonMap fields);
|
||||
|
||||
class RecordedScheduleCall {
|
||||
const RecordedScheduleCall(this.type, this.fields);
|
||||
final String type;
|
||||
final JsonMap fields;
|
||||
}
|
||||
|
||||
/// Records every request and replays the handler's reply. No socket is opened.
|
||||
class FakeSchedulesGateway implements ApiGateway {
|
||||
FakeSchedulesGateway(this.handler);
|
||||
|
||||
final ScheduleHandler handler;
|
||||
final calls = <RecordedScheduleCall>[];
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
calls.add(RecordedScheduleCall(type, Map<String, dynamic>.from(fields)));
|
||||
return handler(type, Map<String, dynamic>.from(fields));
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
}
|
||||
|
||||
/// Holds each request open so a test can complete replies out of order or after
|
||||
/// the screen is gone.
|
||||
class ControlledSchedulesGateway implements ApiGateway {
|
||||
final calls = <RecordedScheduleCall>[];
|
||||
final requests = <Completer<JsonMap>>[];
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
calls.add(RecordedScheduleCall(type, Map<String, dynamic>.from(fields)));
|
||||
final request = Completer<JsonMap>();
|
||||
requests.add(request);
|
||||
return request.future;
|
||||
}
|
||||
|
||||
void complete(int index, JsonMap reply) => requests[index].complete(reply);
|
||||
|
||||
void fail(int index, Object error) => requests[index].completeError(error);
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
}
|
||||
|
||||
JsonMap schedulesReply(List<JsonMap> items) => {
|
||||
'type': 'schedules',
|
||||
'schedules': items,
|
||||
};
|
||||
|
||||
JsonMap scheduleRecord({
|
||||
int? id = 8,
|
||||
int? revision = 3,
|
||||
String name = 'Research batteries',
|
||||
int? pipelineId = 4,
|
||||
int? version = 2,
|
||||
bool enabled = true,
|
||||
String prompt = 'Find battery chemistry sources',
|
||||
String workspace = '/srv/research',
|
||||
Map<String, dynamic> rule = const {
|
||||
'every': '24h',
|
||||
'days': ['mon', 'wed'],
|
||||
'timezone': 'Europe/London',
|
||||
},
|
||||
String? nextDue = '2026-10-22T09:00:00Z',
|
||||
}) => {
|
||||
'id': ?id,
|
||||
'revision': ?revision,
|
||||
'name': name,
|
||||
'pipeline_id': ?pipelineId,
|
||||
'version': ?version,
|
||||
'enabled': enabled,
|
||||
'input': {'prompt': prompt},
|
||||
'workspace': workspace,
|
||||
'rule': rule,
|
||||
'next_due': ?nextDue,
|
||||
};
|
||||
|
||||
JsonMap pausedRecord() => scheduleRecord(
|
||||
id: 9,
|
||||
revision: 1,
|
||||
name: 'Nightly report',
|
||||
pipelineId: 7,
|
||||
version: 5,
|
||||
enabled: false,
|
||||
prompt: 'Summarise the open issues',
|
||||
workspace: '/srv/reports',
|
||||
rule: const {
|
||||
'times': ['10:00', '18:30'],
|
||||
'days': <String>[],
|
||||
'timezone': 'Local',
|
||||
},
|
||||
nextDue: null,
|
||||
);
|
||||
|
||||
JsonMap sparseRecord() => {
|
||||
'id': 11,
|
||||
'name': '',
|
||||
'enabled': false,
|
||||
'input': <String, dynamic>{},
|
||||
'rule': <String, dynamic>{},
|
||||
};
|
||||
|
||||
List<JsonMap> longScheduleList(int count) => [
|
||||
for (var index = 0; index < count; index++)
|
||||
scheduleRecord(
|
||||
id: 100 + index,
|
||||
revision: 1,
|
||||
name: 'Topic $index',
|
||||
prompt: 'Prompt $index',
|
||||
),
|
||||
];
|
||||
|
||||
Widget schedulesApp(
|
||||
Widget child, {
|
||||
required bool cupertino,
|
||||
double textScale = 1,
|
||||
}) {
|
||||
Widget media(BuildContext context, Widget? app) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: app!,
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(
|
||||
builder: media,
|
||||
home: CupertinoPageScaffold(child: SafeArea(child: child)),
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
builder: media,
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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/schedules/domain/saved_schedule.dart';
|
||||
import 'package:pipelines_app/features/schedules/screen.dart';
|
||||
|
||||
import 'schedule_list_test_support.dart';
|
||||
|
||||
Future<void> pumpSchedules(
|
||||
WidgetTester tester, {
|
||||
required bool cupertino,
|
||||
required ApiGateway gateway,
|
||||
ValueChanged<SavedSchedule>? onOpen,
|
||||
double textScale = 1,
|
||||
bool settle = true,
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
await tester.pumpWidget(
|
||||
schedulesApp(
|
||||
SchedulesScreen(gateway: gateway, onOpen: onOpen ?? (_) {}),
|
||||
cupertino: cupertino,
|
||||
textScale: textScale,
|
||||
),
|
||||
);
|
||||
if (settle) {
|
||||
await tester.pumpAndSettle();
|
||||
} else {
|
||||
await tester.pump();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/list/schedule_list_controller.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/list/schedule_list_toolbar.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/list/schedule_list_view.dart';
|
||||
|
||||
import 'schedule_list_test_support.dart';
|
||||
import 'schedule_screen_harness.dart';
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final textScale in [1.0, 2.0]) {
|
||||
testWidgets('${cupertino ? 'Cupertino' : 'Material'} list at 390px and '
|
||||
'${textScale}x text shows server values with native controls', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeSchedulesGateway(
|
||||
(type, fields) async => schedulesReply([
|
||||
scheduleRecord(nextDue: '2026-10-22T09:00:00'),
|
||||
pausedRecord(),
|
||||
]),
|
||||
);
|
||||
await pumpSchedules(
|
||||
tester,
|
||||
cupertino: cupertino,
|
||||
gateway: gateway,
|
||||
textScale: textScale,
|
||||
);
|
||||
|
||||
expect(find.text('2 schedules'), findsOneWidget);
|
||||
expect(find.textContaining('not pipeline definitions'), findsOneWidget);
|
||||
expect(find.text('Research batteries'), findsOneWidget);
|
||||
expect(find.text('Find battery chemistry sources'), findsOneWidget);
|
||||
expect(find.text('Pipeline 4 · v2'), findsOneWidget);
|
||||
expect(find.text('Workspace: /srv/research'), findsOneWidget);
|
||||
expect(find.text('Timer: Every 24h · mon, wed'), findsOneWidget);
|
||||
expect(find.text('Timezone: Europe/London'), findsOneWidget);
|
||||
expect(
|
||||
find.text('Next due: 2026-10-22 09:00 (your local time)'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await tester.scrollUntilVisible(
|
||||
find.text('Nightly report'),
|
||||
300,
|
||||
scrollable: find.descendant(
|
||||
of: find.byKey(scheduleListKey),
|
||||
matching: find.byType(Scrollable),
|
||||
),
|
||||
);
|
||||
expect(find.text('Nightly report'), findsOneWidget);
|
||||
expect(find.text('Pipeline 7 · v5'), findsOneWidget);
|
||||
expect(find.text('Workspace: /srv/reports'), findsOneWidget);
|
||||
expect(find.text('Timer: 10:00, 18:30'), findsOneWidget);
|
||||
expect(find.text('Timezone: Server timezone'), findsOneWidget);
|
||||
expect(find.text('Next due: Paused'), findsOneWidget);
|
||||
|
||||
if (cupertino) {
|
||||
expect(find.byType(CupertinoSearchTextField), findsOneWidget);
|
||||
expect(
|
||||
find.byType(CupertinoSlidingSegmentedControl<ScheduleListFilter>),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byType(CupertinoButton), findsWidgets);
|
||||
expect(find.byType(TextField), findsNothing);
|
||||
} else {
|
||||
expect(find.byKey(scheduleSearchFieldKey), findsOneWidget);
|
||||
expect(
|
||||
find.byType(SegmentedButton<ScheduleListFilter>),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byType(TextField), findsOneWidget);
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/list/schedule_list_toolbar.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/list/schedule_list_view.dart';
|
||||
|
||||
import 'schedule_list_test_support.dart';
|
||||
import 'schedule_screen_harness.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('refresh keeps the search query and its filtered rows', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeSchedulesGateway(
|
||||
(type, fields) async =>
|
||||
schedulesReply([scheduleRecord(), pausedRecord()]),
|
||||
);
|
||||
await pumpSchedules(tester, cupertino: false, gateway: gateway);
|
||||
|
||||
await tester.enterText(
|
||||
find.byKey(scheduleSearchFieldKey),
|
||||
'battery chemistry',
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.text('Research batteries'), findsOneWidget);
|
||||
expect(find.text('Nightly report'), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(scheduleRefreshKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final field = tester.widget<TextField>(find.byKey(scheduleSearchFieldKey));
|
||||
expect(field.controller?.text, 'battery chemistry');
|
||||
expect(find.text('Research batteries'), findsOneWidget);
|
||||
expect(find.text('Nightly report'), findsNothing);
|
||||
expect(gateway.calls, hasLength(2));
|
||||
expect(
|
||||
gateway.calls.every((call) => call.type == 'list_schedules'),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('refresh preserves the list scroll offset', (tester) async {
|
||||
final gateway = FakeSchedulesGateway(
|
||||
(type, fields) async => schedulesReply(longScheduleList(30)),
|
||||
);
|
||||
await pumpSchedules(tester, cupertino: false, gateway: gateway);
|
||||
|
||||
final list = find.byKey(scheduleListKey);
|
||||
await tester.drag(list, const Offset(0, -700));
|
||||
await tester.pumpAndSettle();
|
||||
final before = tester.widget<ListView>(list).controller!.offset;
|
||||
expect(before, greaterThan(0));
|
||||
|
||||
await tester.tap(find.byKey(scheduleRefreshKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final after = tester.widget<ListView>(list).controller!.offset;
|
||||
expect(after, before);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('a failed refresh keeps the scroll offset and the rows', (
|
||||
tester,
|
||||
) async {
|
||||
var fail = false;
|
||||
final gateway = FakeSchedulesGateway((type, fields) async {
|
||||
if (fail) throw StateError('refresh failed');
|
||||
return schedulesReply(longScheduleList(30));
|
||||
});
|
||||
await pumpSchedules(tester, cupertino: false, gateway: gateway);
|
||||
|
||||
final list = find.byKey(scheduleListKey);
|
||||
await tester.drag(list, const Offset(0, -700));
|
||||
await tester.pumpAndSettle();
|
||||
final before = tester.widget<ListView>(list).controller!.offset;
|
||||
expect(before, greaterThan(0));
|
||||
|
||||
fail = true;
|
||||
await tester.tap(find.byKey(scheduleRefreshKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.textContaining('refresh failed'), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<ListView>(find.byKey(scheduleListKey)).controller!.offset,
|
||||
before,
|
||||
);
|
||||
|
||||
fail = false;
|
||||
await tester.tap(find.byKey(scheduleRetryKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.textContaining('refresh failed'), findsNothing);
|
||||
expect(
|
||||
tester.widget<ListView>(find.byKey(scheduleListKey)).controller!.offset,
|
||||
before,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('a failed refresh keeps rows and reports the error', (
|
||||
tester,
|
||||
) async {
|
||||
var fail = false;
|
||||
final gateway = FakeSchedulesGateway((type, fields) async {
|
||||
if (fail) throw StateError('refresh failed');
|
||||
return schedulesReply([scheduleRecord(), pausedRecord()]);
|
||||
});
|
||||
await pumpSchedules(tester, cupertino: false, gateway: gateway);
|
||||
|
||||
fail = true;
|
||||
await tester.tap(find.byKey(scheduleRefreshKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Research batteries'), findsOneWidget);
|
||||
expect(find.text('Nightly report'), findsOneWidget);
|
||||
expect(find.textContaining('refresh failed'), findsOneWidget);
|
||||
expect(find.byKey(scheduleRetryKey), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/schedules/domain/saved_schedule.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/list/schedule_list_row.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/list/schedule_list_toolbar.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/list/schedule_list_view.dart';
|
||||
|
||||
import 'schedule_list_test_support.dart';
|
||||
import 'schedule_screen_harness.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('search covers name, prompt and pipeline in both themes', (
|
||||
tester,
|
||||
) async {
|
||||
for (final cupertino in [false, true]) {
|
||||
final gateway = FakeSchedulesGateway(
|
||||
(type, fields) async =>
|
||||
schedulesReply([scheduleRecord(), pausedRecord()]),
|
||||
);
|
||||
await pumpSchedules(tester, cupertino: cupertino, gateway: gateway);
|
||||
|
||||
await tester.enterText(find.byKey(scheduleSearchFieldKey), 'pipeline 7');
|
||||
await tester.pump();
|
||||
expect(find.text('Nightly report'), findsOneWidget);
|
||||
expect(find.text('Research batteries'), findsNothing);
|
||||
expect(find.text('1 of 2 schedules'), findsOneWidget);
|
||||
|
||||
await tester.enterText(
|
||||
find.byKey(scheduleSearchFieldKey),
|
||||
'battery chemistry',
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.text('Research batteries'), findsOneWidget);
|
||||
expect(find.text('Nightly report'), findsNothing);
|
||||
|
||||
await tester.enterText(find.byKey(scheduleSearchFieldKey), 'no match');
|
||||
await tester.pump();
|
||||
expect(find.text('No schedules match this search.'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('enabled filter removes paused schedules in both themes', (
|
||||
tester,
|
||||
) async {
|
||||
for (final cupertino in [false, true]) {
|
||||
final gateway = FakeSchedulesGateway(
|
||||
(type, fields) async =>
|
||||
schedulesReply([scheduleRecord(), pausedRecord()]),
|
||||
);
|
||||
await pumpSchedules(tester, cupertino: cupertino, gateway: gateway);
|
||||
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byKey(scheduleFilterKey),
|
||||
matching: find.text('Enabled'),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Research batteries'), findsOneWidget);
|
||||
expect(find.text('Nightly report'), findsNothing);
|
||||
expect(find.text('1 of 2 schedules'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('row selection opens the exact record and never mutates', (
|
||||
tester,
|
||||
) async {
|
||||
final record = scheduleRecord();
|
||||
final gateway = FakeSchedulesGateway(
|
||||
(type, fields) async => schedulesReply([record]),
|
||||
);
|
||||
final opened = <SavedSchedule>[];
|
||||
await pumpSchedules(
|
||||
tester,
|
||||
cupertino: false,
|
||||
gateway: gateway,
|
||||
onOpen: opened.add,
|
||||
);
|
||||
|
||||
expect(opened, isEmpty);
|
||||
expect(find.text('Add schedule'), findsNothing);
|
||||
expect(find.text('Edit'), findsNothing);
|
||||
expect(find.text('Delete'), findsNothing);
|
||||
expect(find.text('Pause'), findsNothing);
|
||||
|
||||
await tester.tap(find.byType(ScheduleListRow));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(opened, hasLength(1));
|
||||
expect(opened.single.raw, equals(record));
|
||||
expect(gateway.calls.map((call) => call.type), ['list_schedules']);
|
||||
});
|
||||
|
||||
testWidgets('empty and unsupported or failed replies stay distinct', (
|
||||
tester,
|
||||
) async {
|
||||
final empty = FakeSchedulesGateway(
|
||||
(type, fields) async => {'type': 'schedules'},
|
||||
);
|
||||
await pumpSchedules(tester, cupertino: false, gateway: empty);
|
||||
expect(find.text('No schedules yet.'), findsOneWidget);
|
||||
expect(find.byKey(scheduleRetryKey), findsNothing);
|
||||
|
||||
final unsupported = FakeSchedulesGateway(
|
||||
(type, fields) async => {'type': 'runs'},
|
||||
);
|
||||
await pumpSchedules(tester, cupertino: false, gateway: unsupported);
|
||||
expect(
|
||||
find.textContaining('does not support saved schedules'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byKey(scheduleRetryKey), findsOneWidget);
|
||||
expect(find.text('No schedules yet.'), findsNothing);
|
||||
|
||||
final failed = FakeSchedulesGateway(
|
||||
(type, fields) async => throw StateError('socket closed'),
|
||||
);
|
||||
await pumpSchedules(tester, cupertino: false, gateway: failed);
|
||||
expect(find.textContaining('socket closed'), findsOneWidget);
|
||||
expect(find.byKey(scheduleRetryKey), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('an empty search with the enabled filter names the filter', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeSchedulesGateway(
|
||||
(type, fields) async => schedulesReply([pausedRecord()]),
|
||||
);
|
||||
await pumpSchedules(tester, cupertino: false, gateway: gateway);
|
||||
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byKey(scheduleFilterKey),
|
||||
matching: find.text('Enabled'),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('0 of 1 schedules'), findsOneWidget);
|
||||
expect(find.text('No enabled schedules.'), findsOneWidget);
|
||||
expect(find.text('No schedules match this search.'), findsNothing);
|
||||
|
||||
await tester.enterText(find.byKey(scheduleSearchFieldKey), 'nightly');
|
||||
await tester.pump();
|
||||
expect(find.text('No schedules match this search.'), findsOneWidget);
|
||||
expect(find.text('No enabled schedules.'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('late reply after the screen is disposed does not throw', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = ControlledSchedulesGateway();
|
||||
await pumpSchedules(
|
||||
tester,
|
||||
cupertino: false,
|
||||
gateway: gateway,
|
||||
settle: false,
|
||||
);
|
||||
expect(find.byKey(scheduleRefreshKey), findsNothing);
|
||||
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
gateway.complete(0, schedulesReply([scheduleRecord()]));
|
||||
await tester.pump();
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user