feat(app): add native saved-schedule editor form
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
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/editor/schedule_editor_selectors.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/editor/schedule_editor_wording.dart';
|
||||
|
||||
import 'schedule_editor_harness.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('invalid draft shows field errors and sends nothing', (
|
||||
tester,
|
||||
) async {
|
||||
final calls = <JsonMap>[];
|
||||
await pumpScheduleEditor(
|
||||
tester,
|
||||
draft: createDraft(),
|
||||
onSubmit: (record) async => calls.add(record),
|
||||
);
|
||||
expect(find.text('Add schedule'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(scheduleEditorSubmitKey));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Enter a schedule name.'), findsOneWidget);
|
||||
expect(find.text('Enter a prompt.'), findsOneWidget);
|
||||
expect(calls, isEmpty);
|
||||
expect(
|
||||
tester
|
||||
.widget<TextField>(find.byKey(scheduleEditorVersionKey))
|
||||
.controller!
|
||||
.text,
|
||||
'2',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('valid create sends the exact save record', (tester) async {
|
||||
final calls = <JsonMap>[];
|
||||
final draft = createDraft();
|
||||
await pumpScheduleEditor(
|
||||
tester,
|
||||
draft: draft,
|
||||
onSubmit: (record) async => calls.add(record),
|
||||
);
|
||||
|
||||
await enterField(tester, scheduleEditorNameKey, 'Probe schedule');
|
||||
await enterField(
|
||||
tester,
|
||||
scheduleEditorPromptKey,
|
||||
'Summarise the release notes.',
|
||||
);
|
||||
await tester.tap(find.byKey(scheduleEditorDayKey('mon')));
|
||||
await tester.tap(find.byKey(scheduleEditorDayKey('wed')));
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(scheduleEditorSubmitKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(calls, hasLength(1));
|
||||
expect(calls.single, {
|
||||
'id': 0,
|
||||
'name': 'Probe schedule',
|
||||
'pipeline_id': 4,
|
||||
'version': 2,
|
||||
'enabled': true,
|
||||
'input': {'prompt': 'Summarise the release notes.'},
|
||||
'workspace': '/srv/research',
|
||||
'rule': {
|
||||
'every': '24h',
|
||||
'days': ['mon', 'wed'],
|
||||
'timezone': 'Europe/London',
|
||||
},
|
||||
'notify_mode': 'auto',
|
||||
});
|
||||
expect(calls.single.containsKey('revision'), isFalse);
|
||||
expect(draft.source, isNull);
|
||||
});
|
||||
|
||||
testWidgets('clock times, paused state and notifications reach the record', (
|
||||
tester,
|
||||
) async {
|
||||
final calls = <JsonMap>[];
|
||||
await pumpScheduleEditor(
|
||||
tester,
|
||||
draft: createDraft(name: 'Clock schedule', prompt: 'Run at times'),
|
||||
onSubmit: (record) async => calls.add(record),
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(scheduleEditorTimerKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Clock times').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Clock times (24h, comma separated)'), findsOneWidget);
|
||||
expect(find.text('Interval (at least 1m)'), findsNothing);
|
||||
|
||||
await enterField(tester, scheduleEditorTimesKey, '09:00, 17:30');
|
||||
await tester.tap(find.byKey(scheduleEditorEnabledKey));
|
||||
await tester.tap(find.byKey(scheduleEditorNotifyKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('off').last);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(scheduleEditorSubmitKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(calls.single['enabled'], isFalse);
|
||||
expect(calls.single['notify_mode'], 'off');
|
||||
expect(calls.single['rule'], {
|
||||
'times': ['09:00', '17:30'],
|
||||
'timezone': 'Europe/London',
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('editing keeps CAS identity and unknown raw fields', (
|
||||
tester,
|
||||
) async {
|
||||
final calls = <JsonMap>[];
|
||||
await pumpScheduleEditor(
|
||||
tester,
|
||||
draft: editDraft(),
|
||||
onSubmit: (record) async => calls.add(record),
|
||||
);
|
||||
expect(find.text('Edit schedule'), findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.widget<TextField>(find.byKey(scheduleEditorNameKey))
|
||||
.controller!
|
||||
.text,
|
||||
'Saved topic',
|
||||
);
|
||||
|
||||
await enterField(tester, scheduleEditorNameKey, 'Edited topic');
|
||||
await tester.tap(find.byKey(scheduleEditorSubmitKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final record = calls.single;
|
||||
expect(record['id'], 9);
|
||||
expect(record['revision'], 13);
|
||||
expect(record['pipeline_id'], 4);
|
||||
expect(record['name'], 'Edited topic');
|
||||
expect(record['input'], {
|
||||
'prompt': 'Topic',
|
||||
'count': 4,
|
||||
'flag': false,
|
||||
'nested': {
|
||||
'list': [null, 2],
|
||||
},
|
||||
});
|
||||
expect(record['rule'], {
|
||||
'times': ['09:00', '17:30'],
|
||||
'days': ['fri', 'mon'],
|
||||
'future': 'keep',
|
||||
});
|
||||
expect(record['model'], 'provider/model');
|
||||
expect(record['stage_models'], {'research': 'provider/other'});
|
||||
expect(record['write_paths'], ['src/file.go']);
|
||||
expect(record['allow_tools'], isTrue);
|
||||
expect(record['title'], 'Saved title');
|
||||
expect(record['output_format'], 'json');
|
||||
expect(record['notify_mode'], 'off');
|
||||
expect(record['server_extra'], {
|
||||
'keep': [1, true],
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
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/domain/editor/schedule_draft.dart';
|
||||
import 'package:pipelines_app/features/schedules/domain/saved_schedule.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/editor/schedule_editor_form.dart';
|
||||
|
||||
import '../../domain/editor/draft_fixtures.dart';
|
||||
|
||||
ScheduleDraft createDraft({
|
||||
String name = '',
|
||||
String prompt = '',
|
||||
String version = '2',
|
||||
String workspace = '/srv/research',
|
||||
String timezone = 'Europe/London',
|
||||
}) =>
|
||||
ScheduleDraft.create(
|
||||
pipelineId: 4,
|
||||
version: version,
|
||||
workspace: workspace,
|
||||
timezone: timezone,
|
||||
)
|
||||
..name = name
|
||||
..prompt = prompt;
|
||||
|
||||
ScheduleDraft editDraft() =>
|
||||
ScheduleDraft.fromSchedule(SavedSchedule(deepCopy(completeRecord())));
|
||||
|
||||
Future<void> pumpScheduleEditor(
|
||||
WidgetTester tester, {
|
||||
required ScheduleDraft draft,
|
||||
required Future<void> Function(JsonMap record) onSubmit,
|
||||
bool cupertino = false,
|
||||
bool dark = false,
|
||||
double width = 390,
|
||||
double height = 1600,
|
||||
double textScale = 1,
|
||||
VoidCallback? onCancel,
|
||||
}) async {
|
||||
tester.view.physicalSize = Size(width, height);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final form = SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: ScheduleEditorForm(
|
||||
draft: draft,
|
||||
onSubmit: onSubmit,
|
||||
onCancel: onCancel,
|
||||
),
|
||||
);
|
||||
Widget scaled(BuildContext context, Widget? app) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: app!,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
theme: CupertinoThemeData(
|
||||
brightness: dark ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
builder: scaled,
|
||||
home: CupertinoPageScaffold(child: SafeArea(child: form)),
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: ThemeData(
|
||||
brightness: dark ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
builder: scaled,
|
||||
home: Scaffold(body: SafeArea(child: form)),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> enterField(WidgetTester tester, Key key, String value) async {
|
||||
await tester.enterText(find.byKey(key), value);
|
||||
await tester.pump();
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
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/editor/schedule_editor_selectors.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/editor/schedule_editor_wording.dart';
|
||||
|
||||
import 'schedule_editor_harness.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('async refusal keeps typed values and a retry can succeed', (
|
||||
tester,
|
||||
) async {
|
||||
final calls = <JsonMap>[];
|
||||
Object? refusal = StateError('revision 13 is stale');
|
||||
await pumpScheduleEditor(
|
||||
tester,
|
||||
draft: createDraft(name: 'Probe schedule', prompt: 'Keep these words'),
|
||||
onSubmit: (record) async {
|
||||
calls.add(record);
|
||||
if (refusal case final error?) throw error;
|
||||
},
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(scheduleEditorSubmitKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(scheduleEditorErrorKey), findsOneWidget);
|
||||
expect(find.textContaining('revision 13 is stale'), findsOneWidget);
|
||||
expect(find.textContaining('Your draft is preserved.'), findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.widget<TextField>(find.byKey(scheduleEditorNameKey))
|
||||
.controller!
|
||||
.text,
|
||||
'Probe schedule',
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<TextField>(find.byKey(scheduleEditorPromptKey))
|
||||
.controller!
|
||||
.text,
|
||||
'Keep these words',
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<FilledButton>(find.byKey(scheduleEditorSubmitKey))
|
||||
.onPressed,
|
||||
isNotNull,
|
||||
);
|
||||
|
||||
refusal = null;
|
||||
await tester.tap(find.byKey(scheduleEditorSubmitKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(calls, hasLength(2));
|
||||
expect(calls.last['name'], 'Probe schedule');
|
||||
expect(find.byKey(scheduleEditorErrorKey), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a sending form locks controls and rejects a second submit', (
|
||||
tester,
|
||||
) async {
|
||||
final gate = Completer<void>();
|
||||
var calls = 0;
|
||||
await pumpScheduleEditor(
|
||||
tester,
|
||||
draft: createDraft(name: 'Probe schedule', prompt: 'Run once'),
|
||||
onSubmit: (_) {
|
||||
calls++;
|
||||
return gate.future;
|
||||
},
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(scheduleEditorSubmitKey));
|
||||
await tester.pump();
|
||||
expect(find.text('Saving…'), findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.widget<FilledButton>(find.byKey(scheduleEditorSubmitKey))
|
||||
.onPressed,
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
tester.widget<TextField>(find.byKey(scheduleEditorNameKey)).enabled,
|
||||
isFalse,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(scheduleEditorSubmitKey));
|
||||
await tester.pump();
|
||||
expect(calls, 1);
|
||||
|
||||
gate.complete();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Save schedule'), findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.widget<FilledButton>(find.byKey(scheduleEditorSubmitKey))
|
||||
.onPressed,
|
||||
isNotNull,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino form uses native fields and action sheets', (
|
||||
tester,
|
||||
) async {
|
||||
final calls = <JsonMap>[];
|
||||
await pumpScheduleEditor(
|
||||
tester,
|
||||
cupertino: true,
|
||||
draft: createDraft(name: 'Cupertino schedule', prompt: 'Native fields'),
|
||||
onSubmit: (record) async => calls.add(record),
|
||||
);
|
||||
expect(find.byType(CupertinoTextField), findsNWidgets(6));
|
||||
expect(find.byType(TextField), findsNothing);
|
||||
expect(find.byType(CupertinoSwitch), findsOneWidget);
|
||||
expect(find.byType(Switch), findsNothing);
|
||||
expect(find.byType(CupertinoCheckbox), findsNWidgets(7));
|
||||
expect(find.byType(Checkbox), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(scheduleEditorTimerKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Clock times').last);
|
||||
await tester.pumpAndSettle();
|
||||
await enterField(tester, scheduleEditorTimesKey, '06:30');
|
||||
await tester.tap(find.byKey(scheduleEditorDayKey('mon')));
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester
|
||||
.widget<CupertinoCheckbox>(find.byKey(scheduleEditorDayKey('mon')))
|
||||
.value,
|
||||
isTrue,
|
||||
);
|
||||
await tester.tap(find.byKey(scheduleEditorEnabledKey));
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(scheduleEditorSubmitKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(calls.single['enabled'], isFalse);
|
||||
expect(calls.single['rule'], {
|
||||
'times': ['06:30'],
|
||||
'days': ['mon'],
|
||||
'timezone': 'Europe/London',
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('Cancel calls the injected callback and sends nothing', (
|
||||
tester,
|
||||
) async {
|
||||
var cancelled = 0;
|
||||
final calls = <JsonMap>[];
|
||||
await pumpScheduleEditor(
|
||||
tester,
|
||||
draft: createDraft(name: 'Probe schedule', prompt: 'Prompt'),
|
||||
onSubmit: (record) async => calls.add(record),
|
||||
onCancel: () => cancelled++,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(scheduleEditorCancelKey));
|
||||
await tester.pump();
|
||||
expect(cancelled, 1);
|
||||
expect(calls, isEmpty);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/editor/schedule_editor_wording.dart';
|
||||
|
||||
import 'schedule_editor_harness.dart';
|
||||
|
||||
const _labels = [
|
||||
scheduleEditorNameLabel,
|
||||
scheduleEditorPromptLabel,
|
||||
scheduleEditorVersionLabel,
|
||||
scheduleEditorWorkspaceLabel,
|
||||
scheduleEditorTimerLabel,
|
||||
scheduleEditorEveryLabel,
|
||||
scheduleEditorDaysLabel,
|
||||
scheduleEditorTimezoneLabel,
|
||||
scheduleEditorEnabledLabel,
|
||||
scheduleEditorEnabledNote,
|
||||
scheduleEditorNotificationsLabel,
|
||||
scheduleEditorSubmitLabel,
|
||||
];
|
||||
|
||||
void main() {
|
||||
testWidgets('Material labels wrap at 320px with 2x text', (tester) async {
|
||||
await pumpScheduleEditor(
|
||||
tester,
|
||||
width: 320,
|
||||
height: 1800,
|
||||
textScale: 2,
|
||||
draft: createDraft(),
|
||||
onSubmit: (JsonMap record) async {},
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
for (final label in _labels) {
|
||||
expect(find.text(label), findsOneWidget, reason: label);
|
||||
}
|
||||
expect(find.byType(TextField), findsNWidgets(6));
|
||||
expect(find.byType(Switch), findsOneWidget);
|
||||
expect(find.byType(Checkbox), findsNWidgets(7));
|
||||
final note = tester.renderObject<RenderParagraph>(
|
||||
find.text(scheduleEditorEnabledNote),
|
||||
);
|
||||
expect(note.size.width, lessThanOrEqualTo(320 - 32));
|
||||
});
|
||||
|
||||
testWidgets('Cupertino dark uses native controls and the native palette', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpScheduleEditor(
|
||||
tester,
|
||||
cupertino: true,
|
||||
dark: true,
|
||||
width: 320,
|
||||
height: 1800,
|
||||
textScale: 2,
|
||||
draft: createDraft(),
|
||||
onSubmit: (JsonMap record) async {},
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
for (final label in _labels) {
|
||||
expect(find.text(label), findsOneWidget, reason: label);
|
||||
}
|
||||
expect(find.byType(CupertinoTextField), findsNWidgets(6));
|
||||
expect(find.byType(CupertinoSwitch), findsOneWidget);
|
||||
expect(find.byType(CupertinoCheckbox), findsNWidgets(7));
|
||||
expect(find.byType(Material), findsNothing);
|
||||
expect(find.byType(TextField), findsNothing);
|
||||
expect(find.byType(Switch), findsNothing);
|
||||
expect(find.byType(Checkbox), findsNothing);
|
||||
|
||||
final context = tester.element(find.byKey(scheduleEditorNameKey));
|
||||
expect(CupertinoTheme.of(context).brightness, Brightness.dark);
|
||||
expect(
|
||||
CupertinoColors.label.resolveFrom(context).toARGB32(),
|
||||
CupertinoColors.label.darkColor.toARGB32(),
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user