Sheets, decision options, usage, settings and artifact errors: review r2 batches H and L

Shared AppSheetHeader (title + Done) for the Runs filter/sort and Needs you
sheets; Runs filter single-choice groups as check rows and statuses in
sentence case; Cupertino decision options as a check list; run action sheet
titled with the run; usage page without the duplicate title and with honest
empty states; Settings Reconnect wording, compact notifications row and a
tinted Cupertino Save workspace; friendly artifact preview failures with
Retry.
This commit is contained in:
2026-10-31 12:13:34 +00:00
parent d49ab0667b
commit e43cc867f9
29 changed files with 1198 additions and 432 deletions
@@ -0,0 +1,27 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/artifacts/domain/artifact_preview_failure.dart';
void main() {
test('fetch failures read as plain language, never raw errors', () {
expect(
artifactPreviewFailureMessage(),
'The preview could not be loaded. Check the connection and try again.',
);
expect(
artifactPreviewFailureMessage(status: 404),
'This file is no longer on the server.',
);
expect(
artifactPreviewFailureMessage(status: 403),
'The server did not allow this file to be opened.',
);
expect(
artifactPreviewFailureMessage(status: 502),
'The server could not send this file right now.',
);
expect(
artifactPreviewFailureMessage(status: 418),
'The preview could not be loaded (status 418).',
);
});
}
@@ -12,6 +12,8 @@ import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_external_open.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_gallery_page.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_content.dart'
show artifactPreviewRetryKey;
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_fetch.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart';
@@ -464,8 +466,39 @@ void main() {
pending.complete(ArtifactFetchResult(status: 404, bytes: Uint8List(0)));
await tester.pumpAndSettle();
expect(find.text('The server answered 404.'), findsOneWidget);
expect(find.text('This file is no longer on the server.'), findsOneWidget);
expect(find.textContaining('answered'), findsNothing);
expect(find.byType(SelectableText), findsNothing);
expect(find.byKey(artifactPreviewRetryKey), findsOneWidget);
});
testWidgets('Retry fetches a failed preview again', (tester) async {
final text = recordedArtifact(
'notes.txt',
url: '/artifacts/1/1/notes.txt',
contentType: 'text/plain',
);
final group = _group([text]);
var calls = 0;
await _pumpViewer(
tester,
groups: [group],
selected: artifactVisitIdentity(group, text),
fetch: (_) async {
calls++;
if (calls == 1) throw const ArtifactFetchException('network down');
return ArtifactFetchResult(
status: 200,
bytes: Uint8List.fromList('hello'.codeUnits),
);
},
);
expect(find.byKey(artifactPreviewRetryKey), findsOneWidget);
await tester.tap(find.byKey(artifactPreviewRetryKey));
await tester.pumpAndSettle();
expect(calls, 2);
expect(find.byKey(artifactPreviewRetryKey), findsNothing);
expect(find.text('hello'), findsOneWidget);
});
testWidgets('a network failure is reported instead of an empty preview', (
@@ -483,8 +516,15 @@ void main() {
selected: artifactVisitIdentity(group, text),
fetch: (_) async => throw const ArtifactFetchException('network down'),
);
expect(find.textContaining('Could not load preview'), findsOneWidget);
expect(find.textContaining('network down'), findsOneWidget);
// A friendly line with Retry, never the raw exception text.
expect(
find.text(
'The preview could not be loaded. Check the connection and try again.',
),
findsOneWidget,
);
expect(find.textContaining('network down'), findsNothing);
expect(find.byKey(artifactPreviewRetryKey), findsOneWidget);
});
testWidgets('Cupertino draws the same text preview and controls', (
@@ -7,6 +7,7 @@ import 'package:pipelines_app/features/attention/notify/notification_controller.
import 'package:pipelines_app/features/attention/notify/notification_models.dart';
import 'package:pipelines_app/features/attention/notify/notification_store.dart';
import 'package:pipelines_app/features/attention/ui/needs_you_runs_heading.dart';
import 'package:pipelines_app/features/attention/ui/notification_permission_tile.dart';
import 'package:pipelines_app/features/settings/settings_notifications_section.dart';
import 'notification_test_support.dart';
@@ -70,13 +71,13 @@ void main() {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SettingsNotificationsSection(controller: notify),
),
home: Scaffold(body: SettingsNotificationsSection(controller: notify)),
),
);
await tester.pump();
expect(find.text(notificationRationale), findsOneWidget);
// One compact row: the short state, not the long rationale paragraph.
expect(find.byKey(notificationStateKey), findsOneWidget);
expect(find.text(notificationRationale), findsNothing);
// A denied platform answer shows its own words and no Enable action.
final denied = NotificationController(
@@ -86,12 +87,11 @@ void main() {
addTearDown(denied.dispose);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SettingsNotificationsSection(controller: denied),
),
home: Scaffold(body: SettingsNotificationsSection(controller: denied)),
),
);
await tester.pump();
expect(find.text(notificationRationale), findsOneWidget);
expect(find.byKey(notificationStateKey), findsOneWidget);
expect(find.text(notificationRationale), findsNothing);
});
}
@@ -33,7 +33,7 @@ void main() {
for (final native in [false, true]) {
final host = native ? 'Cupertino' : 'Material';
testWidgets('$host shows the state\'s own honest copy', (tester) async {
testWidgets('$host shows a compact row for each state', (tester) async {
final cases = <NotificationPermissionState, String>{
NotificationPermissionState.unsupported: notificationUnsupportedCopy,
NotificationPermissionState.needsSecureContext:
@@ -46,10 +46,15 @@ void main() {
await tester.pumpWidget(
_page(state: entry.key, cupertino: native, onRequest: _noop),
);
// The Settings section owns the heading; the tile is its body.
final view = notificationPermissionView(entry.key);
// The Settings section owns the heading; the tile is one short row.
expect(find.text(notificationSectionTitle), findsNothing);
expect(find.text(notificationRationale), findsOneWidget);
expect(find.text(entry.value), findsOneWidget, reason: '${entry.key}');
expect(find.text(notificationRationale), findsNothing);
expect(find.text(view.headline), findsOneWidget);
expect(find.text(view.helper), findsOneWidget);
// The full honest sentence is what assistive technology reads.
expect(view.body, entry.value);
expect(find.bySemanticsLabel(entry.value), findsOneWidget);
expect(
find.byKey(notificationEnableKey),
entry.key == NotificationPermissionState.notRequested
@@ -70,8 +75,9 @@ void main() {
cupertino: native,
),
);
expect(find.text(notificationDefaultAskedCopy), findsOneWidget);
expect(find.text(notificationDefaultCopy), findsNothing);
expect(find.text('Alerts are still off'), findsOneWidget);
expect(find.bySemanticsLabel(notificationDefaultAskedCopy), findsOne);
expect(find.bySemanticsLabel(notificationDefaultCopy), findsNothing);
});
testWidgets('$host Enable runs the explicit request', (tester) async {
@@ -115,16 +121,19 @@ void main() {
);
expect(tester.takeException(), isNull);
final rationale = tester.renderObject<RenderParagraph>(
find.text(notificationRationale),
final view = notificationPermissionView(
NotificationPermissionState.notRequested,
);
final helper = tester.renderObject<RenderParagraph>(
find.text(view.helper),
);
expect(
rationale.size.width,
helper.size.width,
greaterThan(100),
reason: 'the action must not squeeze the section copy',
reason: 'the action must not squeeze the row copy',
);
final body = tester.renderObject<RenderParagraph>(
find.text(notificationDefaultCopy),
find.text(view.headline),
);
expect(body.didExceedMaxLines, isFalse);
expect(find.byKey(notificationEnableKey), findsOneWidget);
@@ -3,6 +3,7 @@ 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/actions/decision_action.dart';
import 'package:pipelines_app/features/runs/actions/decision_option_row.dart';
import 'package:pipelines_app/features/runs/actions/decision_wording.dart';
typedef _Handler = Future<JsonMap> Function(String type, JsonMap fields);
@@ -194,9 +195,33 @@ void main() {
decisionConfirmLabel,
);
expect(tester.widget<CupertinoDialogAction>(confirm).onPressed, isNull);
// Options are check-list rows, not blue link buttons: an empty circle
// until one is picked, then a filled check on that row only.
final skip = find.byKey(decisionOptionKey('skip'));
expect(skip, findsOneWidget);
expect(
find.ancestor(
of: find.text('skip'),
matching: find.byType(CupertinoButton),
),
findsNothing,
);
expect(find.byIcon(CupertinoIcons.checkmark_circle_fill), findsNothing);
expect(
find.descendant(of: skip, matching: find.byIcon(CupertinoIcons.circle)),
findsOneWidget,
);
await tester.tap(find.text('skip'));
await tester.pump();
expect(gateway.calls, isEmpty);
expect(
find.descendant(
of: skip,
matching: find.byIcon(CupertinoIcons.checkmark_circle_fill),
),
findsOneWidget,
);
expect(find.byIcon(CupertinoIcons.checkmark_circle_fill), findsOneWidget);
await tester.tap(find.text(decisionConfirmLabel));
await tester.pumpAndSettle();
@@ -81,10 +81,13 @@ void main() {
),
);
expect(
find.text('Pipeline unavailable · 2m 5s · 3 steps'),
findsOneWidget,
);
expect(find.text('Pipeline unavailable · 2m 5s · 3 steps'), findsOneWidget);
});
test('the run action sheet is titled with the run', () {
expect(runMoreMenuTitle(_finished), 'Ship the release notes');
expect(runMoreMenuTitle({'id': 5, 'name': 'nightly'}), 'nightly');
expect(runMoreMenuTitle({'id': 5}), 'Run 5');
});
testWidgets('gives a list action menu a per-run key', (tester) async {
@@ -0,0 +1,188 @@
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_filter_sheet.dart';
import 'package:pipelines_app/features/runs/ui/runs_filters.dart';
import 'package:pipelines_app/features/runs/ui/runs_list.dart';
import 'package:pipelines_app/features/runs/ui/runs_stats_page.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, {
required bool cupertino,
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(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: list))
: MaterialApp(home: Scaffold(body: list)),
);
await tester.pumpAndSettle();
}
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('$host filter sheet has a header whose Done closes it', (
tester,
) async {
await mount(tester, cupertino: cupertino);
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, cupertino: false);
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 sheet has the same header', (tester) async {
await mount(tester, cupertino: false);
await tester.tap(find.byKey(const ValueKey('runs.sort')));
await tester.pumpAndSettle();
expect(find.text(runsSortTitle), findsOneWidget);
await tester.tap(find.byKey(runsSortDoneKey));
await tester.pumpAndSettle();
expect(find.text(runsSortTitle), findsNothing);
expect(controller.sort, 'newest_first');
});
testWidgets('the usage page is honest when nothing was reported', (
tester,
) async {
await mount(
tester,
cupertino: false,
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, cupertino: true);
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);
});
}
@@ -70,18 +70,22 @@ void main() {
await tester.pumpAndSettle();
}
Future<void> reveal(WidgetTester tester, Finder target) =>
tester.scrollUntilVisible(
target,
80,
// The sheet's own list, not the search field's inner scrollable.
scrollable: find
.descendant(
of: find.byKey(const ValueKey('runs.filter.sheet')),
matching: find.byType(Scrollable),
)
.first,
);
Future<void> reveal(WidgetTester tester, Finder target) async {
await tester.scrollUntilVisible(
target,
80,
// The sheet's own list, not the search field's inner scrollable.
scrollable: find
.descendant(
of: find.byKey(const ValueKey('runs.filter.sheet')),
matching: find.byType(Scrollable),
)
.first,
);
// Built is not on screen: bring the row fully inside the sheet.
await tester.ensureVisible(target);
await tester.pumpAndSettle();
}
Future<void> closeSheet(WidgetTester tester) async {
await tester.tapAt(const Offset(4, 4));
@@ -148,7 +152,7 @@ void main() {
await tester.tap(find.byKey(const ValueKey('runs.filter')));
await tester.pumpAndSettle();
expect(find.byType(CupertinoSearchTextField), findsOneWidget);
final failed = find.widgetWithText(CupertinoListTile, 'failed');
final failed = find.widgetWithText(CupertinoListTile, 'Failed');
await reveal(tester, failed);
await tester.pumpAndSettle();
await tester.tap(failed);
@@ -156,7 +160,7 @@ void main() {
expect(controller.statuses, {'failed'});
await closeSheet(tester);
final failedChip = find.widgetWithText(CupertinoButton, 'failed');
final failedChip = find.widgetWithText(CupertinoButton, 'Failed');
expect(failedChip, findsOneWidget);
expect(find.text('Alpha'), findsNothing);
await tester.tap(failedChip);
@@ -154,6 +154,15 @@ void main() {
expect(find.text('Server time 2026-10-21T12:00:00Z'), findsOneWidget);
expect(find.byKey(SettingsKeys.disconnect), findsOneWidget);
expect(find.byKey(SettingsKeys.connect), findsOneWidget);
// Beside Disconnect, the second action reconnects; it never says Connect.
expect(
find.descendant(
of: find.byKey(SettingsKeys.connect),
matching: find.text('Reconnect'),
),
findsOneWidget,
);
expect(find.text('Connect'), findsNothing);
// The only other request is the ntfy settings load, queued behind ping.
_answerNtfySettings(factory.last);
await tester.pump();