feat(app): compact runs filter and sort toolbar
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.
This commit is contained in:
@@ -30,6 +30,14 @@ class RunsController extends ChangeNotifier {
|
|||||||
|
|
||||||
num? get selectedRunId => _selectedId;
|
num? get selectedRunId => _selectedId;
|
||||||
|
|
||||||
|
/// The number of narrowing facets, one per status set, pipeline, time range
|
||||||
|
/// and trigger choice. Mirrors the browser's `runFiltersActiveCount`.
|
||||||
|
int get activeFilterCount =>
|
||||||
|
(statuses.isNotEmpty ? 1 : 0) +
|
||||||
|
(pipelineId != null ? 1 : 0) +
|
||||||
|
(timeRange != 'any_time' && timeRange.isNotEmpty ? 1 : 0) +
|
||||||
|
(scheduled == 'scheduled' || scheduled == 'unscheduled' ? 1 : 0);
|
||||||
|
|
||||||
void listen(Stream<JsonMap> frames) {
|
void listen(Stream<JsonMap> frames) {
|
||||||
_subscription?.cancel();
|
_subscription?.cancel();
|
||||||
_subscription = frames
|
_subscription = frames
|
||||||
@@ -174,6 +182,15 @@ class RunsController extends ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns every filter to its default, like the browser's `Clear filters`.
|
||||||
|
void clearFilters() {
|
||||||
|
statuses.clear();
|
||||||
|
pipelineId = null;
|
||||||
|
timeRange = 'any_time';
|
||||||
|
scheduled = 'any';
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
void _event(JsonMap frame) {
|
void _event(JsonMap frame) {
|
||||||
final folded = foldRunEvent(runs, frame);
|
final folded = foldRunEvent(runs, frame);
|
||||||
runs = folded.runs;
|
runs = folded.runs;
|
||||||
|
|||||||
@@ -2,92 +2,179 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../../../ui/adaptive/host.dart';
|
import '../../../ui/adaptive/host.dart';
|
||||||
|
import '../domain/run_models.dart';
|
||||||
import 'runs_controller.dart';
|
import 'runs_controller.dart';
|
||||||
|
|
||||||
/// The runs list's native sort/schedule/status controls.
|
/// The runs list's compact native filter/sort toolbar and applied-filter chips.
|
||||||
///
|
///
|
||||||
/// On Cupertino the controls stay in one horizontally scrollable strip: a phone
|
/// Mirrors the browser's run toolbar: one `Filter` menu carrying the status and
|
||||||
/// at a doubled text scale cannot stack seven buttons above the list without
|
/// trigger facets, one `Sort:` menu, and a removable chip per applied facet.
|
||||||
/// crushing it, and the browser's narrow toolbar is likewise one row. Material
|
/// The buttons sit in a single horizontally scrollable row so a phone at a
|
||||||
/// keeps its native dropdowns and filter chips.
|
/// doubled text scale can still reach them without crushing the list.
|
||||||
class RunsFilters extends StatelessWidget {
|
class RunsFilters extends StatelessWidget {
|
||||||
const RunsFilters({super.key, required this.controller});
|
const RunsFilters({super.key, required this.controller});
|
||||||
|
|
||||||
final RunsController controller;
|
final RunsController controller;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) =>
|
Widget build(BuildContext context) {
|
||||||
usesCupertinoHost(context) ? _cupertino(context) : _material(context);
|
final count = controller.activeFilterCount;
|
||||||
|
return Column(
|
||||||
Widget _cupertino(BuildContext context) => SingleChildScrollView(
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
children: [
|
||||||
CupertinoButton(
|
SingleChildScrollView(
|
||||||
onPressed: () => _choose(
|
scrollDirection: Axis.horizontal,
|
||||||
context,
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4),
|
||||||
'Sort runs',
|
child: usesCupertinoHost(context)
|
||||||
_sorts,
|
? _cupertinoToolbar(context, count)
|
||||||
controller.sort,
|
: _materialToolbar(count),
|
||||||
controller.setSort,
|
|
||||||
),
|
|
||||||
child: Text('Sort: ${_sortLabel(controller.sort)}'),
|
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
if (count > 0) _appliedFilters(context),
|
||||||
CupertinoButton(
|
|
||||||
onPressed: () => _choose(
|
|
||||||
context,
|
|
||||||
'Schedule',
|
|
||||||
_schedules,
|
|
||||||
controller.scheduled,
|
|
||||||
controller.setScheduled,
|
|
||||||
),
|
|
||||||
child: Text('Schedule: ${_scheduleLabel(controller.scheduled)}'),
|
|
||||||
),
|
|
||||||
for (final status in _statuses) ...[
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
CupertinoButton(
|
|
||||||
onPressed: () => controller.setStatus(status),
|
|
||||||
child: Text(
|
|
||||||
'${controller.statuses.contains(status) ? '✓ ' : ''}${_title(status)}',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _materialToolbar(int count) => Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
PopupMenuButton<_FilterChoice>(
|
||||||
|
tooltip: count > 0
|
||||||
|
? '$count active ${count == 1 ? 'filter' : 'filters'}'
|
||||||
|
: 'Filter runs',
|
||||||
|
onSelected: _apply,
|
||||||
|
itemBuilder: (context) => _materialMenuItems(),
|
||||||
|
child: _materialButton(
|
||||||
|
count > 0 ? Icons.filter_alt : Icons.filter_alt_outlined,
|
||||||
|
count > 0 ? 'Filter ($count)' : 'Filter',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PopupMenuButton<String>(
|
||||||
|
tooltip: 'Sort runs',
|
||||||
|
onSelected: controller.setSort,
|
||||||
|
itemBuilder: (context) => [
|
||||||
|
for (final sort in _sorts)
|
||||||
|
CheckedPopupMenuItem(
|
||||||
|
value: sort.$1,
|
||||||
|
checked: controller.sort == sort.$1,
|
||||||
|
child: Text(sort.$2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
child: _materialButton(
|
||||||
|
Icons.sort,
|
||||||
|
'Sort: ${_sortLabel(controller.sort)}',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _materialButton(IconData icon, String label) => Semantics(
|
||||||
|
button: true,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsetsDirectional.fromSTEB(12, 8, 12, 8),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [Icon(icon), const SizedBox(width: 6), Text(label)],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
Widget _material(BuildContext context) => Wrap(
|
List<PopupMenuEntry<_FilterChoice>> _materialMenuItems() => [
|
||||||
spacing: 8,
|
for (final status in runStates)
|
||||||
children: [
|
CheckedPopupMenuItem(
|
||||||
DropdownButton<String>(
|
value: (kind: 'status', value: status),
|
||||||
value: controller.sort,
|
checked: controller.statuses.contains(status),
|
||||||
isExpanded: true,
|
child: Text(status),
|
||||||
onChanged: (v) {
|
|
||||||
if (v != null) controller.setSort(v);
|
|
||||||
},
|
|
||||||
items: _sorts
|
|
||||||
.map((e) => DropdownMenuItem(value: e.$1, child: Text(e.$2)))
|
|
||||||
.toList(),
|
|
||||||
),
|
),
|
||||||
DropdownButton<String>(
|
const PopupMenuDivider(),
|
||||||
value: controller.scheduled,
|
for (final schedule in _schedules)
|
||||||
isExpanded: true,
|
CheckedPopupMenuItem(
|
||||||
onChanged: (v) {
|
value: (kind: 'schedule', value: schedule.$1),
|
||||||
if (v != null) controller.setScheduled(v);
|
checked: controller.scheduled == schedule.$1,
|
||||||
},
|
child: Text(schedule.$2),
|
||||||
items: _schedules
|
),
|
||||||
.map((e) => DropdownMenuItem(value: e.$1, child: Text(e.$2)))
|
if (controller.activeFilterCount > 0) ...[
|
||||||
.toList(),
|
const PopupMenuDivider(),
|
||||||
|
const PopupMenuItem(
|
||||||
|
value: (kind: 'clear', value: ''),
|
||||||
|
child: Text('Clear filters'),
|
||||||
),
|
),
|
||||||
for (final status in _statuses)
|
|
||||||
FilterChip(
|
|
||||||
label: Text(_title(status)),
|
|
||||||
selected: controller.statuses.contains(status),
|
|
||||||
onSelected: (_) => controller.setStatus(status),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
void _apply(_FilterChoice choice) {
|
||||||
|
if (choice.kind == 'status') {
|
||||||
|
controller.setStatus(choice.value);
|
||||||
|
} else if (choice.kind == 'schedule') {
|
||||||
|
controller.setScheduled(choice.value);
|
||||||
|
} else {
|
||||||
|
controller.clearFilters();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _cupertinoToolbar(BuildContext context, int count) => Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
CupertinoButton(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
||||||
|
minimumSize: Size.zero,
|
||||||
|
onPressed: () => _showCupertinoFilter(context),
|
||||||
|
child: Text(count > 0 ? 'Filter ($count)' : 'Filter'),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
CupertinoButton(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
||||||
|
minimumSize: Size.zero,
|
||||||
|
onPressed: () => _choose(
|
||||||
|
context,
|
||||||
|
'Sort runs',
|
||||||
|
_sorts,
|
||||||
|
controller.sort,
|
||||||
|
controller.setSort,
|
||||||
|
),
|
||||||
|
child: Text('Sort: ${_sortLabel(controller.sort)}'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
/// One sheet for both facets, mirroring the browser's filter menu. Tapping an
|
||||||
|
/// option keeps the sheet open so several statuses can be toggled; the check
|
||||||
|
/// marks redraw from the controller and `Done` dismisses it.
|
||||||
|
Future<void> _showCupertinoFilter(
|
||||||
|
BuildContext context,
|
||||||
|
) => showCupertinoModalPopup<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (sheetContext) => ListenableBuilder(
|
||||||
|
listenable: controller,
|
||||||
|
builder: (context, _) => CupertinoActionSheet(
|
||||||
|
title: const Text('Filter runs'),
|
||||||
|
actions: [
|
||||||
|
for (final status in runStates)
|
||||||
|
CupertinoActionSheetAction(
|
||||||
|
onPressed: () => controller.setStatus(status),
|
||||||
|
child: Text(
|
||||||
|
'${controller.statuses.contains(status) ? '✓ ' : ''}$status',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
for (final schedule in _schedules)
|
||||||
|
CupertinoActionSheetAction(
|
||||||
|
onPressed: () => controller.setScheduled(schedule.$1),
|
||||||
|
child: Text(
|
||||||
|
'${controller.scheduled == schedule.$1 ? '✓ ' : ''}'
|
||||||
|
'${schedule.$2}',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (controller.activeFilterCount > 0)
|
||||||
|
CupertinoActionSheetAction(
|
||||||
|
onPressed: controller.clearFilters,
|
||||||
|
child: const Text('Clear filters'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
cancelButton: CupertinoActionSheetAction(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: const Text('Done'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<void> _choose(
|
Future<void> _choose(
|
||||||
@@ -116,23 +203,101 @@ class RunsFilters extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
if (value != null && value != selected) onSelected(value);
|
if (value != null && value != selected) onSelected(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _appliedFilters(BuildContext context) {
|
||||||
|
final applied = _applied();
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4),
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 4,
|
||||||
|
children: [for (final entry in applied) _appliedChip(context, entry)],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<({String label, VoidCallback clear})> _applied() {
|
||||||
|
final applied = <({String label, VoidCallback clear})>[];
|
||||||
|
final pipeline = _pipelineLabel;
|
||||||
|
if (pipeline != null) {
|
||||||
|
applied.add((label: pipeline, clear: () => controller.setPipeline(null)));
|
||||||
|
}
|
||||||
|
for (final status in controller.statuses) {
|
||||||
|
applied.add((label: status, clear: () => controller.setStatus(status)));
|
||||||
|
}
|
||||||
|
if (controller.scheduled != 'any') {
|
||||||
|
applied.add((
|
||||||
|
label: _scheduleLabel(controller.scheduled),
|
||||||
|
clear: () => controller.setScheduled('any'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return applied;
|
||||||
|
}
|
||||||
|
|
||||||
|
String? get _pipelineLabel {
|
||||||
|
final id = controller.pipelineId;
|
||||||
|
if (id == null) return null;
|
||||||
|
for (final run in controller.runs) {
|
||||||
|
if (run['pipeline_id'] == id) {
|
||||||
|
final name = '${run['name'] ?? ''}'.trim();
|
||||||
|
if (name.isNotEmpty) return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 'Pipeline $id';
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _appliedChip(
|
||||||
|
BuildContext context,
|
||||||
|
({String label, VoidCallback clear}) entry,
|
||||||
|
) {
|
||||||
|
final clearLabel = 'Clear filter: ${entry.label}';
|
||||||
|
if (usesCupertinoHost(context)) {
|
||||||
|
return Semantics(
|
||||||
|
button: true,
|
||||||
|
label: clearLabel,
|
||||||
|
excludeSemantics: true,
|
||||||
|
onTap: entry.clear,
|
||||||
|
child: CupertinoButton(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||||
|
minimumSize: Size.zero,
|
||||||
|
onPressed: entry.clear,
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Flexible(
|
||||||
|
child: Text(entry.label, overflow: TextOverflow.ellipsis),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
const Icon(CupertinoIcons.xmark_circle_fill, size: 16),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return InputChip(
|
||||||
|
label: Text(entry.label),
|
||||||
|
onDeleted: entry.clear,
|
||||||
|
deleteButtonTooltipMessage: clearLabel,
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef _FilterChoice = ({String kind, String value});
|
||||||
|
|
||||||
const _sorts = [
|
const _sorts = [
|
||||||
('newest_first', 'Newest'),
|
('newest_first', 'Newest first'),
|
||||||
('oldest_first', 'Oldest'),
|
('oldest_first', 'Oldest first'),
|
||||||
('pipeline_name', 'Pipeline'),
|
('pipeline_name', 'Pipeline name'),
|
||||||
('status', 'Status'),
|
('status', 'Status'),
|
||||||
];
|
];
|
||||||
const _schedules = [
|
const _schedules = [
|
||||||
('any', 'Any schedule'),
|
('any', 'Any trigger'),
|
||||||
('scheduled', 'Scheduled'),
|
('scheduled', 'Scheduled runs'),
|
||||||
('unscheduled', 'Unscheduled'),
|
('unscheduled', 'Not scheduled'),
|
||||||
];
|
];
|
||||||
const _statuses = ['queued', 'running', 'waiting', 'succeeded', 'failed'];
|
|
||||||
String _sortLabel(String value) =>
|
String _sortLabel(String value) =>
|
||||||
_sorts.firstWhere((e) => e.$1 == value, orElse: () => _sorts.first).$2;
|
_sorts.firstWhere((e) => e.$1 == value, orElse: () => _sorts.first).$2;
|
||||||
String _scheduleLabel(String value) => _schedules
|
String _scheduleLabel(String value) => _schedules
|
||||||
.firstWhere((e) => e.$1 == value, orElse: () => _schedules.first)
|
.firstWhere((e) => e.$1 == value, orElse: () => _schedules.first)
|
||||||
.$2;
|
.$2;
|
||||||
String _title(String value) => '${value[0].toUpperCase()}${value.substring(1)}';
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class RunsList extends StatelessWidget {
|
|||||||
_heading(context),
|
_heading(context),
|
||||||
if (controller.error != null) _inlineError(context),
|
if (controller.error != null) _inlineError(context),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 4),
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
||||||
child: usesCupertinoHost(context)
|
child: usesCupertinoHost(context)
|
||||||
? CupertinoSearchTextField(
|
? CupertinoSearchTextField(
|
||||||
placeholder: 'Filter runs',
|
placeholder: 'Filter runs',
|
||||||
@@ -63,7 +63,8 @@ class RunsList extends StatelessWidget {
|
|||||||
)
|
)
|
||||||
: TextField(
|
: TextField(
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Filter runs',
|
hintText: 'Filter runs',
|
||||||
|
isDense: true,
|
||||||
prefixIcon: Icon(Icons.search),
|
prefixIcon: Icon(Icons.search),
|
||||||
),
|
),
|
||||||
onChanged: controller.setQuery,
|
onChanged: controller.setQuery,
|
||||||
@@ -93,7 +94,11 @@ class RunsList extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: controller.usage == null
|
child: controller.usage == null
|
||||||
? const SizedBox.shrink()
|
? const SizedBox.shrink()
|
||||||
: Text('Usage: ${controller.usage}'),
|
: Text(
|
||||||
|
'Usage: ${controller.usage}',
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
NeedsYouRunsHeading(
|
NeedsYouRunsHeading(
|
||||||
rows: controller.runs,
|
rows: controller.runs,
|
||||||
|
|||||||
@@ -380,4 +380,23 @@ void main() {
|
|||||||
expect(controller.runs.first['title'], 'Late rename');
|
expect(controller.runs.first['title'], 'Late rename');
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test('active filter count treats each facet once and clears all', () {
|
||||||
|
expect(controller.activeFilterCount, 0);
|
||||||
|
|
||||||
|
controller.setStatus('failed');
|
||||||
|
controller.setStatus('running');
|
||||||
|
expect(controller.activeFilterCount, 1);
|
||||||
|
|
||||||
|
controller.setScheduled('scheduled');
|
||||||
|
controller.setPipeline(4);
|
||||||
|
expect(controller.activeFilterCount, 3);
|
||||||
|
|
||||||
|
controller.clearFilters();
|
||||||
|
expect(controller.activeFilterCount, 0);
|
||||||
|
expect(controller.statuses, isEmpty);
|
||||||
|
expect(controller.pipelineId, isNull);
|
||||||
|
expect(controller.scheduled, 'any');
|
||||||
|
expect(controller.timeRange, 'any_time');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,12 +87,23 @@ void main() {
|
|||||||
expect(find.text('No runs found.'), findsOneWidget);
|
expect(find.text('No runs found.'), findsOneWidget);
|
||||||
await tester.enterText(find.byType(CupertinoSearchTextField), '');
|
await tester.enterText(find.byType(CupertinoSearchTextField), '');
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
await tester.tap(find.textContaining('Schedule:'));
|
await tester.tap(find.text('Filter'));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.text('Scheduled'), findsWidgets);
|
final scheduled = find.widgetWithText(
|
||||||
await tester.tap(find.text('Scheduled').last);
|
CupertinoActionSheetAction,
|
||||||
|
'Scheduled runs',
|
||||||
|
);
|
||||||
|
await tester.ensureVisible(scheduled);
|
||||||
|
await tester.tap(scheduled);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(controller.scheduled, 'scheduled');
|
expect(controller.scheduled, 'scheduled');
|
||||||
|
await tester.tap(find.text('Done'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Scheduled runs'), findsOneWidget);
|
||||||
|
await tester.tap(find.text('Scheduled runs'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(controller.scheduled, 'any');
|
||||||
|
expect(find.text('Scheduled runs'), findsNothing);
|
||||||
},
|
},
|
||||||
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
|
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
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),
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user