feat(app): add native runs list interactions

This commit is contained in:
2026-10-21 14:07:02 +01:00
parent fe50c7c52e
commit 40aa98e20b
2 changed files with 397 additions and 54 deletions
@@ -0,0 +1,180 @@
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/runs/data/runs_repository.dart';
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
import 'package:pipelines_app/features/runs/ui/runs_list.dart';
class _Gateway implements ApiGateway {
final framesController = StreamController<JsonMap>.broadcast();
JsonMap? reply;
Object? failure;
Completer<void>? gate;
@override
Stream<JsonMap> get frames => framesController.stream;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
await gate?.future;
if (failure != null) throw failure!;
return reply ?? {'runs': []};
}
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late _Gateway gateway;
late RunsController controller;
setUp(() {
gateway = _Gateway();
controller = RunsController(RunsRepository(gateway));
});
tearDown(() async {
controller.dispose();
await gateway.framesController.close();
});
Future<void> mount(
WidgetTester tester, {
required bool cupertino,
ValueChanged<num>? onSelected,
}) async {
gateway.reply = {
'runs': [
{'id': 1, 'name': 'Alpha', 'status': 'running', 'scheduled': true},
{'id': 2, 'name': 'Beta', 'status': 'failed', 'scheduled': false},
],
};
await controller.load();
final list = AnimatedBuilder(
animation: controller,
builder: (context, _) =>
RunsList(controller: controller, onSelected: onSelected ?? (_) {}),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: list))
: MaterialApp(home: Scaffold(body: list)),
);
}
testWidgets(
'uses native search and filters runs in CupertinoApp',
(tester) async {
num? selectedRun;
await mount(
tester,
cupertino: true,
onSelected: (id) => selectedRun = id,
);
expect(find.byType(CupertinoSearchTextField), findsOneWidget);
expect(find.text('Alpha'), findsOneWidget);
await tester.enterText(find.byType(CupertinoSearchTextField), 'Beta');
await tester.pumpAndSettle();
expect(find.text('Beta'), findsNWidgets(2));
expect(find.text('Alpha'), findsNothing);
await tester.tap(find.byType(CupertinoListTile));
expect(selectedRun, 2);
await tester.enterText(find.byType(CupertinoSearchTextField), 'missing');
await tester.pumpAndSettle();
expect(find.text('No runs found.'), findsOneWidget);
await tester.enterText(find.byType(CupertinoSearchTextField), '');
await tester.pumpAndSettle();
await tester.tap(find.textContaining('Schedule:'));
await tester.pumpAndSettle();
expect(find.text('Scheduled'), findsWidgets);
await tester.tap(find.text('Scheduled').last);
await tester.pumpAndSettle();
expect(controller.scheduled, 'scheduled');
},
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
);
testWidgets(
'retains Material controls and handles large text on narrow layout',
(tester) async {
tester.view.devicePixelRatio = 2;
tester.view.physicalSize = const Size(780, 1560);
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: const TextScaler.linear(2)),
child: child!,
),
home: Scaffold(
body: AnimatedBuilder(
animation: controller,
builder: (_, _) =>
RunsList(controller: controller, onSelected: (_) {}),
),
),
),
);
gateway.reply = {
'runs': [
{'id': 1, 'name': 'Alpha', 'status': 'running', 'scheduled': true},
{'id': 2, 'name': 'Beta', 'status': 'failed', 'scheduled': false},
],
};
await controller.load();
await tester.pumpAndSettle();
expect(find.byType(TextField), findsOneWidget);
final layoutError = tester.takeException();
expect(
layoutError,
isNull,
reason: layoutError is FlutterError
? layoutError.toStringDeep()
: '$layoutError',
);
},
variant: TargetPlatformVariant.only(TargetPlatform.android),
);
testWidgets(
'shows loading, error and server-empty states distinctly',
(tester) async {
gateway.failure = StateError('offline');
gateway.gate = Completer<void>();
final loading = controller.load();
await tester.pumpWidget(
CupertinoApp(
home: CupertinoPageScaffold(
child: AnimatedBuilder(
animation: controller,
builder: (_, child) =>
RunsList(controller: controller, onSelected: (_) {}),
),
),
),
);
await tester.pump();
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
gateway.gate!.complete();
await loading;
await tester.pumpAndSettle();
expect(find.textContaining('offline'), findsOneWidget);
expect(tester.takeException(), isNull);
gateway.failure = null;
gateway.gate = null;
gateway.reply = {'runs': []};
await controller.load();
await tester.pumpAndSettle();
expect(find.text('No runs found.'), findsOneWidget);
expect(find.textContaining('offline'), findsNothing);
expect(tester.takeException(), isNull);
},
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
);
}