feat(app): add read-only saved-schedules list screen
This commit is contained in:
@@ -0,0 +1,94 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../core/api_gateway.dart';
|
||||||
|
import 'data/schedules_repository.dart';
|
||||||
|
import 'domain/saved_schedule.dart';
|
||||||
|
import 'ui/list/schedule_list_controller.dart';
|
||||||
|
import 'ui/list/schedule_list_view.dart';
|
||||||
|
|
||||||
|
/// The saved-schedules list body.
|
||||||
|
///
|
||||||
|
/// The shell supplies navigation chrome. Selecting a row reports the exact
|
||||||
|
/// [SavedSchedule] the server returned; this screen does not create, edit,
|
||||||
|
/// delete, pause or enable anything.
|
||||||
|
class SchedulesScreen extends StatefulWidget {
|
||||||
|
const SchedulesScreen({
|
||||||
|
super.key,
|
||||||
|
required this.gateway,
|
||||||
|
required this.onOpen,
|
||||||
|
this.pipelineId,
|
||||||
|
});
|
||||||
|
|
||||||
|
final ApiGateway gateway;
|
||||||
|
final ValueChanged<SavedSchedule> onOpen;
|
||||||
|
final int? pipelineId;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SchedulesScreen> createState() => _SchedulesScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SchedulesScreenState extends State<SchedulesScreen> {
|
||||||
|
late SchedulesController _controller;
|
||||||
|
late final TextEditingController _searchController;
|
||||||
|
final ScrollController _scrollController = ScrollController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_controller = _createController();
|
||||||
|
_searchController = TextEditingController(text: _controller.query);
|
||||||
|
unawaited(_controller.refresh());
|
||||||
|
}
|
||||||
|
|
||||||
|
SchedulesController _createController() => SchedulesController(
|
||||||
|
repository: SchedulesRepository(widget.gateway),
|
||||||
|
pipelineId: widget.pipelineId,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(covariant SchedulesScreen oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (identical(oldWidget.gateway, widget.gateway) &&
|
||||||
|
oldWidget.pipelineId == widget.pipelineId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final query = _controller.query;
|
||||||
|
final filter = _controller.filter;
|
||||||
|
_controller.dispose();
|
||||||
|
_controller = _createController();
|
||||||
|
_controller.setQuery(query);
|
||||||
|
_controller.setFilter(filter);
|
||||||
|
unawaited(_controller.refresh());
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.dispose();
|
||||||
|
_searchController.dispose();
|
||||||
|
_scrollController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final cupertino =
|
||||||
|
Localizations.of<MaterialLocalizations>(
|
||||||
|
context,
|
||||||
|
MaterialLocalizations,
|
||||||
|
) ==
|
||||||
|
null;
|
||||||
|
return AnimatedBuilder(
|
||||||
|
animation: _controller,
|
||||||
|
builder: (context, _) => SchedulesListView(
|
||||||
|
controller: _controller,
|
||||||
|
searchController: _searchController,
|
||||||
|
scrollController: _scrollController,
|
||||||
|
cupertino: cupertino,
|
||||||
|
onOpen: widget.onOpen,
|
||||||
|
onRefresh: () => unawaited(_controller.refresh()),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
import '../../data/schedules_repository.dart';
|
||||||
|
import '../../domain/saved_schedule.dart';
|
||||||
|
import 'schedule_list_format.dart';
|
||||||
|
|
||||||
|
enum ScheduleListFilter { all, enabled }
|
||||||
|
|
||||||
|
extension ScheduleListFilterLabel on ScheduleListFilter {
|
||||||
|
String get label => switch (this) {
|
||||||
|
ScheduleListFilter.all => 'All',
|
||||||
|
ScheduleListFilter.enabled => 'Enabled',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A list refresh failure, kept apart from a valid empty result.
|
||||||
|
class ScheduleListFailure {
|
||||||
|
const ScheduleListFailure(this.message, {this.unsupported = false});
|
||||||
|
|
||||||
|
factory ScheduleListFailure.from(Object error) {
|
||||||
|
final text = error is SchedulesRepositoryException
|
||||||
|
? error.message
|
||||||
|
: '$error';
|
||||||
|
if (text == _unsupportedReply || _unsupportedPattern.hasMatch(text)) {
|
||||||
|
return ScheduleListFailure(
|
||||||
|
'This server does not support saved schedules. '
|
||||||
|
'Upgrade the server to use schedules. ($text)',
|
||||||
|
unsupported: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return ScheduleListFailure(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
final String message;
|
||||||
|
final bool unsupported;
|
||||||
|
|
||||||
|
/// The repository's exact report for a reply without `type: schedules`.
|
||||||
|
static const _unsupportedReply = 'The server returned no schedules response.';
|
||||||
|
|
||||||
|
/// Matches the web client's older-server detection, so a server that refuses
|
||||||
|
/// the command with its own `unknown request`/`unsupported` wording gets the
|
||||||
|
/// same upgrade guidance instead of only the raw error.
|
||||||
|
static final _unsupportedPattern = RegExp(
|
||||||
|
r'unknown (message|request|command)|unsupported.*schedule',
|
||||||
|
caseSensitive: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Loads saved run configurations with search and enabled filtering.
|
||||||
|
///
|
||||||
|
/// This controller is read-only: it only calls `list_schedules`. It never saves,
|
||||||
|
/// deletes, pauses or enables a schedule, and it never treats schedules as
|
||||||
|
/// pipeline definitions.
|
||||||
|
class SchedulesController extends ChangeNotifier {
|
||||||
|
SchedulesController({required this.repository, this.pipelineId});
|
||||||
|
|
||||||
|
final SchedulesRepository repository;
|
||||||
|
final int? pipelineId;
|
||||||
|
|
||||||
|
List<SavedSchedule> _schedules = const [];
|
||||||
|
List<SavedSchedule>? _visibleSchedules;
|
||||||
|
bool _loading = false;
|
||||||
|
bool _loaded = false;
|
||||||
|
ScheduleListFailure? _failure;
|
||||||
|
String _query = '';
|
||||||
|
ScheduleListFilter _filter = ScheduleListFilter.all;
|
||||||
|
int _generation = 0;
|
||||||
|
bool _disposed = false;
|
||||||
|
|
||||||
|
List<SavedSchedule> get schedules => _schedules;
|
||||||
|
bool get isLoading => _loading;
|
||||||
|
bool get hasLoaded => _loaded;
|
||||||
|
ScheduleListFailure? get failure => _failure;
|
||||||
|
String get query => _query;
|
||||||
|
ScheduleListFilter get filter => _filter;
|
||||||
|
|
||||||
|
/// Cached until the list, query or filter changes; the view, count label and
|
||||||
|
/// toolbar all read it during one build.
|
||||||
|
List<SavedSchedule> get visibleSchedules =>
|
||||||
|
_visibleSchedules ??= _filterSchedules();
|
||||||
|
|
||||||
|
List<SavedSchedule> _filterSchedules() {
|
||||||
|
final needle = _query.trim().toLowerCase();
|
||||||
|
return List.unmodifiable([
|
||||||
|
for (final schedule in _schedules)
|
||||||
|
if ((_filter == ScheduleListFilter.all || schedule.enabled) &&
|
||||||
|
(needle.isEmpty || _matches(schedule, needle)))
|
||||||
|
schedule,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _invalidateVisibility() => _visibleSchedules = null;
|
||||||
|
|
||||||
|
bool get isInitialLoading => _loading && !_loaded;
|
||||||
|
|
||||||
|
/// Empty-state wording that names the actual reason when the search box is
|
||||||
|
/// empty and only the enabled filter hides every row.
|
||||||
|
String get emptyMessage => _query.trim().isNotEmpty
|
||||||
|
? 'No schedules match this search.'
|
||||||
|
: 'No enabled schedules.';
|
||||||
|
|
||||||
|
String get countLabel =>
|
||||||
|
scheduleCountLabel(visibleSchedules.length, _schedules.length);
|
||||||
|
|
||||||
|
bool _matches(SavedSchedule schedule, String needle) {
|
||||||
|
final haystack = [
|
||||||
|
scheduleDisplayName(schedule),
|
||||||
|
schedule.prompt,
|
||||||
|
if (schedule.pipelineId != null) 'Pipeline ${schedule.pipelineId}',
|
||||||
|
].join('\n').toLowerCase();
|
||||||
|
return haystack.contains(needle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setQuery(String value) {
|
||||||
|
if (value == _query) return;
|
||||||
|
_query = value;
|
||||||
|
_invalidateVisibility();
|
||||||
|
_notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFilter(ScheduleListFilter value) {
|
||||||
|
if (value == _filter) return;
|
||||||
|
_filter = value;
|
||||||
|
_invalidateVisibility();
|
||||||
|
_notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearQuery() => setQuery('');
|
||||||
|
|
||||||
|
/// Reloads the list without recreating the screen, so the search field and
|
||||||
|
/// the list's scroll position survive a refresh.
|
||||||
|
///
|
||||||
|
/// Only the newest request may publish. A slower, older reply is ignored,
|
||||||
|
/// including one that completes after this controller was disposed.
|
||||||
|
Future<void> refresh() async {
|
||||||
|
final generation = ++_generation;
|
||||||
|
_loading = true;
|
||||||
|
_failure = null;
|
||||||
|
_notify();
|
||||||
|
try {
|
||||||
|
final schedules = await repository.listSchedules(pipelineId: pipelineId);
|
||||||
|
if (!_owns(generation)) return;
|
||||||
|
_schedules = List.unmodifiable(schedules);
|
||||||
|
_invalidateVisibility();
|
||||||
|
_loaded = true;
|
||||||
|
} catch (error) {
|
||||||
|
if (!_owns(generation)) return;
|
||||||
|
_failure = ScheduleListFailure.from(error);
|
||||||
|
} finally {
|
||||||
|
if (_owns(generation)) {
|
||||||
|
_loading = false;
|
||||||
|
_notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _owns(int generation) => !_disposed && generation == _generation;
|
||||||
|
|
||||||
|
void _notify() {
|
||||||
|
if (!_disposed) notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_disposed = true;
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import '../../domain/saved_schedule.dart';
|
||||||
|
|
||||||
|
/// User-facing values for one saved schedule row.
|
||||||
|
///
|
||||||
|
/// Every accessor reports what the server sent. A missing field keeps a
|
||||||
|
/// distinct "unavailable"/"not scheduled" value instead of being invented.
|
||||||
|
|
||||||
|
String scheduleDisplayName(SavedSchedule schedule) {
|
||||||
|
final name = schedule.name.trim();
|
||||||
|
return name.isEmpty ? 'Unnamed schedule' : name;
|
||||||
|
}
|
||||||
|
|
||||||
|
String scheduleStatusLabel(SavedSchedule schedule) =>
|
||||||
|
schedule.enabled ? 'Enabled' : 'Paused';
|
||||||
|
|
||||||
|
String schedulePipelineVersionValue(SavedSchedule schedule) {
|
||||||
|
final pipeline = schedule.pipelineId == null
|
||||||
|
? 'Pipeline unavailable'
|
||||||
|
: 'Pipeline ${schedule.pipelineId}';
|
||||||
|
final version = schedule.version == null
|
||||||
|
? 'Version unavailable'
|
||||||
|
: 'v${schedule.version}';
|
||||||
|
return '$pipeline · $version';
|
||||||
|
}
|
||||||
|
|
||||||
|
String scheduleWorkspaceValue(SavedSchedule schedule) {
|
||||||
|
final workspace = schedule.workspace.trim();
|
||||||
|
return workspace.isEmpty ? 'Workspace unavailable' : workspace;
|
||||||
|
}
|
||||||
|
|
||||||
|
String scheduleTimerValue(SavedSchedule schedule) {
|
||||||
|
final rule = schedule.rule;
|
||||||
|
final repeat = rule.every.isNotEmpty
|
||||||
|
? 'Every ${rule.every}'
|
||||||
|
: rule.times.isNotEmpty
|
||||||
|
? rule.times.join(', ')
|
||||||
|
: '';
|
||||||
|
if (repeat.isEmpty) return 'Timer unavailable';
|
||||||
|
return rule.days.isEmpty ? repeat : '$repeat · ${rule.days.join(', ')}';
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Matches the web client: an empty or `Local` rule timezone means the server
|
||||||
|
/// applies its own timezone, which is not an absent value.
|
||||||
|
String scheduleTimezoneValue(SavedSchedule schedule) {
|
||||||
|
final timezone = schedule.rule.timezone.trim();
|
||||||
|
return timezone.isEmpty || timezone == 'Local' ? 'Server timezone' : timezone;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Paused schedules show the pause state, as in the current web client; enabled
|
||||||
|
/// schedules show the server's `next_due` or an honest unavailable value.
|
||||||
|
String scheduleNextDueValue(SavedSchedule schedule) {
|
||||||
|
if (!schedule.enabled) return 'Paused';
|
||||||
|
return scheduleDueValue(schedule.nextDue);
|
||||||
|
}
|
||||||
|
|
||||||
|
String scheduleDueValue(String value) {
|
||||||
|
if (value.isEmpty) return 'Not scheduled';
|
||||||
|
final date = DateTime.tryParse(value);
|
||||||
|
if (date == null) return 'Next time unavailable';
|
||||||
|
final local = date.toLocal();
|
||||||
|
String two(int part) => part.toString().padLeft(2, '0');
|
||||||
|
return '${local.year.toString().padLeft(4, '0')}-${two(local.month)}-'
|
||||||
|
'${two(local.day)} ${two(local.hour)}:${two(local.minute)} '
|
||||||
|
'(your local time)';
|
||||||
|
}
|
||||||
|
|
||||||
|
String scheduleCountLabel(int visible, int total) {
|
||||||
|
if (visible != total) return '$visible of $total schedules';
|
||||||
|
return total == 1 ? '1 schedule' : '$total schedules';
|
||||||
|
}
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../domain/saved_schedule.dart';
|
||||||
|
import 'schedule_list_format.dart';
|
||||||
|
|
||||||
|
/// One tappable saved-schedule row with the server's actual values.
|
||||||
|
class ScheduleListRow extends StatelessWidget {
|
||||||
|
const ScheduleListRow({
|
||||||
|
super.key,
|
||||||
|
required this.schedule,
|
||||||
|
required this.cupertino,
|
||||||
|
required this.onOpen,
|
||||||
|
});
|
||||||
|
|
||||||
|
final SavedSchedule schedule;
|
||||||
|
final bool cupertino;
|
||||||
|
final VoidCallback onOpen;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final content = Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Expanded(child: _details(context)),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Icon(
|
||||||
|
cupertino ? CupertinoIcons.chevron_right : Icons.chevron_right,
|
||||||
|
color: _secondaryColor(context),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (cupertino) {
|
||||||
|
return CupertinoButton(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
onPressed: onOpen,
|
||||||
|
child: content,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return InkWell(onTap: onOpen, child: content);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _details(BuildContext context) {
|
||||||
|
final prompt = schedule.prompt;
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
scheduleDisplayName(schedule),
|
||||||
|
style: _titleStyle(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(scheduleStatusLabel(schedule), style: _statusStyle(context)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if (prompt.isNotEmpty) ...[
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text(prompt, style: _bodyStyle(context)),
|
||||||
|
],
|
||||||
|
const SizedBox(height: 6),
|
||||||
|
_meta(context, schedulePipelineVersionValue(schedule)),
|
||||||
|
_meta(context, 'Workspace: ${scheduleWorkspaceValue(schedule)}'),
|
||||||
|
_meta(context, 'Timer: ${scheduleTimerValue(schedule)}'),
|
||||||
|
_meta(context, 'Timezone: ${scheduleTimezoneValue(schedule)}'),
|
||||||
|
_meta(context, 'Next due: ${scheduleNextDueValue(schedule)}'),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _meta(BuildContext context, String value) =>
|
||||||
|
Text(value, style: _metaStyle(context));
|
||||||
|
|
||||||
|
TextStyle? _titleStyle(BuildContext context) => cupertino
|
||||||
|
? CupertinoTheme.of(
|
||||||
|
context,
|
||||||
|
).textTheme.textStyle.copyWith(fontWeight: FontWeight.w600)
|
||||||
|
: Theme.of(
|
||||||
|
context,
|
||||||
|
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w600);
|
||||||
|
|
||||||
|
TextStyle? _bodyStyle(BuildContext context) =>
|
||||||
|
cupertino ? CupertinoTheme.of(context).textTheme.textStyle : null;
|
||||||
|
|
||||||
|
TextStyle? _metaStyle(BuildContext context) => cupertino
|
||||||
|
? CupertinoTheme.of(context).textTheme.textStyle.copyWith(
|
||||||
|
fontSize: 14,
|
||||||
|
color: _secondaryColor(context),
|
||||||
|
)
|
||||||
|
: Theme.of(
|
||||||
|
context,
|
||||||
|
).textTheme.bodySmall?.copyWith(color: _secondaryColor(context));
|
||||||
|
|
||||||
|
TextStyle? _statusStyle(BuildContext context) => _metaStyle(
|
||||||
|
context,
|
||||||
|
)?.copyWith(color: _statusColor(context), fontWeight: FontWeight.w600);
|
||||||
|
|
||||||
|
Color _secondaryColor(BuildContext context) => cupertino
|
||||||
|
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||||
|
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||||
|
|
||||||
|
Color _statusColor(BuildContext context) => schedule.enabled
|
||||||
|
? (cupertino
|
||||||
|
? CupertinoTheme.of(context).primaryColor
|
||||||
|
: Theme.of(context).colorScheme.primary)
|
||||||
|
: _secondaryColor(context);
|
||||||
|
}
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'schedule_list_controller.dart';
|
||||||
|
|
||||||
|
const scheduleSearchFieldKey = ValueKey<String>('schedule-search-field');
|
||||||
|
const scheduleFilterKey = ValueKey<String>('schedule-filter');
|
||||||
|
const scheduleRefreshKey = ValueKey<String>('schedule-refresh');
|
||||||
|
|
||||||
|
/// Search, enabled filter and the read-only refresh control.
|
||||||
|
class ScheduleListToolbar extends StatelessWidget {
|
||||||
|
const ScheduleListToolbar({
|
||||||
|
super.key,
|
||||||
|
required this.controller,
|
||||||
|
required this.searchController,
|
||||||
|
required this.cupertino,
|
||||||
|
required this.onRefresh,
|
||||||
|
});
|
||||||
|
|
||||||
|
final SchedulesController controller;
|
||||||
|
final TextEditingController searchController;
|
||||||
|
final bool cupertino;
|
||||||
|
final VoidCallback onRefresh;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
|
||||||
|
child: _search(context),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Align(
|
||||||
|
alignment: AlignmentDirectional.centerStart,
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(maxWidth: 480),
|
||||||
|
child: _filter(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
_refresh(context),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (controller.hasLoaded)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 4),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(controller.countLabel, style: _metaStyle(context)),
|
||||||
|
Text(
|
||||||
|
'Saved run configurations, not pipeline definitions.',
|
||||||
|
style: _metaStyle(context),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _search(BuildContext context) {
|
||||||
|
if (cupertino) {
|
||||||
|
return CupertinoSearchTextField(
|
||||||
|
key: scheduleSearchFieldKey,
|
||||||
|
controller: searchController,
|
||||||
|
placeholder: 'Search schedules',
|
||||||
|
onChanged: controller.setQuery,
|
||||||
|
onSuffixTap: () {
|
||||||
|
searchController.clear();
|
||||||
|
controller.clearQuery();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return TextField(
|
||||||
|
key: scheduleSearchFieldKey,
|
||||||
|
controller: searchController,
|
||||||
|
onChanged: controller.setQuery,
|
||||||
|
textInputAction: TextInputAction.search,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Search schedules',
|
||||||
|
prefixIcon: const Icon(Icons.search),
|
||||||
|
suffixIcon: controller.query.isEmpty
|
||||||
|
? null
|
||||||
|
: IconButton(
|
||||||
|
tooltip: 'Clear search',
|
||||||
|
icon: const Icon(Icons.clear),
|
||||||
|
onPressed: () {
|
||||||
|
searchController.clear();
|
||||||
|
controller.clearQuery();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _filter(BuildContext context) {
|
||||||
|
if (cupertino) {
|
||||||
|
return CupertinoSlidingSegmentedControl<ScheduleListFilter>(
|
||||||
|
key: scheduleFilterKey,
|
||||||
|
groupValue: controller.filter,
|
||||||
|
onValueChanged: (value) {
|
||||||
|
if (value != null) controller.setFilter(value);
|
||||||
|
},
|
||||||
|
children: {
|
||||||
|
for (final filter in ScheduleListFilter.values)
|
||||||
|
filter: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
||||||
|
child: Text(filter.label),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return SegmentedButton<ScheduleListFilter>(
|
||||||
|
key: scheduleFilterKey,
|
||||||
|
segments: [
|
||||||
|
for (final filter in ScheduleListFilter.values)
|
||||||
|
ButtonSegment<ScheduleListFilter>(
|
||||||
|
value: filter,
|
||||||
|
label: Text(filter.label),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
selected: {controller.filter},
|
||||||
|
showSelectedIcon: false,
|
||||||
|
onSelectionChanged: (selection) {
|
||||||
|
if (selection.isNotEmpty) controller.setFilter(selection.first);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _refresh(BuildContext context) {
|
||||||
|
if (controller.isLoading) {
|
||||||
|
return Semantics(
|
||||||
|
label: 'Refreshing schedules',
|
||||||
|
liveRegion: true,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
child: cupertino
|
||||||
|
? const CupertinoActivityIndicator()
|
||||||
|
: const CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (cupertino) {
|
||||||
|
return Semantics(
|
||||||
|
label: 'Refresh schedules',
|
||||||
|
child: CupertinoButton(
|
||||||
|
key: scheduleRefreshKey,
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
onPressed: onRefresh,
|
||||||
|
child: const Icon(CupertinoIcons.refresh),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return IconButton(
|
||||||
|
key: scheduleRefreshKey,
|
||||||
|
tooltip: 'Refresh schedules',
|
||||||
|
onPressed: onRefresh,
|
||||||
|
icon: const Icon(Icons.refresh),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextStyle? _metaStyle(BuildContext context) => cupertino
|
||||||
|
? CupertinoTheme.of(context).textTheme.textStyle.copyWith(
|
||||||
|
fontSize: 14,
|
||||||
|
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
||||||
|
)
|
||||||
|
: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||||
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../domain/saved_schedule.dart';
|
||||||
|
import 'schedule_list_controller.dart';
|
||||||
|
import 'schedule_list_row.dart';
|
||||||
|
import 'schedule_list_toolbar.dart';
|
||||||
|
|
||||||
|
const scheduleListKey = ValueKey<String>('schedule-list');
|
||||||
|
const scheduleRetryKey = ValueKey<String>('schedule-retry');
|
||||||
|
|
||||||
|
/// Platform-adaptive list body. It owns no navigation chrome; the shell frames
|
||||||
|
/// it as the Schedules destination.
|
||||||
|
class SchedulesListView extends StatelessWidget {
|
||||||
|
const SchedulesListView({
|
||||||
|
super.key,
|
||||||
|
required this.controller,
|
||||||
|
required this.searchController,
|
||||||
|
required this.scrollController,
|
||||||
|
required this.cupertino,
|
||||||
|
required this.onOpen,
|
||||||
|
required this.onRefresh,
|
||||||
|
});
|
||||||
|
|
||||||
|
final SchedulesController controller;
|
||||||
|
final TextEditingController searchController;
|
||||||
|
final ScrollController scrollController;
|
||||||
|
final bool cupertino;
|
||||||
|
final ValueChanged<SavedSchedule> onOpen;
|
||||||
|
final VoidCallback onRefresh;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
ScheduleListToolbar(
|
||||||
|
controller: controller,
|
||||||
|
searchController: searchController,
|
||||||
|
cupertino: cupertino,
|
||||||
|
onRefresh: onRefresh,
|
||||||
|
),
|
||||||
|
Expanded(child: _body(context)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _body(BuildContext context) {
|
||||||
|
final failure = controller.failure;
|
||||||
|
if (failure != null && controller.schedules.isEmpty) {
|
||||||
|
return _failureState(context, failure);
|
||||||
|
}
|
||||||
|
if (controller.isInitialLoading) return _loadingState(context);
|
||||||
|
if (controller.schedules.isEmpty) {
|
||||||
|
return _emptyState('No schedules yet.');
|
||||||
|
}
|
||||||
|
final content = controller.visibleSchedules.isEmpty
|
||||||
|
? _emptyState(controller.emptyMessage)
|
||||||
|
: _list(context);
|
||||||
|
// The banner slot is always present so a failed or recovered refresh does
|
||||||
|
// not change the list's ancestors. Replacing the ListView would rebuild the
|
||||||
|
// Scrollable and drop the user's scroll offset.
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
if (failure != null)
|
||||||
|
_failureBanner(context, failure)
|
||||||
|
else
|
||||||
|
const SizedBox.shrink(),
|
||||||
|
Expanded(child: content),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _list(BuildContext context) {
|
||||||
|
final schedules = controller.visibleSchedules;
|
||||||
|
return ListView.separated(
|
||||||
|
key: scheduleListKey,
|
||||||
|
controller: scrollController,
|
||||||
|
padding: const EdgeInsets.only(top: 4, bottom: 24),
|
||||||
|
itemCount: schedules.length,
|
||||||
|
separatorBuilder: (context, index) =>
|
||||||
|
cupertino ? _cupertinoSeparator(context) : const Divider(height: 1),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final schedule = schedules[index];
|
||||||
|
return ScheduleListRow(
|
||||||
|
key: ValueKey<String>(
|
||||||
|
'schedule-row-$index-${schedule.id ?? 'unknown'}',
|
||||||
|
),
|
||||||
|
schedule: schedule,
|
||||||
|
cupertino: cupertino,
|
||||||
|
onOpen: () => onOpen(schedule),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _cupertinoSeparator(BuildContext context) => Container(
|
||||||
|
height: 1 / MediaQuery.devicePixelRatioOf(context),
|
||||||
|
color: CupertinoColors.separator.resolveFrom(context),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _loadingState(BuildContext context) {
|
||||||
|
return Center(
|
||||||
|
child: Semantics(
|
||||||
|
liveRegion: true,
|
||||||
|
label: 'Loading schedules',
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
cupertino
|
||||||
|
? const CupertinoActivityIndicator()
|
||||||
|
: const CircularProgressIndicator(),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
const Text('Loading schedules…'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _emptyState(String message) {
|
||||||
|
return Center(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
child: Text(message, textAlign: TextAlign.center),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _failureState(BuildContext context, ScheduleListFailure failure) {
|
||||||
|
return Center(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
_failureText(context, failure),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
_retryButton(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _failureBanner(BuildContext context, ScheduleListFailure failure) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Expanded(child: _failureText(context, failure)),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
_retryButton(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _failureText(BuildContext context, ScheduleListFailure failure) {
|
||||||
|
final color = cupertino
|
||||||
|
? CupertinoColors.systemRed.resolveFrom(context)
|
||||||
|
: Theme.of(context).colorScheme.error;
|
||||||
|
return Semantics(
|
||||||
|
liveRegion: true,
|
||||||
|
child: Text(
|
||||||
|
failure.message,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(color: color),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _retryButton() {
|
||||||
|
if (cupertino) {
|
||||||
|
return CupertinoButton(
|
||||||
|
key: scheduleRetryKey,
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
onPressed: onRefresh,
|
||||||
|
child: const Text('Retry'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return TextButton(
|
||||||
|
key: scheduleRetryKey,
|
||||||
|
onPressed: onRefresh,
|
||||||
|
child: const Text('Retry'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
# S1b — saved-schedules list (read-only)
|
||||||
|
|
||||||
|
## What changed
|
||||||
|
|
||||||
|
App-only files; no existing feature, shell, `main`, pubspec, data/domain or
|
||||||
|
server source edited.
|
||||||
|
|
||||||
|
| File | Lines | Responsibility |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `lib/features/schedules/screen.dart` | 94 | `SchedulesScreen(gateway, onOpen, pipelineId)` body; owns controller, search text and scroll |
|
||||||
|
| `lib/features/schedules/ui/list/schedule_list_controller.dart` | 168 | list load, newest-only publish, search/enabled filter, failure classification, cached visible view |
|
||||||
|
| `lib/features/schedules/ui/list/schedule_list_view.dart` | 188 | adaptive list, loading/empty/error states, stable error-banner slot |
|
||||||
|
| `lib/features/schedules/ui/list/schedule_list_toolbar.dart` | 179 | native search, all/enabled filter, refresh, count |
|
||||||
|
| `lib/features/schedules/ui/list/schedule_list_row.dart` | 115 | tappable row with server fields |
|
||||||
|
| `lib/features/schedules/ui/list/schedule_list_format.dart` | 70 | honest value/date/count wording |
|
||||||
|
| `test/features/schedules/ui/list/schedules_screen_test.dart` | 171 | search, filter, empty-filter wording, onOpen, states, unsubscribe |
|
||||||
|
| `test/features/schedules/ui/list/schedules_refresh_test.dart` | 119 | query/scroll preservation across successful and failed refresh |
|
||||||
|
| `test/features/schedules/ui/list/schedules_layout_test.dart` | 79 | Material + Cupertino at 390px, 1x and 2x text |
|
||||||
|
| `test/features/schedules/ui/list/schedule_list_controller_test.dart` | 182 | envelopes, empty/unsupported/error wording, ordering, dispose |
|
||||||
|
| `test/features/schedules/ui/list/schedule_list_filter_test.dart` | 87 | search/filter behavior and cache invalidation |
|
||||||
|
| `test/features/schedules/ui/list/schedule_list_format_test.dart` | 72 | complete/missing/invalid values and fixed due-time wording |
|
||||||
|
| `test/features/schedules/ui/list/schedule_list_test_support.dart` | 143 | recorded/immediate and controlled fake gateways |
|
||||||
|
| `test/features/schedules/ui/list/schedule_screen_harness.dart` | 33 | 390px test app builder |
|
||||||
|
| `tool/schedules_list_probe_app.dart` | 110 | local-only browser fixture (fake schedules, light/dark) |
|
||||||
|
| `tool/schedules_list_probe.mjs` | 252 | real Chrome probe, content assertions, five captures |
|
||||||
|
|
||||||
|
## Behavior
|
||||||
|
|
||||||
|
`SchedulesRepository.listSchedules` and `SavedSchedule` are reused unchanged.
|
||||||
|
The screen calls only `list_schedules`, with `pipeline_id` when supplied. There
|
||||||
|
is no add/edit/delete/pause/enable control and no other request type.
|
||||||
|
|
||||||
|
- A valid empty reply shows `No schedules yet.` An older/unsupported envelope is
|
||||||
|
a distinct error (`This server does not support saved schedules…`), and a
|
||||||
|
transport/repository error keeps its actual text. A failed refresh with rows
|
||||||
|
already loaded keeps those rows and shows the error above them.
|
||||||
|
- Older-server detection now matches the web client's wording
|
||||||
|
(`unknown (message|request|command)` and `unsupported…schedule`, case
|
||||||
|
insensitive) in addition to the repository's `no schedules response` report,
|
||||||
|
so a real server refusal receives the same upgrade guidance as the web.
|
||||||
|
- Search matches schedule name, prompt and the actual pipeline ID (`Pipeline 4`,
|
||||||
|
including a bare `4`). No pipeline name exists in the saved-schedule record, so
|
||||||
|
matching names is not possible without another request; none is faked.
|
||||||
|
- Filter is `All` / `Enabled`. Paused rows remain visible under `All`. When the
|
||||||
|
search box is empty and only the filter hides every row, the empty state says
|
||||||
|
`No enabled schedules.`; an entered query still says
|
||||||
|
`No schedules match this search.`
|
||||||
|
- Rows show the server's pipeline ID, pinned version, workspace, timer rule,
|
||||||
|
timezone and `next_due`. Missing values stay `Pipeline unavailable`,
|
||||||
|
`Version unavailable`, `Workspace unavailable`, `Timer unavailable`; an
|
||||||
|
omitted/`Local` timezone is `Server timezone`; an absent/invalid due time is
|
||||||
|
`Not scheduled` / `Next time unavailable`; a paused row shows `Paused`.
|
||||||
|
Due values are converted to local time and labelled `(your local time)`,
|
||||||
|
matching the web client's wording.
|
||||||
|
- Selecting a row passes the exact `SavedSchedule` object from the loaded list to
|
||||||
|
`onOpen`; it does not re-fetch, copy into a draft or mutate it.
|
||||||
|
- Query, filter and list are not recreated by refresh, so the search text and
|
||||||
|
`ScrollController` offset survive. The failed-refresh banner occupies a
|
||||||
|
permanently present slot above the list, so showing or clearing it does not
|
||||||
|
change the list's ancestor chain or rebuild its `Scrollable`. Only the newest
|
||||||
|
refresh generation may publish; stale replies and replies after dispose are
|
||||||
|
ignored.
|
||||||
|
- The filtered view is cached in the controller and invalidated on query,
|
||||||
|
filter and new replies, so one rebuild does not repeat the same O(n) pass for
|
||||||
|
the body, count and toolbar.
|
||||||
|
|
||||||
|
Controls are native defaults: Material `TextField`, `SegmentedButton`,
|
||||||
|
`IconButton`, `TextButton`, `Divider`, `CircularProgressIndicator`; Cupertino
|
||||||
|
`CupertinoSearchTextField`, `CupertinoSlidingSegmentedControl`,
|
||||||
|
`CupertinoButton`, `CupertinoActivityIndicator`. No CSS palette, custom font,
|
||||||
|
fixed row height or bespoke control was added. Layout is a content-driven column
|
||||||
|
with wrapping text; a single max-width constraint keeps the filter compact on
|
||||||
|
wide screens.
|
||||||
|
|
||||||
|
## Review findings addressed
|
||||||
|
|
||||||
|
- **M1 (must-fix), failed refresh reset the scroll offset.** Reproduced with the
|
||||||
|
new `schedules_refresh_test.dart` against the previous structure: the test
|
||||||
|
failed because the `Expanded` child changed from `ListView` to
|
||||||
|
`Column(banner, Expanded(ListView))`, recreating the `Scrollable`. With the
|
||||||
|
permanent banner slot the test passes for both the failure transition and the
|
||||||
|
later recovery/retry, at the unchanged offset. The test was also run against a
|
||||||
|
temporary local revert of the fix and failed as expected, then restored.
|
||||||
|
- **Advisory 1**, filter-only empty state: now `No enabled schedules.` unless a
|
||||||
|
query is active.
|
||||||
|
- **Advisory 2**, older-server wording: web-parity regex added and tested with
|
||||||
|
raw `unknown request`, `UNKNOWN COMMAND` and `Unsupported schedules command`
|
||||||
|
errors; unrelated errors keep their exact text.
|
||||||
|
- **Advisory 5**, repeated filtering: visible list cached and invalidated.
|
||||||
|
- **Advisory 6**, test oracle: the layout test now asserts the literal
|
||||||
|
`Next due: 2026-10-22 09:00 (your local time)` from a zone-less fixture instant;
|
||||||
|
the duplicated formatter helper was removed from the harness.
|
||||||
|
- **Advisory 7**, Material dark evidence: the fixture accepts
|
||||||
|
`?brightness=dark` and the probe captures Material dark at 390px.
|
||||||
|
|
||||||
|
Advisory 3 (typed repository reason instead of matching a private message
|
||||||
|
string) needs a change in the landed `data/schedules_repository.dart`, outside
|
||||||
|
this list slice; the exact-string mapping is retained and documented. Advisory
|
||||||
|
4 (formatting in the rule's IANA timezone) still needs a timezone package.
|
||||||
|
|
||||||
|
## Checks actually run
|
||||||
|
|
||||||
|
```
|
||||||
|
dart format --set-exit-if-changed lib/features/schedules \
|
||||||
|
test/features/schedules/ui/list tool/schedules_list_probe_app.dart
|
||||||
|
# 19 files, 0 changed
|
||||||
|
|
||||||
|
flutter test test/features/schedules/ui/list # 29 passed
|
||||||
|
flutter test # 110 passed
|
||||||
|
flutter analyze # No issues found!
|
||||||
|
flutter build web # ✓ Built build/web
|
||||||
|
flutter build web -t tool/schedules_list_probe_app.dart # ✓ Built build/web
|
||||||
|
node --check tool/schedules_list_probe.mjs # clean
|
||||||
|
node tool/schedules_list_probe.mjs --out …/public/s1b-schedules-captures
|
||||||
|
# 5 captures, content assertions passed
|
||||||
|
```
|
||||||
|
|
||||||
|
The focused suite covers the list envelope (with and without `pipeline_id`),
|
||||||
|
empty vs unsupported vs transport errors, older-server wording, a failed refresh
|
||||||
|
retaining rows, out-of-order refresh, disposal safety, search/filter behavior and
|
||||||
|
cache invalidation, `onOpen` receiving the exact raw record, no mutation calls,
|
||||||
|
query preservation, a successful and a failed refresh preserving scroll (plus
|
||||||
|
recovery), filter-only empty wording, both MaterialApp and CupertinoApp at 390px
|
||||||
|
with 1x and 2x text, and no render overflow.
|
||||||
|
|
||||||
|
## Browser evidence
|
||||||
|
|
||||||
|
Real headless Chrome served the fixture build on an OS-assigned loopback port,
|
||||||
|
with explicit MIME types, Flutter semantics enabled, and content assertions
|
||||||
|
before each capture:
|
||||||
|
|
||||||
|
- `/Users/alan/.local/share/pipelines/data/artifacts/58/public/s1b-schedules-captures/s1b-schedules-material-390.png`
|
||||||
|
- `…/s1b-schedules-material-390-2x.png`
|
||||||
|
- `…/s1b-schedules-material-390-dark.png`
|
||||||
|
- `…/s1b-schedules-cupertino-390.png` (platform dark appearance)
|
||||||
|
- `…/s1b-schedules-material-1100.png`
|
||||||
|
- `…/manifest.json`
|
||||||
|
|
||||||
|
The fixture uses a local fake gateway with four records (enabled, paused, clock
|
||||||
|
rule, sparse record). It never contacted a Pipelines server, bypassed
|
||||||
|
authentication or created/changed a real schedule or run.
|
||||||
|
|
||||||
|
## Full diff
|
||||||
|
|
||||||
|
Every changed path is new and untracked; no pre-existing work was modified,
|
||||||
|
reset or deleted. The complete patch is saved at:
|
||||||
|
|
||||||
|
`/Users/alan/.local/share/pipelines/data/artifacts/58/public/s1b-schedules-list.diff`
|
||||||
|
|
||||||
|
## Honest limits
|
||||||
|
|
||||||
|
- **Not committed.** This stage forbids commit/push/deploy, so the candidate
|
||||||
|
remains uncommitted in the `flutter/s1-list` worktree for the manager.
|
||||||
|
- **Not wired into the shell.** `lib/main.dart`, `lib/shell/` and destination
|
||||||
|
registration are untouched; the Schedules destination still shows its
|
||||||
|
placeholder until the separate integration item.
|
||||||
|
- **No schedule editor.** Create/edit/delete/pause remain separate follow-up
|
||||||
|
items; no mutation was implemented or exercised.
|
||||||
|
- **Pipeline-name search unavailable.** The saved-schedule record exposes only
|
||||||
|
`pipeline_id`; search uses that exact ID rather than inventing a name.
|
||||||
|
- **Due times use the device timezone.** The absolute `next_due` instant is shown
|
||||||
|
as `(your local time)` and the rule timezone separately. The web client can
|
||||||
|
format in the rule's IANA timezone; that needs a timezone package not available
|
||||||
|
in this slice.
|
||||||
|
- **Mobile unverified.** No Android/iOS build, emulator, ADB or device was used.
|
||||||
|
- **Live server unverified.** Browser evidence is fixture-only by design; no
|
||||||
|
production authentication or schedule data was used.
|
||||||
@@ -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);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,252 @@
|
|||||||
|
import { createServer } from 'node:http';
|
||||||
|
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
||||||
|
import { spawn } from 'node:child_process';
|
||||||
|
import { once } from 'node:events';
|
||||||
|
import { setTimeout as delay } from 'node:timers/promises';
|
||||||
|
import { join, extname, resolve, sep } from 'node:path';
|
||||||
|
import { tmpdir } from 'node:os';
|
||||||
|
|
||||||
|
// Serves the Flutter web build produced by:
|
||||||
|
// flutter build web -t tool/schedules_list_probe_app.dart
|
||||||
|
// The fixture is local-only: no Pipelines server, authentication or real
|
||||||
|
// schedule is touched.
|
||||||
|
const root = join(process.cwd(), 'build/web');
|
||||||
|
const outputIndex = process.argv.indexOf('--out');
|
||||||
|
const output = outputIndex >= 0
|
||||||
|
? resolve(process.argv[outputIndex + 1])
|
||||||
|
: resolve(process.env.OPENCODE_ARTIFACT_DIR ?? join(process.cwd(), 'build/schedules-captures'));
|
||||||
|
const chromePath = process.env.CHROME_PATH
|
||||||
|
?? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
|
||||||
|
const mime = {
|
||||||
|
'.html': 'text/html; charset=utf-8',
|
||||||
|
'.js': 'text/javascript; charset=utf-8',
|
||||||
|
'.mjs': 'text/javascript; charset=utf-8',
|
||||||
|
'.json': 'application/json',
|
||||||
|
'.wasm': 'application/wasm',
|
||||||
|
'.png': 'image/png',
|
||||||
|
'.jpg': 'image/jpeg',
|
||||||
|
'.svg': 'image/svg+xml',
|
||||||
|
'.ico': 'image/x-icon',
|
||||||
|
'.css': 'text/css; charset=utf-8',
|
||||||
|
'.ttf': 'font/ttf',
|
||||||
|
'.otf': 'font/otf',
|
||||||
|
'.woff': 'font/woff',
|
||||||
|
'.woff2': 'font/woff2',
|
||||||
|
'.bin': 'application/octet-stream',
|
||||||
|
};
|
||||||
|
|
||||||
|
const server = createServer(async (req, res) => {
|
||||||
|
try {
|
||||||
|
const pathname = decodeURIComponent(new URL(req.url, 'http://localhost').pathname);
|
||||||
|
const path = resolve(root, '.' + pathname);
|
||||||
|
if (path !== root && !path.startsWith(root + sep)) {
|
||||||
|
return res.writeHead(403).end();
|
||||||
|
}
|
||||||
|
const filePath = pathname.endsWith('/') ? join(path, 'index.html') : path;
|
||||||
|
const file = await readFile(filePath);
|
||||||
|
res
|
||||||
|
.writeHead(200, {
|
||||||
|
'content-type': mime[extname(filePath)] ?? 'application/octet-stream',
|
||||||
|
'cache-control': 'no-store',
|
||||||
|
})
|
||||||
|
.end(file);
|
||||||
|
} catch {
|
||||||
|
res.writeHead(404).end('not found');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
server.listen(0, '127.0.0.1');
|
||||||
|
await once(server, 'listening');
|
||||||
|
const port = server.address().port;
|
||||||
|
const profile = await mkdtemp(join(tmpdir(), 's1b-schedules-chrome-'));
|
||||||
|
const chrome = spawn(chromePath, [
|
||||||
|
'--headless=new',
|
||||||
|
'--no-first-run',
|
||||||
|
'--no-default-browser-check',
|
||||||
|
'--disable-gpu',
|
||||||
|
'--remote-debugging-port=0',
|
||||||
|
`--user-data-dir=${profile}`,
|
||||||
|
'about:blank',
|
||||||
|
], { stdio: ['ignore', 'ignore', 'pipe'] });
|
||||||
|
let stderr = '';
|
||||||
|
chrome.stderr.on('data', data => { stderr += data; });
|
||||||
|
const waitFor = async (fn, label, attempts = 160) => {
|
||||||
|
for (let i = 0; i < attempts; i++) {
|
||||||
|
const value = await fn();
|
||||||
|
if (value) return value;
|
||||||
|
await delay(100);
|
||||||
|
}
|
||||||
|
throw new Error(`Timed out waiting for ${label}`);
|
||||||
|
};
|
||||||
|
let ws;
|
||||||
|
try {
|
||||||
|
const endpoint = await waitFor(
|
||||||
|
() => stderr.match(/DevTools listening on (ws:\/\/[^\s]+)/)?.[1],
|
||||||
|
'Chrome DevTools',
|
||||||
|
);
|
||||||
|
ws = new WebSocket(endpoint);
|
||||||
|
await once(ws, 'open');
|
||||||
|
let id = 0;
|
||||||
|
const pending = new Map();
|
||||||
|
const pageErrors = [];
|
||||||
|
ws.addEventListener('message', event => {
|
||||||
|
const msg = JSON.parse(event.data);
|
||||||
|
if (msg.method === 'Runtime.exceptionThrown') {
|
||||||
|
pageErrors.push(msg.params?.exceptionDetails?.text ?? 'page exception');
|
||||||
|
}
|
||||||
|
if (msg.id && pending.has(msg.id)) {
|
||||||
|
pending.get(msg.id)(msg);
|
||||||
|
pending.delete(msg.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const send = (method, params = {}, sessionId) => new Promise(resolveCall => {
|
||||||
|
const callId = ++id;
|
||||||
|
pending.set(callId, resolveCall);
|
||||||
|
ws.send(JSON.stringify({
|
||||||
|
id: callId,
|
||||||
|
method,
|
||||||
|
params,
|
||||||
|
...(sessionId ? { sessionId } : {}),
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
const created = await send('Target.createTarget', { url: 'about:blank' });
|
||||||
|
if (!created.result) throw new Error(`Target creation failed: ${JSON.stringify(created)}`);
|
||||||
|
const target = created.result.targetId;
|
||||||
|
const session = (
|
||||||
|
await send('Target.attachToTarget', { targetId: target, flatten: true })
|
||||||
|
).result.sessionId;
|
||||||
|
await send('Page.enable', {}, session);
|
||||||
|
await send('Runtime.enable', {}, session);
|
||||||
|
const evaluate = async expression => {
|
||||||
|
const response = await send(
|
||||||
|
'Runtime.evaluate',
|
||||||
|
{ expression, returnByValue: true, awaitPromise: true },
|
||||||
|
session,
|
||||||
|
);
|
||||||
|
if (response.error) throw new Error(`Runtime.evaluate failed: ${JSON.stringify(response)}`);
|
||||||
|
if (response.result?.exceptionDetails) {
|
||||||
|
throw new Error(`Runtime exception: ${JSON.stringify(response.result.exceptionDetails)}`);
|
||||||
|
}
|
||||||
|
return response.result?.result?.value;
|
||||||
|
};
|
||||||
|
await mkdir(output, { recursive: true });
|
||||||
|
const cases = [
|
||||||
|
{
|
||||||
|
name: 's1b-schedules-material-390',
|
||||||
|
theme: 'material',
|
||||||
|
scale: 1,
|
||||||
|
width: 390,
|
||||||
|
height: 844,
|
||||||
|
expect: ['4 schedules', 'Research batteries', 'Pipeline 4 · v2', 'Timer: Every 24h', 'Timezone: Europe/London', 'Next due:'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 's1b-schedules-material-390-2x',
|
||||||
|
theme: 'material',
|
||||||
|
scale: 2,
|
||||||
|
width: 390,
|
||||||
|
height: 844,
|
||||||
|
expect: ['Research batteries', 'Pipeline 4 · v2', 'Workspace: /srv/research', 'Timer: Every 24h'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 's1b-schedules-material-390-dark',
|
||||||
|
theme: 'material',
|
||||||
|
brightness: 'dark',
|
||||||
|
scale: 1,
|
||||||
|
width: 390,
|
||||||
|
height: 844,
|
||||||
|
expect: ['4 schedules', 'Research batteries', 'Pipeline 4 · v2', 'Timezone: Europe/London', 'Next due:'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 's1b-schedules-cupertino-390',
|
||||||
|
theme: 'cupertino',
|
||||||
|
scale: 1,
|
||||||
|
width: 390,
|
||||||
|
height: 844,
|
||||||
|
expect: ['Research batteries', 'Pipeline 4 · v2', 'Timezone: Europe/London'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 's1b-schedules-material-1100',
|
||||||
|
theme: 'material',
|
||||||
|
scale: 1,
|
||||||
|
width: 1100,
|
||||||
|
height: 800,
|
||||||
|
expect: ['Research batteries', 'Nightly report', 'Weekly digest', 'Sparse server record'],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const results = [];
|
||||||
|
for (const item of cases) {
|
||||||
|
const query = new URLSearchParams({ theme: item.theme, scale: String(item.scale) });
|
||||||
|
if (item.brightness) query.set('brightness', item.brightness);
|
||||||
|
const url = `http://127.0.0.1:${port}/?${query}`;
|
||||||
|
const navigation = await send('Page.navigate', { url }, session);
|
||||||
|
if (navigation.error || navigation.result?.errorText) {
|
||||||
|
throw new Error(`Navigation failed: ${JSON.stringify(navigation)}`);
|
||||||
|
}
|
||||||
|
await send(
|
||||||
|
'Emulation.setDeviceMetricsOverride',
|
||||||
|
{
|
||||||
|
width: item.width,
|
||||||
|
height: item.height,
|
||||||
|
deviceScaleFactor: 1,
|
||||||
|
mobile: item.width < 600,
|
||||||
|
},
|
||||||
|
session,
|
||||||
|
);
|
||||||
|
await delay(2500);
|
||||||
|
const placeholder = await waitFor(
|
||||||
|
() => evaluate("!!document.querySelector('flt-semantics-placeholder')"),
|
||||||
|
`${item.name} semantics placeholder`,
|
||||||
|
);
|
||||||
|
if (!placeholder) throw new Error(`${item.name}: no semantics placeholder`);
|
||||||
|
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
||||||
|
const labels = await waitFor(async () => {
|
||||||
|
const current = await evaluate(
|
||||||
|
"[...document.querySelectorAll('flt-semantics')].map(x=>x.getAttribute('aria-label')||x.innerText).filter(Boolean)",
|
||||||
|
);
|
||||||
|
return current?.some(label => label.includes('Research batteries')) ? current : null;
|
||||||
|
}, `${item.name} schedule content`);
|
||||||
|
const text = labels.join('\n');
|
||||||
|
for (const expected of item.expect) {
|
||||||
|
if (!text.includes(expected)) {
|
||||||
|
throw new Error(`${item.name}: missing ${JSON.stringify(expected)} in ${JSON.stringify(labels)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (/does not support|No schedules yet|socket closed/.test(text)) {
|
||||||
|
throw new Error(`${item.name}: unexpected state text ${JSON.stringify(labels)}`);
|
||||||
|
}
|
||||||
|
await delay(400);
|
||||||
|
const screenshot = await send(
|
||||||
|
'Page.captureScreenshot',
|
||||||
|
{ format: 'png', captureBeyondViewport: false },
|
||||||
|
session,
|
||||||
|
);
|
||||||
|
const file = `${item.name}.png`;
|
||||||
|
await writeFile(join(output, file), Buffer.from(screenshot.result.data, 'base64'));
|
||||||
|
results.push({
|
||||||
|
name: item.name,
|
||||||
|
file,
|
||||||
|
width: item.width,
|
||||||
|
height: item.height,
|
||||||
|
theme: item.theme,
|
||||||
|
brightness: item.brightness ?? 'platform',
|
||||||
|
checked: item.expect,
|
||||||
|
labelCount: labels.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (pageErrors.length) {
|
||||||
|
throw new Error(`Page exceptions: ${JSON.stringify(pageErrors)}`);
|
||||||
|
}
|
||||||
|
const manifest = {
|
||||||
|
url: `http://127.0.0.1:${port}/`,
|
||||||
|
fixture: 'tool/schedules_list_probe_app.dart',
|
||||||
|
output,
|
||||||
|
captures: results,
|
||||||
|
};
|
||||||
|
await writeFile(join(output, 'manifest.json'), JSON.stringify(manifest, null, 2));
|
||||||
|
console.log(JSON.stringify(manifest, null, 2));
|
||||||
|
} finally {
|
||||||
|
ws?.close();
|
||||||
|
chrome.kill('SIGTERM');
|
||||||
|
await Promise.race([once(chrome, 'exit'), delay(3000)]);
|
||||||
|
server.close();
|
||||||
|
await rm(profile, { recursive: true, force: true });
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pipelines_app/core/api_gateway.dart';
|
||||||
|
import 'package:pipelines_app/features/schedules/screen.dart';
|
||||||
|
|
||||||
|
/// Isolated browser fixture for the read-only schedules list.
|
||||||
|
///
|
||||||
|
/// Run with:
|
||||||
|
/// flutter build web -t tool/schedules_list_probe_app.dart
|
||||||
|
/// and open `/?theme=cupertino&scale=2`.
|
||||||
|
void main() {
|
||||||
|
final parameters = Uri.base.queryParameters;
|
||||||
|
final cupertino = parameters['theme'] == 'cupertino';
|
||||||
|
final dark = parameters['brightness'] == 'dark';
|
||||||
|
final scale = double.tryParse(parameters['scale'] ?? '') ?? 1.0;
|
||||||
|
final screen = SchedulesScreen(gateway: _FixtureGateway(), onOpen: (_) {});
|
||||||
|
Widget media(BuildContext context, Widget? app) => MediaQuery(
|
||||||
|
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(scale)),
|
||||||
|
child: app!,
|
||||||
|
);
|
||||||
|
if (cupertino) {
|
||||||
|
runApp(
|
||||||
|
CupertinoApp(
|
||||||
|
debugShowCheckedModeBanner: false,
|
||||||
|
builder: media,
|
||||||
|
home: CupertinoPageScaffold(child: SafeArea(child: screen)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
runApp(
|
||||||
|
MaterialApp(
|
||||||
|
debugShowCheckedModeBanner: false,
|
||||||
|
theme: dark ? ThemeData(brightness: Brightness.dark) : null,
|
||||||
|
builder: media,
|
||||||
|
home: Scaffold(
|
||||||
|
appBar: AppBar(title: const Text('Schedules')),
|
||||||
|
body: screen,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FixtureGateway implements ApiGateway {
|
||||||
|
@override
|
||||||
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||||
|
if (type != 'list_schedules') {
|
||||||
|
throw StateError('The schedules list fixture only lists schedules.');
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'type': 'schedules',
|
||||||
|
'schedules': [
|
||||||
|
{
|
||||||
|
'id': 8,
|
||||||
|
'revision': 3,
|
||||||
|
'name': 'Research batteries',
|
||||||
|
'pipeline_id': 4,
|
||||||
|
'version': 2,
|
||||||
|
'enabled': true,
|
||||||
|
'input': {'prompt': 'Find battery chemistry sources'},
|
||||||
|
'workspace': '/srv/research',
|
||||||
|
'rule': {
|
||||||
|
'every': '24h',
|
||||||
|
'days': ['mon', 'wed'],
|
||||||
|
'timezone': 'Europe/London',
|
||||||
|
},
|
||||||
|
'next_due': '2026-10-22T09:00:00Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': 9,
|
||||||
|
'revision': 1,
|
||||||
|
'name': 'Nightly report',
|
||||||
|
'pipeline_id': 7,
|
||||||
|
'version': 5,
|
||||||
|
'enabled': false,
|
||||||
|
'input': {'prompt': 'Summarise the open issues'},
|
||||||
|
'workspace': '/srv/reports',
|
||||||
|
'rule': {
|
||||||
|
'times': ['10:00', '18:30'],
|
||||||
|
'days': <String>[],
|
||||||
|
'timezone': 'Local',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': 10,
|
||||||
|
'revision': 2,
|
||||||
|
'name': 'Weekly digest',
|
||||||
|
'pipeline_id': 12,
|
||||||
|
'version': 1,
|
||||||
|
'enabled': true,
|
||||||
|
'input': {'prompt': 'Collect the week’s changes'},
|
||||||
|
'workspace': '/srv/digest',
|
||||||
|
'rule': {'every': '168h', 'days': <String>[]},
|
||||||
|
'next_due': '2026-10-26T08:30:00+01:00',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': 11,
|
||||||
|
'revision': 1,
|
||||||
|
'name': 'Sparse server record',
|
||||||
|
'enabled': false,
|
||||||
|
'input': <String, dynamic>{},
|
||||||
|
'rule': <String, dynamic>{},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Stream<JsonMap> get frames => const Stream.empty();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user