Merge branch 'main' into flutter/templates-gallery

This commit is contained in:
2026-10-21 22:04:02 +01:00
27 changed files with 3267 additions and 83 deletions
@@ -0,0 +1,180 @@
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart';
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'chat_composer_fixtures.dart';
/// A store whose read resolves only when the test says so.
class _DelayedDraftStore implements ChatDraftStore {
_DelayedDraftStore(this.saved);
final String saved;
final reads = <Completer<String>>[];
final writes = <String>[];
@override
Future<String> read(String sessionId) {
final completer = Completer<String>();
reads.add(completer);
return completer.future;
}
@override
Future<bool> write(String sessionId, String text) async {
writes.add(text);
return true;
}
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
test(
'SharedPreferences stores the exact per-session draft and clears it',
() async {
SharedPreferences.setMockInitialValues({});
const store = SharedPreferencesChatDraftStore();
expect(await store.write('a', ' line one\nline two '), isTrue);
expect(await store.read('a'), ' line one\nline two ');
expect(await store.read('b'), '');
final preferences = await SharedPreferences.getInstance();
expect(
preferences.getString('${chatDraftKeyPrefix}a'),
' line one\nline two ',
);
expect(await store.write('a', ''), isTrue);
expect(await store.read('a'), '');
expect(preferences.getString('${chatDraftKeyPrefix}a'), isNull);
},
);
test('drafts stay isolated per conversation and load exactly', () async {
final drafts = MemoryChatDraftStore();
final firstGateway = FakeComposerGateway();
final secondGateway = FakeComposerGateway();
final first = ChatComposerController(firstGateway, 'a', drafts: drafts);
final second = ChatComposerController(secondGateway, 'b', drafts: drafts);
addTearDown(first.dispose);
addTearDown(second.dispose);
addTearDown(firstGateway.close);
addTearDown(secondGateway.close);
await first.setDraft('draft a\n');
await second.setDraft('draft b');
expect(drafts.entries, {'a': 'draft a\n', 'b': 'draft b'});
final reopened = ChatComposerController(
FakeComposerGateway(),
'a',
drafts: drafts,
);
addTearDown(reopened.dispose);
await reopened.loadDraft();
expect(reopened.draft, 'draft a\n');
});
test('a draft typed while the saved draft loads is not replaced', () async {
final store = _DelayedDraftStore('saved');
final controller = ChatComposerController(
FakeComposerGateway(),
's',
drafts: store,
);
addTearDown(controller.dispose);
final loading = controller.loadDraft();
await pumpEventQueue();
await controller.setDraft('typed');
store.reads.single.complete('saved');
await loading;
expect(controller.draft, 'typed');
expect(store.writes.last, 'typed');
});
test(
'an unreadable store leaves the draft empty and can load later',
() async {
final drafts = MemoryChatDraftStore(drafts: {'s': 'saved'})
..failReads = true;
final controller = ChatComposerController(
FakeComposerGateway(),
's',
drafts: drafts,
);
addTearDown(controller.dispose);
await controller.loadDraft();
expect(controller.draft, '');
drafts.failReads = false;
await controller.loadDraft();
expect(controller.draft, 'saved');
},
);
test(
'a failed draft save keeps the text and reports it, then clears',
() async {
final drafts = MemoryChatDraftStore()..failWrites = true;
final controller = ChatComposerController(
FakeComposerGateway(),
's',
drafts: drafts,
);
addTearDown(controller.dispose);
await controller.setDraft('still here');
expect(controller.draft, 'still here');
expect(controller.draftError, ChatComposerController.draftSaveFailed);
expect(drafts.entries, isEmpty);
drafts.failWrites = false;
await controller.setDraft('saved now');
expect(controller.draftError, isNull);
expect(drafts.entries, {'s': 'saved now'});
},
);
test('rapid edits persist in order and the newest draft wins', () async {
final drafts = MemoryChatDraftStore();
final controller = ChatComposerController(
FakeComposerGateway(),
's',
drafts: drafts,
);
addTearDown(controller.dispose);
final first = controller.setDraft('a');
final second = controller.setDraft('ab');
final third = controller.setDraft('abc');
await Future.wait([first, second, third]);
expect(controller.draft, 'abc');
expect(drafts.entries, {'s': 'abc'});
});
test('a failed draft clear still sends and stays visibly unsaved', () async {
final drafts = MemoryChatDraftStore()..failWrites = true;
final gateway = FakeComposerGateway();
gateway.prompt = (_, _) async => const {};
final controller = ChatComposerController(gateway, 's', drafts: drafts);
addTearDown(controller.dispose);
addTearDown(gateway.close);
await controller.setDraft('send me');
await controller.send();
expect(gateway.promptBodies.single['text'], 'send me');
expect(controller.draft, '');
expect(controller.error, isNull);
// The in-memory draft cleared; the device store still reports the failure.
expect(controller.draftError, ChatComposerController.draftSaveFailed);
});
}
@@ -0,0 +1,40 @@
import 'dart:async';
import 'package:pipelines_app/core/api_gateway.dart';
/// A fake gateway for the composer. The test controls each prompt/interrupt
/// reply; unsolicited frames are pushed through [emitEvent].
class FakeComposerGateway implements ApiGateway {
final calls = <({String type, JsonMap fields})>[];
final _frames = StreamController<JsonMap>.broadcast();
Future<JsonMap> Function(String text, String operationId)? prompt;
Future<JsonMap> Function()? interrupt;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
calls.add((type: type, fields: fields));
switch (type) {
case 'chat_prompt':
final body = fields['chat_prompt'] as JsonMap? ?? const {};
return prompt == null
? <String, dynamic>{}
: prompt!('${body['text'] ?? ''}', '${body['operation_id'] ?? ''}');
case 'chat_interrupt':
return interrupt == null ? <String, dynamic>{} : interrupt!();
}
return <String, dynamic>{};
}
@override
Stream<JsonMap> get frames => _frames.stream;
void emitEvent(JsonMap body) =>
_frames.add({'type': 'chat_event', 'chat_event': body});
List<JsonMap> get promptBodies => calls
.where((call) => call.type == 'chat_prompt')
.map((call) => call.fields['chat_prompt'] as JsonMap)
.toList();
void close() => _frames.close();
}
@@ -0,0 +1,240 @@
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart';
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
import 'chat_composer_fixtures.dart';
void main() {
late FakeComposerGateway gateway;
late MemoryChatDraftStore drafts;
late ChatComposerController controller;
late List<ChatComposerSend> optimistic;
late List<String> rejected;
late int sequence;
setUp(() {
gateway = FakeComposerGateway();
drafts = MemoryChatDraftStore();
optimistic = [];
rejected = [];
sequence = 0;
controller = ChatComposerController(
gateway,
's',
drafts: drafts,
newOperationId: () => 'op/${++sequence}',
onOptimistic: optimistic.add,
onRejected: (send, error) => rejected.add(error),
);
});
tearDown(() {
controller.dispose();
gateway.close();
});
test('sends the exact trimmed wire identity and clears the draft', () async {
await controller.setDraft(' hello ');
await controller.send();
expect(gateway.calls, hasLength(1));
expect(gateway.calls.single.type, 'chat_prompt');
expect(gateway.calls.single.fields, {
'chat_prompt': {
'session_id': 's',
'text': 'hello',
'operation_id': 'op/1',
'native_message_id': 'msg_op1',
},
});
expect(controller.draft, '');
expect(drafts.entries, isEmpty);
expect(controller.sending, isFalse);
expect(controller.error, isNull);
expect(optimistic.single.text, 'hello');
expect(optimistic.single.operationId, 'op/1');
expect(optimistic.single.nativeMessageId, 'msg_op1');
expect(optimistic.single.optimisticId, 'msg_op1');
});
test('a whitespace-only draft sends nothing', () async {
await controller.setDraft(' \n ');
await controller.send();
expect(gateway.calls, isEmpty);
expect(optimistic, isEmpty);
expect(controller.draft, ' \n ');
expect(controller.sending, isFalse);
});
test('a second send is refused while one request is in flight', () async {
final reply = Completer<Map<String, dynamic>>();
gateway.prompt = (_, _) => reply.future;
await controller.setDraft('one');
final first = controller.send();
await pumpEventQueue();
expect(controller.sending, isTrue);
expect(gateway.promptBodies, hasLength(1));
await controller.send();
expect(gateway.promptBodies, hasLength(1));
expect(optimistic, hasLength(1));
reply.complete(const {});
await first;
expect(controller.sending, isFalse);
});
test('a refused unchanged intent retries with the same identity', () async {
var fail = true;
gateway.prompt = (_, _) async {
if (fail) throw StateError('response lost');
return const {};
};
await controller.setDraft(' keep me ');
await controller.send();
expect(controller.error, contains('response lost'));
expect(controller.draft, ' keep me ');
expect(await drafts.read('s'), ' keep me ');
expect(rejected.single, contains('response lost'));
fail = false;
await controller.send();
expect(gateway.promptBodies.map((body) => body['operation_id']), [
'op/1',
'op/1',
]);
expect(gateway.promptBodies.map((body) => body['native_message_id']), [
'msg_op1',
'msg_op1',
]);
expect(controller.draft, '');
expect(controller.error, isNull);
fail = true;
await controller.setDraft('other');
await controller.send();
expect(gateway.promptBodies.last['operation_id'], 'op/2');
expect(gateway.promptBodies.last['native_message_id'], 'msg_op2');
});
test('a refusal keeps newer typing instead of restoring the draft', () async {
final reply = Completer<Map<String, dynamic>>();
gateway.prompt = (_, _) => reply.future;
await controller.setDraft('original');
final sending = controller.send();
await pumpEventQueue();
await controller.setDraft('newer');
reply.completeError(StateError('refused'));
await sending;
expect(controller.draft, 'newer');
expect(await drafts.read('s'), 'newer');
expect(controller.error, contains('refused'));
expect(rejected.single, contains('refused'));
// The optimistic turn still carries the intent that was refused.
expect(optimistic.single.text, 'original');
});
test(
'takes the queued flag from the reply and clears it on a live frame',
() async {
gateway.prompt = (_, _) async => {'chat_queued': true};
await controller.setDraft('first');
await controller.send();
expect(controller.queued, isTrue);
gateway.emitEvent({'session_id': 'other', 'kind': 'text'});
await pumpEventQueue();
expect(controller.queued, isTrue, reason: 'not this conversation');
gateway.emitEvent({'session_id': 's', 'kind': 'usage'});
gateway.emitEvent({'session_id': 's', 'kind': 'compaction'});
await pumpEventQueue();
expect(controller.queued, isTrue, reason: 'no turn moved on');
gateway.emitEvent({'session_id': 's', 'kind': 'step'});
await pumpEventQueue();
expect(controller.queued, isFalse);
},
);
test('a reply without chat_queued clears a previous queued flag', () async {
gateway.prompt = (_, _) async => {'chat_queued': true};
await controller.setDraft('first');
await controller.send();
expect(controller.queued, isTrue);
gateway.prompt = (_, _) async => const {};
await controller.setDraft('second');
await controller.send();
expect(controller.queued, isFalse);
});
test(
'Stop sends the exact interrupt query and leaves state to the frame',
() async {
gateway.prompt = (_, _) async => {'chat_queued': true};
await controller.setDraft('queued');
await controller.send();
await controller.stop();
final stop = gateway.calls.singleWhere(
(call) => call.type == 'chat_interrupt',
);
expect(stop.fields, {
'chat_query': {'session_id': 's'},
});
expect(controller.error, isNull);
expect(controller.stopping, isFalse);
// Nothing settles the queued prompt behind the composer's back.
expect(controller.queued, isTrue);
},
);
test('a refused Stop stays visible and settles nothing', () async {
gateway.prompt = (_, _) async => {'chat_queued': true};
await controller.setDraft('queued');
await controller.send();
gateway.interrupt = () async => throw StateError('cannot stop');
await controller.stop();
expect(controller.error, contains('cannot stop'));
expect(controller.stopping, isFalse);
expect(controller.queued, isTrue);
expect(controller.sending, isFalse);
});
test('a late reply after disposal changes and reports nothing', () async {
final reply = Completer<Map<String, dynamic>>();
gateway.prompt = (_, _) => reply.future;
await controller.setDraft('bye');
final sending = controller.send();
await pumpEventQueue();
expect(optimistic, hasLength(1));
controller.dispose();
gateway.emitEvent({'session_id': 's', 'kind': 'step'});
await controller.send();
expect(gateway.promptBodies, hasLength(1));
reply.completeError(StateError('late response'));
await sending;
expect(rejected, isEmpty);
expect(controller.error, isNull);
expect(controller.draft, '');
});
}
@@ -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(),
);
});
}
@@ -0,0 +1,25 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/templates/data/template_repository.dart';
import 'template_test_support.dart';
void main() {
test(
'a malformed created detail never becomes a claimed successful create',
() async {
for (final id in [null, 0, -1, 'unknown', 1.5]) {
final gateway = RecordingGateway([
{
'type': 'submitted',
'detail': {'id': id, 'name': 'Unconfirmed'},
},
]);
await expectLater(
TemplateRepository(gateway).submit('Topic', source),
throwsA(isA<TemplateRepositoryException>()),
);
expect(gateway.calls.single.fields['create_only'], isTrue);
}
},
);
}