535dee0805
Replace the full-width runs dropdowns and status chips with web-shaped controls: a Material filter popup with checked statuses and triggers, a sort menu, and removable applied-filter chips; Cupertino gets a compact Filter/Sort row plus one action sheet with live check marks. Add RunsController.activeFilterCount and clearFilters(), and use the shared seven-state run vocabulary. Clarify the singular active-filter tooltip.
142 lines
4.8 KiB
Dart
142 lines
4.8 KiB
Dart
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;
|
|
|
|
@override
|
|
Stream<JsonMap> get frames => framesController.stream;
|
|
|
|
@override
|
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async =>
|
|
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}) 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: (_) {}),
|
|
);
|
|
await tester.pumpWidget(
|
|
cupertino
|
|
? CupertinoApp(home: CupertinoPageScaffold(child: list))
|
|
: MaterialApp(home: Scaffold(body: list)),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
testWidgets(
|
|
'material toolbar is a compact menu row with removable applied chips',
|
|
(tester) async {
|
|
await mount(tester, cupertino: false);
|
|
expect(find.byType(DropdownButton<String>), findsNothing);
|
|
expect(find.byType(FilterChip), findsNothing);
|
|
expect(find.text('Filter'), findsOneWidget);
|
|
expect(find.text('Sort: Newest first'), findsOneWidget);
|
|
|
|
await tester.tap(find.text('Filter'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('queued'), findsOneWidget);
|
|
expect(find.text('Any trigger'), findsOneWidget);
|
|
|
|
final failedItem = find.ancestor(
|
|
of: find.text('failed'),
|
|
matching: find.byWidgetPredicate((widget) => widget is PopupMenuItem),
|
|
);
|
|
await tester.tap(failedItem);
|
|
await tester.pumpAndSettle();
|
|
expect(controller.statuses, {'failed'});
|
|
expect(find.text('Filter (1)'), findsOneWidget);
|
|
expect(find.byType(InputChip), findsOneWidget);
|
|
expect(find.text('failed'), findsWidgets);
|
|
expect(find.text('Alpha'), findsNothing);
|
|
expect(find.text('Beta'), findsOneWidget);
|
|
|
|
await tester.tap(find.textContaining('Sort:'));
|
|
await tester.pumpAndSettle();
|
|
final statusItem = find.ancestor(
|
|
of: find.text('Status'),
|
|
matching: find.byWidgetPredicate((widget) => widget is PopupMenuItem),
|
|
);
|
|
await tester.tap(statusItem);
|
|
await tester.pumpAndSettle();
|
|
expect(controller.sort, 'status');
|
|
expect(find.text('Sort: Status'), findsOneWidget);
|
|
|
|
await tester.tap(find.byTooltip('Clear filter: failed'));
|
|
await tester.pumpAndSettle();
|
|
expect(controller.statuses, isEmpty);
|
|
expect(find.byType(InputChip), findsNothing);
|
|
expect(find.text('Filter'), findsOneWidget);
|
|
expect(find.text('Alpha'), findsOneWidget);
|
|
},
|
|
variant: TargetPlatformVariant.only(TargetPlatform.android),
|
|
);
|
|
|
|
testWidgets(
|
|
'cupertino toolbar filters from one sheet and its chip clears the facet',
|
|
(tester) async {
|
|
await mount(tester, cupertino: true);
|
|
expect(find.text('Filter'), findsOneWidget);
|
|
expect(find.text('Sort: Newest first'), findsOneWidget);
|
|
|
|
await tester.tap(find.text('Filter'));
|
|
await tester.pumpAndSettle();
|
|
final failedAction = find.widgetWithText(
|
|
CupertinoActionSheetAction,
|
|
'failed',
|
|
);
|
|
await tester.ensureVisible(failedAction);
|
|
await tester.tap(failedAction);
|
|
await tester.pumpAndSettle();
|
|
expect(controller.statuses, {'failed'});
|
|
expect(find.text('✓ failed'), findsOneWidget);
|
|
expect(find.text('Filter (1)'), findsOneWidget);
|
|
|
|
await tester.tap(find.text('Done'));
|
|
await tester.pumpAndSettle();
|
|
final failedChip = find.widgetWithText(CupertinoButton, 'failed');
|
|
expect(failedChip, findsOneWidget);
|
|
expect(find.text('Alpha'), findsNothing);
|
|
|
|
await tester.tap(failedChip);
|
|
await tester.pumpAndSettle();
|
|
expect(controller.statuses, isEmpty);
|
|
expect(find.text('Filter'), findsOneWidget);
|
|
expect(find.text('Alpha'), findsOneWidget);
|
|
},
|
|
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
|
|
);
|
|
}
|