Files
pipelines/app/test/features/runs/ui/runs_sheets_test.dart
T
alan f3d6013ef5 Remove Cupertino variants from runs sheet tests
Keep the runs sheet coverage focused on the Material-only app path and remove obsolete Cupertino hosts and loop variants.
2026-11-11 03:04:27 +00:00

170 lines
5.8 KiB
Dart

import 'dart:async';
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_filter_sheet.dart';
import 'package:pipelines_app/features/runs/ui/runs_list.dart';
import 'package:pipelines_app/ui/layout/app_sheet_header.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': []};
}
/// The Runs sheets share one header (title and Done), single-choice groups
/// use check rows, statuses read in sentence case, and the usage page neither
/// repeats its title nor draws a chart of zeros.
void main() {
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, {String? createdAt}) async {
tester.view.physicalSize = const Size(800, 1400);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final at = createdAt ?? DateTime.now().toIso8601String();
gateway.reply = {
'runs': [
{
'id': 1,
'pipeline_id': 9,
'name': 'Alpha',
'status': 'running',
'created_at': at,
'scheduled': true,
},
],
};
await controller.load();
final list = AnimatedBuilder(
animation: controller,
builder: (context, _) =>
RunsList(controller: controller, onSelected: (_) {}),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: list)));
await tester.pumpAndSettle();
}
testWidgets('filter sheet has a header whose Done closes it', (tester) async {
await mount(tester);
await tester.tap(find.byKey(const ValueKey('runs.filter')));
await tester.pumpAndSettle();
expect(find.byType(AppSheetHeader), findsOneWidget);
expect(
find.descendant(
of: find.byType(AppSheetHeader),
matching: find.text(runsFilterTitle),
),
findsOneWidget,
);
expect(find.text('Queued'), findsOneWidget);
expect(find.text('queued'), findsNothing);
expect(find.byKey(runsFilterClearKey), findsNothing);
await tester.tap(find.text('Last 7 days'));
await tester.pumpAndSettle();
expect(controller.timeRange, 'last_7_days');
// An active filter offers Clear in the header.
expect(find.byKey(runsFilterClearKey), findsOneWidget);
await tester.tap(find.byKey(runsFilterDoneKey));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('runs.filter.sheet')), findsNothing);
// The applied chip reads in sentence case too.
expect(find.textContaining('Last 7 days'), findsOneWidget);
});
testWidgets('Material single-choice groups are check rows, not checkboxes', (
tester,
) async {
await mount(tester);
await tester.tap(find.byKey(const ValueKey('runs.filter')));
await tester.pumpAndSettle();
// Seven statuses may be combined: those keep their checkboxes.
expect(find.byType(CheckboxListTile), findsNWidgets(7));
final anyTime = find.widgetWithText(ListTile, 'Any time');
expect(anyTime, findsOneWidget);
expect(
find.descendant(of: anyTime, matching: find.byIcon(Icons.check)),
findsOneWidget,
);
expect(
find.descendant(of: anyTime, matching: find.byType(Checkbox)),
findsNothing,
);
final today = find.widgetWithText(ListTile, 'Today');
expect(
find.descendant(of: today, matching: find.byIcon(Icons.check)),
findsNothing,
);
expect(tester.widget<ListTile>(anyTime).selected, isTrue);
});
testWidgets('Material sort opens an anchored choice menu', (tester) async {
await mount(tester);
await tester.tap(find.byKey(const ValueKey('runs.sort')));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('app-choice-menu')), findsOneWidget);
await tester.tap(find.text('Oldest first'));
await tester.pumpAndSettle();
expect(controller.sort, 'oldest_first');
});
testWidgets('the usage page is honest when nothing was reported', (
tester,
) async {
await mount(
tester,
createdAt: DateTime(2020, 1, 1).toIso8601String(),
);
await tester.tap(find.byKey(const ValueKey('runs.stats')));
await tester.pumpAndSettle();
// The bar says Usage; the body does not repeat it.
expect(find.text('Usage'), findsOneWidget);
expect(find.byKey(const ValueKey('runs.stats.usage.empty')), findsOne);
expect(find.byKey(const ValueKey('runs.stats.days')), findsNothing);
expect(find.byKey(const ValueKey('runs.stats.days.empty')), findsOne);
expect(find.text('Running'), findsOneWidget);
expect(find.text('0'), findsNothing);
});
testWidgets('the 7-day chart shows bars over an axis when runs started', (
tester,
) async {
await mount(tester);
await tester.tap(find.byKey(const ValueKey('runs.stats')));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('runs.stats.days')), findsOneWidget);
expect(find.byKey(const ValueKey('runs.stats.days.empty')), findsNothing);
// Only the day with a run is labelled with its count.
final days = find.byKey(const ValueKey('runs.stats.days'));
expect(find.descendant(of: days, matching: find.text('1')), findsOne);
expect(find.text('0'), findsNothing);
expect(tester.takeException(), isNull);
});
}