feat(app): wire saved schedules into the pipeline summary
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/pipelines/screen.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/pipeline/schedule_pipeline_wording.dart';
|
||||
|
||||
import 'fixtures.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('pipeline Summary lists its schedules without changing tabs', (
|
||||
tester,
|
||||
) async {
|
||||
final record = {
|
||||
'id': 8,
|
||||
'revision': 3,
|
||||
'name': 'Research batteries',
|
||||
'pipeline_id': 1,
|
||||
'version': 3,
|
||||
'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',
|
||||
};
|
||||
final gateway = FakeGateway((type, fields) {
|
||||
return switch (type) {
|
||||
'list_pipelines' => pipelineListReply([
|
||||
pipelineSummary(id: 1, name: 'Alpha review', version: 3),
|
||||
]),
|
||||
'list_runs' => runListReply([]),
|
||||
'get_pipeline' => pipelineDetailReply(
|
||||
pipelineDetail(
|
||||
id: 1,
|
||||
name: 'Alpha review',
|
||||
version: 3,
|
||||
latestVersion: 5,
|
||||
versions: [versionSummary(3), versionSummary(5)],
|
||||
),
|
||||
),
|
||||
'list_schedules' => {
|
||||
'type': 'schedules',
|
||||
'schedules': [record],
|
||||
},
|
||||
_ => errorReply('unexpected $type'),
|
||||
};
|
||||
});
|
||||
tester.view.physicalSize = const Size(1100, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(home: PipelinesScreen(gateway: gateway)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('pipeline-row-1')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Schedules (1)'), findsOneWidget);
|
||||
expect(find.text('Research batteries'), findsOneWidget);
|
||||
expect(
|
||||
find.text('Pinned v3 · Every 24h · mon, wed · Europe/London'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byKey(scheduleAddKey), findsOneWidget);
|
||||
expect(find.byKey(scheduleRowEditKey(8)), findsOneWidget);
|
||||
expect(find.byKey(scheduleRowToggleKey(8)), findsOneWidget);
|
||||
expect(find.byKey(scheduleRowDeleteKey(8)), findsOneWidget);
|
||||
expect(gateway.callsOf('list_schedules').single.fields, {'pipeline_id': 1});
|
||||
|
||||
await tester.tap(find.text('Source'));
|
||||
await tester.pump();
|
||||
expect(find.text('name: alpha'), findsOneWidget);
|
||||
await tester.tap(find.text('Graph'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.byKey(scheduleAddKey), findsNothing);
|
||||
await tester.tap(find.text('Summary'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Research batteries'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -153,9 +153,8 @@ void main() {
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final controller = PipelinesController(
|
||||
PipelinesRepository(gatewayFor(PipelineFixture())),
|
||||
);
|
||||
final gateway = gatewayFor(PipelineFixture());
|
||||
final controller = PipelinesController(PipelinesRepository(gateway));
|
||||
addTearDown(controller.dispose);
|
||||
await controller.openPipeline(1);
|
||||
await tester.pumpWidget(
|
||||
@@ -167,7 +166,11 @@ void main() {
|
||||
child: child!,
|
||||
),
|
||||
home: Scaffold(
|
||||
body: PipelineDetailPanel(controller: controller, showBack: true),
|
||||
body: PipelineDetailPanel(
|
||||
controller: controller,
|
||||
gateway: gateway,
|
||||
showBack: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -27,6 +27,7 @@ FakeGateway gatewayFor(
|
||||
fields['version'] as int,
|
||||
)!,
|
||||
),
|
||||
'list_schedules' => {'type': 'schedules', 'schedules': <dynamic>[]},
|
||||
_ => errorReply('unexpected $type'),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -0,0 +1,402 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/transport/connection_state.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/editor/schedule_editor_wording.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/pipeline/schedule_pipeline_wording.dart';
|
||||
|
||||
import 'schedule_pipeline_test_support.dart';
|
||||
|
||||
Future<void> _tapSave(WidgetTester tester) async {
|
||||
// A focused field keeps itself visible, so drop focus before scrolling the
|
||||
// form to its actions.
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
await tester.pumpAndSettle();
|
||||
final finder = find.byKey(scheduleEditorSubmitKey);
|
||||
await tester.ensureVisible(finder);
|
||||
await tester.pump();
|
||||
await tester.tap(finder);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('lists this pipeline schedules with server values and states', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = SectionGateway(
|
||||
(type, fields) async => schedulesReply([
|
||||
sectionRecord(),
|
||||
sectionRecord(
|
||||
id: 9,
|
||||
revision: 1,
|
||||
name: 'Nightly report',
|
||||
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,
|
||||
),
|
||||
]),
|
||||
);
|
||||
await pumpScheduleSection(tester, gateway: gateway);
|
||||
|
||||
expect(find.text('Schedules (2)'), findsOneWidget);
|
||||
expect(find.text('Research batteries'), findsOneWidget);
|
||||
expect(
|
||||
find.text('Pinned v2 · Every 24h · mon, wed · Europe/London'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Next: Paused'), findsOneWidget);
|
||||
expect(find.text('Nightly report'), findsOneWidget);
|
||||
expect(
|
||||
find.text('Pinned v5 · 10:00, 18:30 · Server timezone'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Enabled'), findsOneWidget);
|
||||
expect(find.text('Paused'), findsOneWidget);
|
||||
expect(find.text('Next: Paused'), findsOneWidget);
|
||||
expect(find.byKey(scheduleRowEditKey(8)), findsOneWidget);
|
||||
expect(find.byKey(scheduleRowToggleKey(9)), findsOneWidget);
|
||||
expect(gateway.calls.map((call) => call.type), ['list_schedules']);
|
||||
expect(gateway.calls.single.fields, {'pipeline_id': 4});
|
||||
});
|
||||
|
||||
testWidgets('create validates, keeps a conflict draft and reuses one key', (
|
||||
tester,
|
||||
) async {
|
||||
var rows = <Map<String, dynamic>>[];
|
||||
var saves = 0;
|
||||
final gateway = SectionGateway((type, fields) {
|
||||
switch (type) {
|
||||
case 'list_schedules':
|
||||
return schedulesReply([...rows]);
|
||||
case 'save_schedule':
|
||||
saves++;
|
||||
if (saves == 1) {
|
||||
throw const ProtocolError('conflict: revision 7 is stale');
|
||||
}
|
||||
final record = Map<String, dynamic>.from(fields['schedule'] as Map);
|
||||
final stored = {
|
||||
...record,
|
||||
'id': 8,
|
||||
'revision': 1,
|
||||
'name': 'Server truth',
|
||||
};
|
||||
rows = [stored];
|
||||
return {'type': 'schedule', 'schedule': stored};
|
||||
default:
|
||||
throw StateError('unexpected $type');
|
||||
}
|
||||
});
|
||||
await pumpScheduleSection(tester, gateway: gateway, version: 3);
|
||||
|
||||
expect(find.text('Schedules (0)'), findsOneWidget);
|
||||
expect(
|
||||
find.text('No schedules yet. Add one for each topic or recurring task.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(find.byKey(scheduleAddKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final versionField = tester.widget<TextField>(
|
||||
find.byKey(scheduleEditorVersionKey),
|
||||
);
|
||||
final workspaceField = tester.widget<TextField>(
|
||||
find.byKey(scheduleEditorWorkspaceKey),
|
||||
);
|
||||
expect(versionField.controller?.text, '3');
|
||||
expect(workspaceField.controller?.text, '/srv/research');
|
||||
|
||||
await _tapSave(tester);
|
||||
expect(gateway.callsOf('save_schedule'), isEmpty);
|
||||
expect(find.text('Enter a schedule name.'), findsOneWidget);
|
||||
expect(find.text('Enter a prompt.'), findsOneWidget);
|
||||
expect(find.byKey(scheduleEditorSubmitKey), findsOneWidget);
|
||||
|
||||
await tester.enterText(find.byKey(scheduleEditorNameKey), 'New schedule');
|
||||
await tester.enterText(
|
||||
find.byKey(scheduleEditorPromptKey),
|
||||
'Summarise the release notes.',
|
||||
);
|
||||
await _tapSave(tester);
|
||||
|
||||
final first = gateway.callsOf('save_schedule').single;
|
||||
final key = first.fields['request_key'];
|
||||
expect(key, isA<String>());
|
||||
expect(key, isNotEmpty);
|
||||
expect(
|
||||
find.textContaining('conflict: revision 7 is stale'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.textContaining('Your draft is preserved.'), findsOneWidget);
|
||||
expect(find.byKey(scheduleEditorSubmitKey), findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.widget<TextField>(find.byKey(scheduleEditorNameKey))
|
||||
.controller
|
||||
?.text,
|
||||
'New schedule',
|
||||
);
|
||||
|
||||
await _tapSave(tester);
|
||||
|
||||
final savesCalls = gateway.callsOf('save_schedule');
|
||||
expect(savesCalls, hasLength(2));
|
||||
expect(savesCalls[0].fields['request_key'], key);
|
||||
expect(savesCalls[1].fields['request_key'], key);
|
||||
expect(savesCalls[1].fields['schedule'], {
|
||||
'id': 0,
|
||||
'name': 'New schedule',
|
||||
'pipeline_id': 4,
|
||||
'version': 3,
|
||||
'enabled': true,
|
||||
'input': {'prompt': 'Summarise the release notes.'},
|
||||
'workspace': '/srv/research',
|
||||
'rule': {'every': '24h'},
|
||||
'notify_mode': 'auto',
|
||||
});
|
||||
|
||||
expect(find.byKey(scheduleEditorSubmitKey), findsNothing);
|
||||
expect(find.text('Server truth'), findsOneWidget);
|
||||
expect(find.text('New schedule'), findsNothing);
|
||||
expect(gateway.callsOf('list_schedules'), hasLength(2));
|
||||
expect(gateway.callsOf('list_schedules').last.fields, {'pipeline_id': 4});
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'edit starts from the exact record and preserves unknown fields',
|
||||
(tester) async {
|
||||
final original = sectionRecord();
|
||||
var rows = <Map<String, dynamic>>[original];
|
||||
final gateway = SectionGateway((type, fields) {
|
||||
switch (type) {
|
||||
case 'list_schedules':
|
||||
return schedulesReply([...rows]);
|
||||
case 'save_schedule':
|
||||
final record = Map<String, dynamic>.from(fields['schedule'] as Map);
|
||||
final stored = {...record, 'revision': 4};
|
||||
rows = [stored];
|
||||
return {'type': 'schedule', 'schedule': stored};
|
||||
default:
|
||||
throw StateError('unexpected $type');
|
||||
}
|
||||
});
|
||||
await pumpScheduleSection(tester, gateway: gateway);
|
||||
|
||||
await tester.tap(find.byKey(scheduleRowEditKey(8)));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester
|
||||
.widget<TextField>(find.byKey(scheduleEditorNameKey))
|
||||
.controller
|
||||
?.text,
|
||||
'Research batteries',
|
||||
);
|
||||
await tester.enterText(find.byKey(scheduleEditorNameKey), 'Edited topic');
|
||||
await _tapSave(tester);
|
||||
|
||||
final call = gateway.callsOf('save_schedule').single;
|
||||
expect(call.fields.containsKey('request_key'), isFalse);
|
||||
final sent = call.fields['schedule'] as Map<String, dynamic>;
|
||||
expect(sent['id'], 8);
|
||||
expect(sent['revision'], 3);
|
||||
expect(sent['name'], 'Edited topic');
|
||||
expect(sent['pipeline_id'], 4);
|
||||
expect(sent['version'], 2);
|
||||
expect(sent['enabled'], isTrue);
|
||||
expect(sent['input'], original['input']);
|
||||
expect(sent['rule'], original['rule']);
|
||||
expect(sent['future_server_field'], original['future_server_field']);
|
||||
expect(sent['model'], 'provider/model');
|
||||
expect(sent['notify_mode'], 'off');
|
||||
expect(find.text('Edited topic'), findsOneWidget);
|
||||
expect(gateway.callsOf('list_schedules'), hasLength(2));
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('pause sends only the enabled flip and the same revision', (
|
||||
tester,
|
||||
) async {
|
||||
final original = sectionRecord();
|
||||
var rows = <Map<String, dynamic>>[original];
|
||||
final gateway = SectionGateway((type, fields) {
|
||||
switch (type) {
|
||||
case 'list_schedules':
|
||||
return schedulesReply([...rows]);
|
||||
case 'save_schedule':
|
||||
final record = Map<String, dynamic>.from(fields['schedule'] as Map);
|
||||
final stored = {...record, 'revision': 4};
|
||||
rows = [stored];
|
||||
return {'type': 'schedule', 'schedule': stored};
|
||||
default:
|
||||
throw StateError('unexpected $type');
|
||||
}
|
||||
});
|
||||
await pumpScheduleSection(tester, gateway: gateway);
|
||||
|
||||
await tester.tap(find.byKey(scheduleRowToggleKey(8)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final call = gateway.callsOf('save_schedule').single;
|
||||
expect(call.fields.containsKey('request_key'), isFalse);
|
||||
expect(call.fields['schedule'], {...original, 'enabled': false});
|
||||
expect(find.text('Paused'), findsOneWidget);
|
||||
expect(find.text('Next: Paused'), findsOneWidget);
|
||||
expect(find.byKey(scheduleRowToggleKey(8)), findsOneWidget);
|
||||
expect(find.text('Enable'), findsOneWidget);
|
||||
expect(gateway.calls.map((call) => call.type), [
|
||||
'list_schedules',
|
||||
'save_schedule',
|
||||
'list_schedules',
|
||||
]);
|
||||
});
|
||||
|
||||
testWidgets('pause refusal stays visible on that row', (tester) async {
|
||||
final gateway = SectionGateway((type, fields) {
|
||||
if (type == 'list_schedules') {
|
||||
return schedulesReply([sectionRecord()]);
|
||||
}
|
||||
throw const ProtocolError('conflict: revision 3 is stale');
|
||||
});
|
||||
await pumpScheduleSection(tester, gateway: gateway);
|
||||
|
||||
await tester.tap(find.byKey(scheduleRowToggleKey(8)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(scheduleRowErrorKey(8)), findsOneWidget);
|
||||
expect(find.text('conflict: revision 3 is stale'), findsOneWidget);
|
||||
expect(find.text('Pause'), findsOneWidget);
|
||||
expect(gateway.callsOf('list_schedules'), hasLength(1));
|
||||
});
|
||||
|
||||
testWidgets('delete confirms once and sends the exact id and revision', (
|
||||
tester,
|
||||
) async {
|
||||
var rows = <Map<String, dynamic>>[sectionRecord()];
|
||||
final gateway = SectionGateway((type, fields) {
|
||||
switch (type) {
|
||||
case 'list_schedules':
|
||||
return schedulesReply([...rows]);
|
||||
case 'delete_schedule':
|
||||
expect(fields, {'schedule_id': 8, 'expected_revision': 3});
|
||||
rows = [];
|
||||
return {'type': 'schedule_deleted', 'schedule_id': 8};
|
||||
default:
|
||||
throw StateError('unexpected $type');
|
||||
}
|
||||
});
|
||||
await pumpScheduleSection(tester, gateway: gateway);
|
||||
|
||||
await tester.tap(find.byKey(scheduleRowDeleteKey(8)));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Delete Research batteries?'), findsOneWidget);
|
||||
expect(
|
||||
find.text(
|
||||
'Future runs only. Run history and active runs will not be deleted.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(find.byKey(scheduleDeleteKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.callsOf('delete_schedule'), isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(scheduleRowDeleteKey(8)));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(scheduleDeleteConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.callsOf('delete_schedule'), hasLength(1));
|
||||
expect(find.text('Research batteries'), findsNothing);
|
||||
expect(
|
||||
find.text('No schedules yet. Add one for each topic or recurring task.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(gateway.calls.map((call) => call.type), [
|
||||
'list_schedules',
|
||||
'delete_schedule',
|
||||
'list_schedules',
|
||||
]);
|
||||
});
|
||||
|
||||
testWidgets('delete refusal keeps the prompt and shows server words', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = SectionGateway((type, fields) {
|
||||
if (type == 'list_schedules') {
|
||||
return schedulesReply([sectionRecord()]);
|
||||
}
|
||||
throw const ProtocolError('schedule changed elsewhere');
|
||||
});
|
||||
await pumpScheduleSection(tester, gateway: gateway);
|
||||
|
||||
await tester.tap(find.byKey(scheduleRowDeleteKey(8)));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(scheduleDeleteConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('schedule changed elsewhere'), findsOneWidget);
|
||||
expect(find.byKey(scheduleDeleteErrorKey), findsOneWidget);
|
||||
expect(find.byKey(scheduleDeleteConfirmKey), findsOneWidget);
|
||||
expect(gateway.callsOf('list_schedules'), hasLength(1));
|
||||
|
||||
await tester.tap(find.byKey(scheduleDeleteKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Research batteries'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('list failure keeps its own words and can retry', (tester) async {
|
||||
var fail = true;
|
||||
final gateway = SectionGateway((type, fields) {
|
||||
if (fail) throw const ProtocolError('socket closed');
|
||||
return schedulesReply([sectionRecord()]);
|
||||
});
|
||||
await pumpScheduleSection(tester, gateway: gateway);
|
||||
|
||||
expect(find.text('socket closed'), findsOneWidget);
|
||||
expect(find.text('Retry'), findsOneWidget);
|
||||
fail = false;
|
||||
await tester.tap(find.text('Retry'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Research batteries'), findsOneWidget);
|
||||
expect(find.text('socket closed'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('320px at 2x text stays usable on both native hosts', (
|
||||
tester,
|
||||
) async {
|
||||
for (final cupertino in [false, true]) {
|
||||
final gateway = SectionGateway(
|
||||
(type, fields) async => schedulesReply([
|
||||
sectionRecord(
|
||||
name: 'A very long schedule name that must wrap without overflow',
|
||||
prompt:
|
||||
'A long prompt that also wraps instead of forcing a fixed row '
|
||||
'height or a horizontal scroll.',
|
||||
),
|
||||
]),
|
||||
);
|
||||
await pumpScheduleSection(
|
||||
tester,
|
||||
gateway: gateway,
|
||||
cupertino: cupertino,
|
||||
dark: cupertino,
|
||||
width: 320,
|
||||
height: 844,
|
||||
textScale: 2,
|
||||
);
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byKey(scheduleAddKey), findsOneWidget);
|
||||
await tester.ensureVisible(find.byKey(scheduleRowDeleteKey(8)));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(scheduleRowEditKey(8)), findsOneWidget);
|
||||
expect(find.byKey(scheduleRowToggleKey(8)), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/pipeline/schedule_pipeline_section.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_store.dart';
|
||||
|
||||
typedef ScheduleSectionHandler =
|
||||
FutureOr<JsonMap> Function(String type, JsonMap fields);
|
||||
|
||||
class SectionCall {
|
||||
const SectionCall(this.type, this.fields);
|
||||
final String type;
|
||||
final JsonMap fields;
|
||||
}
|
||||
|
||||
/// Records every request and lets the test decide each reply. No socket is
|
||||
/// opened and no Pipelines server is involved.
|
||||
class SectionGateway implements ApiGateway {
|
||||
SectionGateway(this.handler);
|
||||
|
||||
final ScheduleSectionHandler handler;
|
||||
final calls = <SectionCall>[];
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
calls.add(SectionCall(type, Map<String, dynamic>.from(fields)));
|
||||
return handler(type, Map<String, dynamic>.from(fields));
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
|
||||
List<SectionCall> callsOf(String type) =>
|
||||
calls.where((call) => call.type == type).toList(growable: false);
|
||||
}
|
||||
|
||||
JsonMap schedulesReply(List<JsonMap> items) => {
|
||||
'type': 'schedules',
|
||||
'schedules': items,
|
||||
};
|
||||
|
||||
JsonMap sectionRecord({
|
||||
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',
|
||||
'future_rule_field': 'kept',
|
||||
},
|
||||
String? nextDue = '2026-10-22T09:00:00Z',
|
||||
}) => {
|
||||
'id': ?id,
|
||||
'revision': ?revision,
|
||||
'name': name,
|
||||
'pipeline_id': ?pipelineId,
|
||||
'version': ?version,
|
||||
'enabled': enabled,
|
||||
'input': {
|
||||
'prompt': prompt,
|
||||
'custom': {'nested': 'kept'},
|
||||
},
|
||||
'workspace': workspace,
|
||||
'rule': rule,
|
||||
'next_due': ?nextDue,
|
||||
'notify_mode': 'off',
|
||||
'model': 'provider/model',
|
||||
'future_server_field': {
|
||||
'nested': [
|
||||
1,
|
||||
2,
|
||||
{'deep': true},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
Widget sectionApp(
|
||||
Widget section, {
|
||||
required bool cupertino,
|
||||
bool dark = false,
|
||||
double textScale = 1,
|
||||
}) {
|
||||
Widget media(BuildContext context, Widget? app) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: app!,
|
||||
);
|
||||
final body = SafeArea(
|
||||
child: ListView(children: [section, const SizedBox(height: 24)]),
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: CupertinoThemeData(
|
||||
brightness: dark ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
builder: media,
|
||||
home: CupertinoPageScaffold(child: body),
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(brightness: dark ? Brightness.dark : Brightness.light),
|
||||
builder: media,
|
||||
home: Scaffold(body: body),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> pumpScheduleSection(
|
||||
WidgetTester tester, {
|
||||
required SectionGateway gateway,
|
||||
bool cupertino = false,
|
||||
bool dark = false,
|
||||
double width = 390,
|
||||
double height = 844,
|
||||
double textScale = 1,
|
||||
int version = 3,
|
||||
}) async {
|
||||
tester.view.physicalSize = Size(width, height);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final section = SchedulePipelineSection(
|
||||
gateway: gateway,
|
||||
pipelineId: 4,
|
||||
version: version,
|
||||
settingsStore: MemorySettingsStore(workspace: '/srv/research'),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
sectionApp(section, cupertino: cupertino, dark: dark, textScale: textScale),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
Reference in New Issue
Block a user