Merge branch 'main' into pipelines/run-20261111-0115-cupertino-out-ui-motion-navigation-input-6491

# Conflicts:
#	app/test/features/runs/ui/runs_list_widget_test.dart
This commit is contained in:
2026-11-11 02:43:51 +00:00
74 changed files with 1997 additions and 2915 deletions
@@ -6,10 +6,10 @@ import 'package:pipelines_app/features/attention/ui/needs_you_keys.dart';
import 'attention_runs_test_support.dart';
/// The hardest real-app case: a narrow phone at a doubled text scale. Both the
/// Runs list chrome and the native sheet must keep the bell and every action
/// inside the viewport.
/// Runs list chrome and the sheet must keep the bell and every action inside the
/// viewport.
void main() {
testWidgets('both hosts fit the bell and sheet at 320 logical px and 2x', (
testWidgets('Material fits the bell and sheet at 320 logical px and 2x', (
tester,
) async {
tester.view.devicePixelRatio = 2;
@@ -19,54 +19,49 @@ void main() {
final gateway = AttentionRunsGateway();
addTearDown(gateway.framesController.close);
for (final native in [false, true]) {
await mountAttentionRuns(
tester,
gateway,
cupertino: native,
store: MemoryAttentionStore(),
runs: [
attentionRun(
1,
'waiting',
title: 'Approve a release candidate at 320 px',
),
attentionRun(
2,
'failed',
title: 'A failed run with a label long enough to wrap',
diagnostic: 'Stage 3 stopped because the credential is missing.',
),
],
request: native ? 1 : 0,
textScale: 2,
key: ValueKey(native),
);
expect(find.byKey(attentionBellKey), findsOneWidget);
final listError = tester.takeException();
expect(
listError,
isNull,
reason: listError is FlutterError
? '${native ? 'Cupertino' : 'Material'} list: ${listError.toStringDeep()}'
: '${native ? 'Cupertino' : 'Material'} list: $listError',
);
await openAttentionSheet(tester);
final sheetError = tester.takeException();
expect(
sheetError,
isNull,
reason: sheetError is FlutterError
? '${native ? 'Cupertino' : 'Material'} sheet: ${sheetError.toStringDeep()}'
: '${native ? 'Cupertino' : 'Material'} sheet: $sheetError',
);
final sheet = tester.getRect(find.byKey(attentionSheetKey));
expect(sheet.left, greaterThanOrEqualTo(0));
expect(sheet.right, lessThanOrEqualTo(320));
expect(sheet.top, greaterThanOrEqualTo(0));
expect(sheet.bottom, lessThanOrEqualTo(640));
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
}
await mountAttentionRuns(
tester,
gateway,
store: MemoryAttentionStore(),
runs: [
attentionRun(
1,
'waiting',
title: 'Approve a release candidate at 320 px',
),
attentionRun(
2,
'failed',
title: 'A failed run with a label long enough to wrap',
diagnostic: 'Stage 3 stopped because the credential is missing.',
),
],
textScale: 2,
);
expect(find.byKey(attentionBellKey), findsOneWidget);
final listError = tester.takeException();
expect(
listError,
isNull,
reason: listError is FlutterError
? 'Material list: ${listError.toStringDeep()}'
: 'Material list: $listError',
);
await openAttentionSheet(tester);
final sheetError = tester.takeException();
expect(
sheetError,
isNull,
reason: sheetError is FlutterError
? 'Material sheet: ${sheetError.toStringDeep()}'
: 'Material sheet: $sheetError',
);
final sheet = tester.getRect(find.byKey(attentionSheetKey));
expect(sheet.left, greaterThanOrEqualTo(0));
expect(sheet.right, lessThanOrEqualTo(320));
expect(sheet.top, greaterThanOrEqualTo(0));
expect(sheet.bottom, lessThanOrEqualTo(640));
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
});
}
@@ -1,6 +1,5 @@
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';
@@ -63,7 +62,6 @@ class AttentionRunsGateway implements ApiGateway {
Widget attentionRunsApp(
AttentionRunsGateway gateway, {
required bool cupertino,
required AttentionStore store,
double textScale = 1,
Key? key,
@@ -80,13 +78,6 @@ Widget attentionRunsApp(
attentionStore: store,
attentionNow: () => attentionTestNow,
);
if (cupertino) {
return CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
builder: scaled,
home: CupertinoPageScaffold(child: screen),
);
}
return MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
builder: scaled,
@@ -97,7 +88,6 @@ Widget attentionRunsApp(
Future<void> mountAttentionRuns(
WidgetTester tester,
AttentionRunsGateway gateway, {
required bool cupertino,
required AttentionStore store,
required List<JsonMap> runs,
int request = 0,
@@ -107,7 +97,6 @@ Future<void> mountAttentionRuns(
await tester.pumpWidget(
attentionRunsApp(
gateway,
cupertino: cupertino,
store: store,
textScale: textScale,
key: key,
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/attention/domain/attention_models.dart';
@@ -14,183 +13,173 @@ void main() {
setUp(() => gateway = AttentionRunsGateway());
tearDown(() => gateway.framesController.close());
for (final native in [false, true]) {
final host = native ? 'Cupertino' : 'Material';
testWidgets(
'$host Runs list bell opens the native sheet and dismisses one',
(tester) async {
final semantics = tester.ensureSemantics();
final store = MemoryAttentionStore();
await mountAttentionRuns(
tester,
gateway,
cupertino: native,
store: store,
runs: [
attentionRun(1, 'waiting', title: 'Approve the release'),
attentionRun(
2,
'failed',
title: 'Ship the release',
diagnostic: 'Stage 2',
),
attentionRun(3, 'waiting', title: 'Machine export')
..['export_pending_sequence'] = 2,
attentionRun(4, 'running', title: 'Still running'),
],
);
expect(
find.bySemanticsLabel('Notifications, 2 needing attention'),
findsOneWidget,
);
await openAttentionSheet(tester);
expect(find.byKey(attentionSheetKey), findsOneWidget);
expect(find.byKey(attentionRowKey('3:Decision')), findsNothing);
expect(find.byKey(attentionRowKey('4:Failed')), findsNothing);
expect(find.byKey(attentionRowKey('2:Failed')), findsOneWidget);
await tester.tap(find.byKey(attentionDismissKey('2:Failed')));
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsOneWidget);
expect(find.byKey(attentionRowKey('2:Failed')), findsNothing);
expect(store.stored, encodeAttentionDismissals({'2:Failed'}));
// Closing and rebuilding from the same store keeps the dismissal.
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.pumpWidget(const SizedBox());
await mountAttentionRuns(
tester,
gateway,
cupertino: native,
store: store,
runs: [
attentionRun(1, 'waiting', title: 'Approve the release'),
attentionRun(
2,
'failed',
title: 'Ship the release',
diagnostic: 'Stage 2',
),
],
request: 1,
key: const ValueKey('rebuilt'),
);
expect(
find.bySemanticsLabel('Notifications, 1 needing attention'),
findsOneWidget,
);
semantics.dispose();
},
testWidgets('Material Runs list bell opens the sheet and dismisses one', (
tester,
) async {
final semantics = tester.ensureSemantics();
final store = MemoryAttentionStore();
await mountAttentionRuns(
tester,
gateway,
store: store,
runs: [
attentionRun(1, 'waiting', title: 'Approve the release'),
attentionRun(
2,
'failed',
title: 'Ship the release',
diagnostic: 'Stage 2',
),
attentionRun(3, 'waiting', title: 'Machine export')
..['export_pending_sequence'] = 2,
attentionRun(4, 'running', title: 'Still running'),
],
);
testWidgets('$host rows follow the browser open/dismiss rules', (
expect(
find.bySemanticsLabel('Notifications, 2 needing attention'),
findsOneWidget,
);
await openAttentionSheet(tester);
expect(find.byKey(attentionSheetKey), findsOneWidget);
expect(find.byKey(attentionRowKey('3:Decision')), findsNothing);
expect(find.byKey(attentionRowKey('4:Failed')), findsNothing);
expect(find.byKey(attentionRowKey('2:Failed')), findsOneWidget);
await tester.tap(find.byKey(attentionDismissKey('2:Failed')));
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsOneWidget);
expect(find.byKey(attentionRowKey('2:Failed')), findsNothing);
expect(store.stored, encodeAttentionDismissals({'2:Failed'}));
// Closing and rebuilding from the same store keeps the dismissal.
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.pumpWidget(const SizedBox());
await mountAttentionRuns(
tester,
) async {
final store = MemoryAttentionStore();
await mountAttentionRuns(
tester,
gateway,
cupertino: native,
store: store,
runs: [
attentionRun(1, 'waiting', title: 'Approve the release'),
attentionRun(2, 'failed', title: 'Ship the release'),
],
);
gateway,
store: store,
runs: [
attentionRun(1, 'waiting', title: 'Approve the release'),
attentionRun(
2,
'failed',
title: 'Ship the release',
diagnostic: 'Stage 2',
),
],
request: 1,
key: const ValueKey('rebuilt'),
);
expect(
find.bySemanticsLabel('Notifications, 1 needing attention'),
findsOneWidget,
);
semantics.dispose();
});
await openAttentionSheet(tester);
await tester.tap(find.byKey(attentionRowKey('1:Decision')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(gateway.detailRequests[1], hasLength(1));
expect(
store.stored,
isNull,
reason: 'a Decision opens without dismissing',
);
gateway.replyDetail(1, {'id': 1, 'title': 'Approve the release'});
await tester.pump();
await tester.pumpAndSettle();
// The wide list and its bell stay available beside the open detail.
expect(find.byKey(const ValueKey('run-row-2')), findsOneWidget);
await openAttentionSheet(tester);
await tester.tap(find.byKey(attentionRowKey('2:Failed')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(gateway.detailRequests[2], hasLength(1));
expect(store.stored, encodeAttentionDismissals({'2:Failed'}));
gateway.replyDetail(2, {'id': 2, 'title': 'Ship the release'});
await tester.pump();
});
testWidgets('$host live frame and Clear-all snapshot reach the bell', (
testWidgets('Material rows follow the browser open/dismiss rules', (
tester,
) async {
final store = MemoryAttentionStore();
await mountAttentionRuns(
tester,
) async {
final semantics = tester.ensureSemantics();
final store = MemoryAttentionStore();
await mountAttentionRuns(
tester,
gateway,
cupertino: native,
store: store,
runs: [attentionRun(1, 'failed', title: 'First failure')],
);
expect(
find.bySemanticsLabel('Notifications, 1 needing attention'),
findsOneWidget,
);
gateway,
store: store,
runs: [
attentionRun(1, 'waiting', title: 'Approve the release'),
attentionRun(2, 'failed', title: 'Ship the release'),
],
);
await openAttentionSheet(tester);
gateway.framesController.add({
'type': 'run_event',
'run_id': 9,
'pipeline_id': 4,
'name': 'nightly',
'title': 'Arrived while open',
'status': 'waiting',
'created_at': attentionTestNow
.subtract(const Duration(minutes: 5))
.toIso8601String(),
});
await tester.pump();
await tester.pumpAndSettle();
expect(find.byKey(attentionRowKey('9:Decision')), findsOneWidget);
await openAttentionSheet(tester);
await tester.tap(find.byKey(attentionRowKey('1:Decision')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(gateway.detailRequests[1], hasLength(1));
expect(
store.stored,
isNull,
reason: 'a Decision opens without dismissing',
);
gateway.replyDetail(1, {'id': 1, 'title': 'Approve the release'});
await tester.pump();
await tester.pumpAndSettle();
await tester.tap(find.byKey(attentionClearAllKey));
await tester.pumpAndSettle();
expect(find.byKey(attentionRowKey('1:Failed')), findsNothing);
expect(
find.byKey(attentionRowKey('9:Decision')),
findsOneWidget,
reason: 'Clear all acts on the snapshot it opened with',
);
expect(store.stored, encodeAttentionDismissals({'1:Failed'}));
semantics.dispose();
});
// The wide list and its bell stay available beside the open detail.
expect(find.byKey(const ValueKey('run-row-2')), findsOneWidget);
await openAttentionSheet(tester);
await tester.tap(find.byKey(attentionRowKey('2:Failed')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(gateway.detailRequests[2], hasLength(1));
expect(store.stored, encodeAttentionDismissals({'2:Failed'}));
gateway.replyDetail(2, {'id': 2, 'title': 'Ship the release'});
await tester.pump();
});
testWidgets('$host empty runs hide the badge but keep the bell', (
testWidgets('Material live frame and Clear-all snapshot reach the bell', (
tester,
) async {
final semantics = tester.ensureSemantics();
final store = MemoryAttentionStore();
await mountAttentionRuns(
tester,
) async {
final semantics = tester.ensureSemantics();
await mountAttentionRuns(
tester,
gateway,
cupertino: native,
store: MemoryAttentionStore(),
runs: const [],
);
gateway,
store: store,
runs: [attentionRun(1, 'failed', title: 'First failure')],
);
expect(
find.bySemanticsLabel('Notifications, 1 needing attention'),
findsOneWidget,
);
expect(find.byKey(attentionBellKey), findsOneWidget);
expect(find.byKey(attentionBadgeKey), findsNothing);
expect(find.bySemanticsLabel('Notifications'), findsOneWidget);
await openAttentionSheet(tester);
expect(find.text('Nothing needs you right now.'), findsOneWidget);
expect(find.byKey(attentionClearAllKey), findsNothing);
semantics.dispose();
await openAttentionSheet(tester);
gateway.framesController.add({
'type': 'run_event',
'run_id': 9,
'pipeline_id': 4,
'name': 'nightly',
'title': 'Arrived while open',
'status': 'waiting',
'created_at': attentionTestNow
.subtract(const Duration(minutes: 5))
.toIso8601String(),
});
}
await tester.pump();
await tester.pumpAndSettle();
expect(find.byKey(attentionRowKey('9:Decision')), findsOneWidget);
await tester.tap(find.byKey(attentionClearAllKey));
await tester.pumpAndSettle();
expect(find.byKey(attentionRowKey('1:Failed')), findsNothing);
expect(
find.byKey(attentionRowKey('9:Decision')),
findsOneWidget,
reason: 'Clear all acts on the snapshot it opened with',
);
expect(store.stored, encodeAttentionDismissals({'1:Failed'}));
semantics.dispose();
});
testWidgets('Material empty runs hide the badge but keep the bell', (
tester,
) async {
final semantics = tester.ensureSemantics();
await mountAttentionRuns(
tester,
gateway,
store: MemoryAttentionStore(),
runs: const [],
);
expect(find.byKey(attentionBellKey), findsOneWidget);
expect(find.byKey(attentionBadgeKey), findsNothing);
expect(find.bySemanticsLabel('Notifications'), findsOneWidget);
await openAttentionSheet(tester);
expect(find.text('Nothing needs you right now.'), findsOneWidget);
expect(find.byKey(attentionClearAllKey), findsNothing);
semantics.dispose();
});
}
@@ -1,126 +1,137 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/attention/ui/needs_you_bell.dart';
import 'package:pipelines_app/features/attention/ui/needs_you_keys.dart';
import 'needs_you_test_support.dart';
void main() {
for (final native in [false, true]) {
final host = native ? 'Cupertino' : 'Material';
testWidgets('Material bell is plain and announced when nothing needs you', (
tester,
) async {
final semantics = tester.ensureSemantics();
await tester.pumpWidget(attentionApp(NeedsYouPage(entries: const [])));
testWidgets('$host bell is plain and announced when nothing needs you', (
tester,
) async {
final semantics = tester.ensureSemantics();
await tester.pumpWidget(
attentionApp(NeedsYouPage(entries: const [], cupertino: native)),
);
expect(find.bySemanticsLabel('Notifications'), findsOneWidget);
expect(find.byKey(attentionBadgeKey), findsNothing);
expect(find.text('0'), findsNothing);
semantics.dispose();
});
expect(find.bySemanticsLabel('Notifications'), findsOneWidget);
expect(find.byKey(attentionBadgeKey), findsNothing);
expect(find.text('0'), findsNothing);
semantics.dispose();
});
testWidgets('Material bell announces the count and shows one badge', (
tester,
) async {
final semantics = tester.ensureSemantics();
final entries = [
attentionFixture(id: 1),
attentionFixture(id: 2, status: 'waiting', title: 'Approve release'),
attentionFixture(id: 3, diagnostic: 'Stage 2 failed'),
];
await tester.pumpWidget(attentionApp(NeedsYouPage(entries: entries)));
testWidgets('$host bell announces the count and shows one badge', (
tester,
) async {
final semantics = tester.ensureSemantics();
final entries = [
attentionFixture(id: 1),
attentionFixture(id: 2, status: 'waiting', title: 'Approve release'),
attentionFixture(id: 3, diagnostic: 'Stage 2 failed'),
];
await tester.pumpWidget(
attentionApp(
NeedsYouPage(entries: entries, cupertino: native),
cupertino: native,
expect(
find.bySemanticsLabel('Notifications, 3 needing attention'),
findsOneWidget,
);
expect(find.byKey(attentionBadgeKey), findsOneWidget);
expect(find.text('3'), findsOneWidget);
semantics.dispose();
});
testWidgets('Material bell opens the honest empty sheet and back closes it', (
tester,
) async {
await tester.pumpWidget(attentionApp(NeedsYouPage(entries: const [])));
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsOneWidget);
expect(find.text('Needs you'), findsOneWidget);
expect(find.text('Nothing needs you right now.'), findsOneWidget);
expect(find.byKey(attentionEmptyKey), findsOneWidget);
expect(find.byKey(attentionClearAllKey), findsNothing);
expect(find.text('Dismiss'), findsNothing);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsNothing);
});
testWidgets('Material sheet is a named heading and Escape closes it', (
tester,
) async {
final semantics = tester.ensureSemantics();
await tester.pumpWidget(attentionApp(NeedsYouPage(entries: const [])));
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
final title = tester.getSemantics(find.text('Needs you'));
expect(
title.getSemanticsData().flagsCollection.isHeader,
isTrue,
reason: 'the sheet title must reach assistive tech as a heading',
);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsNothing);
semantics.dispose();
});
testWidgets('Material sheet closes on a barrier tap', (tester) async {
await tester.pumpWidget(attentionApp(NeedsYouPage(entries: const [])));
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsOneWidget);
// Above the sheet body: only the native modal barrier is there.
await tester.tapAt(const Offset(20, 20));
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsNothing);
});
testWidgets('Material closing the sheet returns focus to the bell', (
tester,
) async {
await tester.pumpWidget(attentionApp(NeedsYouPage(entries: const [])));
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsNothing);
expect(bellHasFocus(tester), isTrue);
});
testWidgets('a stale cupertino flag still draws the Material bell and sheet', (
tester,
) async {
await tester.pumpWidget(
attentionApp(
Scaffold(
body: Center(
child: NeedsYouBell(
entries: [attentionFixture()],
cupertino: true,
onOpen: (_) {},
onDismiss: (_) {},
onClearAll: (_) {},
),
),
),
);
),
);
expect(
find.bySemanticsLabel('Notifications, 3 needing attention'),
findsOneWidget,
);
expect(find.byKey(attentionBadgeKey), findsOneWidget);
expect(find.text('3'), findsOneWidget);
semantics.dispose();
});
expect(tester.widget(find.byKey(attentionBellKey)), isA<IconButton>());
expect(find.byIcon(Icons.notifications_outlined), findsOneWidget);
testWidgets('$host bell opens the honest empty sheet and back closes it', (
tester,
) async {
await tester.pumpWidget(
attentionApp(NeedsYouPage(entries: const [], cupertino: native)),
);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsOneWidget);
expect(find.text('Needs you'), findsOneWidget);
expect(find.text('Nothing needs you right now.'), findsOneWidget);
expect(find.byKey(attentionEmptyKey), findsOneWidget);
expect(find.byKey(attentionClearAllKey), findsNothing);
expect(find.text('Dismiss'), findsNothing);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsNothing);
});
testWidgets('$host sheet is a named heading and Escape closes it', (
tester,
) async {
final semantics = tester.ensureSemantics();
await tester.pumpWidget(
attentionApp(NeedsYouPage(entries: const [], cupertino: native)),
);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
final title = tester.getSemantics(find.text('Needs you'));
expect(
title.getSemanticsData().flagsCollection.isHeader,
isTrue,
reason: 'the sheet title must reach assistive tech as a heading',
);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsNothing);
semantics.dispose();
});
testWidgets('$host sheet closes on a barrier tap', (tester) async {
await tester.pumpWidget(
attentionApp(NeedsYouPage(entries: const [], cupertino: native)),
);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsOneWidget);
// Above the sheet body: only the native modal barrier is there.
await tester.tapAt(const Offset(20, 20));
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsNothing);
});
testWidgets('$host closing the sheet returns focus to the bell', (
tester,
) async {
await tester.pumpWidget(
attentionApp(NeedsYouPage(entries: const [], cupertino: native)),
);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsNothing);
expect(bellHasFocus(tester), isTrue);
});
}
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
expect(find.byType(BottomSheet), findsOneWidget);
expect(find.byKey(attentionSheetKey), findsOneWidget);
});
}
@@ -6,65 +6,60 @@ import 'needs_you_test_support.dart';
/// Layout evidence for the hardest case: a narrow phone at a doubled text scale.
void main() {
for (final native in [false, true]) {
final host = native ? 'Cupertino' : 'Material';
testWidgets('Material sheet wraps at 320 logical px and 2x in dark', (
tester,
) async {
tester.view.devicePixelRatio = 2;
tester.view.physicalSize = const Size(640, 1280);
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
const longTitle =
'Implementer-with-an-unshortened-stage-label that the operator sees';
const longDetail =
'Stage 3 stopped at the export archive step because the credential '
'it needs is no longer configured on this server.';
final entry = attentionFixture(
id: 1,
name: 'Release',
title: longTitle,
diagnostic: longDetail,
);
await tester.pumpWidget(
attentionApp(
NeedsYouPage(entries: [entry]),
dark: true,
textScale: 2,
),
);
testWidgets('$host sheet wraps at 320 logical px and 2x in dark', (
tester,
) async {
tester.view.devicePixelRatio = 2;
tester.view.physicalSize = const Size(640, 1280);
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
const longTitle =
'Implementer-with-an-unshortened-stage-label that the operator sees';
const longDetail =
'Stage 3 stopped at the export archive step because the credential '
'it needs is no longer configured on this server.';
final entry = attentionFixture(
id: 1,
name: 'Release',
title: longTitle,
diagnostic: longDetail,
);
await tester.pumpWidget(
attentionApp(
NeedsYouPage(entries: [entry], cupertino: native),
cupertino: native,
dark: true,
textScale: 2,
),
);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
final label = find.text(longTitle);
final description = find.text('Release · $longDetail');
expect(label, findsOneWidget);
expect(description, findsOneWidget);
await tester.ensureVisible(label);
final paragraph = tester.renderObject<RenderParagraph>(label);
expect(paragraph.didExceedMaxLines, isFalse);
final unscaled = TextPainter(
text: paragraph.text,
textDirection: paragraph.textDirection,
textScaler: TextScaler.noScaling,
)..layout();
expect(
unscaled.width,
greaterThan(paragraph.size.width),
reason: 'the long label wraps instead of shrinking to one line',
);
unscaled.dispose();
final label = find.text(longTitle);
final description = find.text('Release · $longDetail');
expect(label, findsOneWidget);
expect(description, findsOneWidget);
await tester.ensureVisible(label);
final paragraph = tester.renderObject<RenderParagraph>(label);
expect(paragraph.didExceedMaxLines, isFalse);
final unscaled = TextPainter(
text: paragraph.text,
textDirection: paragraph.textDirection,
textScaler: TextScaler.noScaling,
)..layout();
expect(
unscaled.width,
greaterThan(paragraph.size.width),
reason: 'the long label wraps instead of shrinking to one line',
);
unscaled.dispose();
final sheet = tester.getRect(find.byKey(attentionSheetKey));
expect(sheet.left, greaterThanOrEqualTo(0));
expect(sheet.right, lessThanOrEqualTo(320));
expect(sheet.top, greaterThanOrEqualTo(0));
expect(sheet.bottom, lessThanOrEqualTo(640));
expect(tester.takeException(), isNull);
});
}
final sheet = tester.getRect(find.byKey(attentionSheetKey));
expect(sheet.left, greaterThanOrEqualTo(0));
expect(sheet.right, lessThanOrEqualTo(320));
expect(sheet.top, greaterThanOrEqualTo(0));
expect(sheet.bottom, lessThanOrEqualTo(640));
expect(tester.takeException(), isNull);
});
}
@@ -9,109 +9,97 @@ import 'needs_you_test_support.dart';
/// arrive, disappear or change text must redraw, while Clear all stays limited
/// to the snapshot the route opened with.
void main() {
for (final native in [false, true]) {
final host = native ? 'Cupertino' : 'Material';
testWidgets(
'$host same-identity content change reaches the open and reopened sheet',
(tester) async {
final before = attentionFixture(id: 1, title: 'Old title');
final changed = attentionFixture(
id: 1,
title: 'New title',
diagnostic: 'Stage 3 failed',
);
final reopened = attentionFixture(id: 1, title: 'Newest title');
expect(changed.key, before.key);
final source = ValueNotifier<List<AttentionEntry>>([before]);
addTearDown(source.dispose);
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: <AttentionEntry>[],
dismissed: <AttentionEntry>[],
cleared: <List<AttentionEntry>>[],
cupertino: native,
),
cupertino: native,
),
);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
expect(find.text('Old title'), findsOneWidget);
// Same run and kind, new title and diagnostic: the open sheet must
// redraw from the caller's list, as the browser does.
source.value = [changed];
await tester.pumpAndSettle();
expect(find.text('New title'), findsOneWidget);
expect(find.text('Old title'), findsNothing);
expect(find.text('Release · Stage 3 failed'), findsOneWidget);
expect(
attentionDismissName(tester, changed),
'Dismiss New title',
reason: 'the row action is named from the row it now shows',
);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsNothing);
// A closed sheet must not keep the list it was last opened with either.
source.value = [reopened];
await tester.pumpAndSettle();
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
expect(find.text('Newest title'), findsOneWidget);
expect(find.text('New title'), findsNothing);
expect(attentionDismissName(tester, reopened), 'Dismiss Newest title');
},
testWidgets('Material same-identity content change reaches the open and '
'reopened sheet', (tester) async {
final before = attentionFixture(id: 1, title: 'Old title');
final changed = attentionFixture(
id: 1,
title: 'New title',
diagnostic: 'Stage 3 failed',
);
final reopened = attentionFixture(id: 1, title: 'Newest title');
expect(changed.key, before.key);
final source = ValueNotifier<List<AttentionEntry>>([before]);
addTearDown(source.dispose);
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: <AttentionEntry>[],
dismissed: <AttentionEntry>[],
cleared: <List<AttentionEntry>>[],
),
),
);
testWidgets(
'$host Clear all uses the open snapshot and leaves later arrivals',
(tester) async {
final a = attentionFixture(id: 1, title: 'Ship the release');
final b = attentionFixture(id: 2, title: 'Arrived while open');
final source = ValueNotifier<List<AttentionEntry>>([a]);
addTearDown(source.dispose);
final cleared = <List<AttentionEntry>>[];
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: <AttentionEntry>[],
dismissed: <AttentionEntry>[],
cleared: cleared,
cupertino: native,
),
cupertino: native,
),
);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
expect(find.text('Old title'), findsOneWidget);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
source.value = [a, b];
await tester.pumpAndSettle();
expect(
find.byKey(attentionRowKey(b.key)),
findsOneWidget,
reason: 'the open sheet shows the live list, as the browser does',
);
await tester.tap(find.byKey(attentionClearAllKey));
await tester.pumpAndSettle();
expect(cleared, hasLength(1));
expect(cleared.single.map((entry) => entry.key), [a.key]);
expect(source.value.map((entry) => entry.key), [b.key]);
// Clearing keeps the sheet open; only the snapshot it opened with is gone.
expect(find.byKey(attentionSheetKey), findsOneWidget);
expect(find.byKey(attentionRowKey(b.key)), findsOneWidget);
expect(find.byKey(attentionRowKey(a.key)), findsNothing);
},
// Same run and kind, new title and diagnostic: the open sheet must
// redraw from the caller's list, as the browser does.
source.value = [changed];
await tester.pumpAndSettle();
expect(find.text('New title'), findsOneWidget);
expect(find.text('Old title'), findsNothing);
expect(find.text('Release · Stage 3 failed'), findsOneWidget);
expect(
attentionDismissName(tester, changed),
'Dismiss New title',
reason: 'the row action is named from the row it now shows',
);
}
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsNothing);
// A closed sheet must not keep the list it was last opened with either.
source.value = [reopened];
await tester.pumpAndSettle();
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
expect(find.text('Newest title'), findsOneWidget);
expect(find.text('New title'), findsNothing);
expect(attentionDismissName(tester, reopened), 'Dismiss Newest title');
});
testWidgets('Material Clear all uses the open snapshot and leaves later '
'arrivals', (tester) async {
final a = attentionFixture(id: 1, title: 'Ship the release');
final b = attentionFixture(id: 2, title: 'Arrived while open');
final source = ValueNotifier<List<AttentionEntry>>([a]);
addTearDown(source.dispose);
final cleared = <List<AttentionEntry>>[];
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: <AttentionEntry>[],
dismissed: <AttentionEntry>[],
cleared: cleared,
),
),
);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
source.value = [a, b];
await tester.pumpAndSettle();
expect(
find.byKey(attentionRowKey(b.key)),
findsOneWidget,
reason: 'the open sheet shows the live list, as the browser does',
);
await tester.tap(find.byKey(attentionClearAllKey));
await tester.pumpAndSettle();
expect(cleared, hasLength(1));
expect(cleared.single.map((entry) => entry.key), [a.key]);
expect(source.value.map((entry) => entry.key), [b.key]);
// Clearing keeps the sheet open; only the snapshot it opened with is gone.
expect(find.byKey(attentionSheetKey), findsOneWidget);
expect(find.byKey(attentionRowKey(b.key)), findsOneWidget);
expect(find.byKey(attentionRowKey(a.key)), findsNothing);
});
}
@@ -7,166 +7,140 @@ import 'package:pipelines_app/ui/status/run_status_icon.dart';
import 'needs_you_test_support.dart';
void main() {
for (final native in [false, true]) {
final host = native ? 'Cupertino' : 'Material';
testWidgets('Material sheet names every row and every dismiss action', (
tester,
) async {
final a = attentionFixture(id: 1, title: 'Ship the release');
final b = attentionFixture(id: 2, name: 'Nightly audit', status: 'waiting');
await tester.pumpWidget(attentionApp(NeedsYouPage(entries: [a, b])));
testWidgets('$host sheet names every row and every dismiss action', (
tester,
) async {
final a = attentionFixture(id: 1, title: 'Ship the release');
final b = attentionFixture(
id: 2,
name: 'Nightly audit',
status: 'waiting',
);
await tester.pumpWidget(
attentionApp(
NeedsYouPage(entries: [a, b], cupertino: native),
cupertino: native,
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsOneWidget);
expect(find.text('Needs you'), findsOneWidget);
expect(find.byKey(attentionRowKey(a.key)), findsOneWidget);
expect(find.byKey(attentionRowKey(b.key)), findsOneWidget);
expect(find.text('Ship the release'), findsOneWidget);
expect(find.text('Release · Run failed'), findsOneWidget);
expect(find.text('Nightly audit'), findsOneWidget);
expect(find.text('Nightly audit · Waiting for your decision'), findsOneWidget);
expect(find.byKey(attentionClearAllKey), findsOneWidget);
// Each row leads with the shared run status glyph, as the web's rows.
expect(
tester
.widgetList<RunStatusIcon>(find.byType(RunStatusIcon))
.map((icon) => icon.state),
unorderedEquals(['failed', 'waiting']),
);
// The browser names each destructive control after the row it removes.
expect(attentionDismissName(tester, a), 'Dismiss Ship the release');
expect(attentionDismissName(tester, b), 'Dismiss Nightly audit');
expect(find.text('Dismiss'), findsNothing);
});
testWidgets('Material repeated labels add the run id to the dismiss name', (
tester,
) async {
final first = attentionFixture(id: 11, title: 'Nightly audit');
final second = attentionFixture(id: 12, title: 'Nightly audit');
await tester.pumpWidget(
attentionApp(NeedsYouPage(entries: [first, second])),
);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
expect(attentionDismissName(tester, first), 'Dismiss Nightly audit (run 11)');
expect(
attentionDismissName(tester, second),
'Dismiss Nightly audit (run 12)',
);
});
testWidgets('Material row Dismiss names its identity and stays open', (
tester,
) async {
final a = attentionFixture(id: 1, title: 'Ship the release');
final b = attentionFixture(id: 2, title: 'Fix the export');
final source = ValueNotifier<List<AttentionEntry>>([a, b]);
addTearDown(source.dispose);
final opened = <AttentionEntry>[];
final dismissed = <AttentionEntry>[];
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: opened,
dismissed: dismissed,
cleared: <List<AttentionEntry>>[],
),
);
),
);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
await tester.tap(find.byKey(attentionDismissKey(b.key)));
await tester.pumpAndSettle();
expect(find.byKey(attentionSheetKey), findsOneWidget);
expect(find.text('Needs you'), findsOneWidget);
expect(find.byKey(attentionRowKey(a.key)), findsOneWidget);
expect(find.byKey(attentionRowKey(b.key)), findsOneWidget);
expect(find.text('Ship the release'), findsOneWidget);
expect(find.text('Release · Run failed'), findsOneWidget);
expect(find.text('Nightly audit'), findsOneWidget);
expect(
find.text('Nightly audit · Waiting for your decision'),
findsOneWidget,
);
expect(find.byKey(attentionClearAllKey), findsOneWidget);
// Each row leads with the shared run status glyph, as the web's rows.
expect(
tester
.widgetList<RunStatusIcon>(find.byType(RunStatusIcon))
.map((icon) => icon.state),
unorderedEquals(['failed', 'waiting']),
);
expect(dismissed.map((entry) => entry.key), [b.key]);
expect(opened, isEmpty);
// The browser keeps the sheet open and redraws it; the caller removed the
// dismissed identity, so the remaining row is still there for a second one.
expect(find.byKey(attentionSheetKey), findsOneWidget);
expect(find.byKey(attentionRowKey(b.key)), findsNothing);
expect(find.byKey(attentionRowKey(a.key)), findsOneWidget);
});
// The browser names each destructive control after the row it removes.
expect(attentionDismissName(tester, a), 'Dismiss Ship the release');
expect(attentionDismissName(tester, b), 'Dismiss Nightly audit');
expect(find.text('Dismiss'), findsNothing);
});
testWidgets('$host repeated labels add the run id to the dismiss name', (
tester,
) async {
final first = attentionFixture(id: 11, title: 'Nightly audit');
final second = attentionFixture(id: 12, title: 'Nightly audit');
await tester.pumpWidget(
attentionApp(
NeedsYouPage(entries: [first, second], cupertino: native),
cupertino: native,
testWidgets('Material row opens its run and only a Failed row is dismissed', (
tester,
) async {
final failed = attentionFixture(id: 1, title: 'Ship the release');
final decision = attentionFixture(
id: 2,
title: 'Approve the release',
status: 'waiting',
);
final source = ValueNotifier<List<AttentionEntry>>([failed, decision]);
addTearDown(source.dispose);
final opened = <AttentionEntry>[];
final dismissed = <AttentionEntry>[];
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: opened,
dismissed: dismissed,
cleared: <List<AttentionEntry>>[],
),
);
),
);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
await tester.tap(find.byKey(attentionRowKey(failed.key)));
await tester.pumpAndSettle();
expect(
attentionDismissName(tester, first),
'Dismiss Nightly audit (run 11)',
);
expect(
attentionDismissName(tester, second),
'Dismiss Nightly audit (run 12)',
);
});
expect(opened.map((entry) => entry.key), [failed.key]);
expect(
dismissed.map((entry) => entry.key),
[failed.key],
reason: 'opening a failed run is the operator dealing with it',
);
expect(find.byKey(attentionSheetKey), findsNothing);
testWidgets('$host row Dismiss names its identity and stays open', (
tester,
) async {
final a = attentionFixture(id: 1, title: 'Ship the release');
final b = attentionFixture(id: 2, title: 'Fix the export');
final source = ValueNotifier<List<AttentionEntry>>([a, b]);
addTearDown(source.dispose);
final opened = <AttentionEntry>[];
final dismissed = <AttentionEntry>[];
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: opened,
dismissed: dismissed,
cleared: <List<AttentionEntry>>[],
cupertino: native,
),
cupertino: native,
),
);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
await tester.tap(find.byKey(attentionRowKey(decision.key)));
await tester.pumpAndSettle();
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
await tester.tap(find.byKey(attentionDismissKey(b.key)));
await tester.pumpAndSettle();
expect(dismissed.map((entry) => entry.key), [b.key]);
expect(opened, isEmpty);
// The browser keeps the sheet open and redraws it; the caller removed the
// dismissed identity, so the remaining row is still there for a second one.
expect(find.byKey(attentionSheetKey), findsOneWidget);
expect(find.byKey(attentionRowKey(b.key)), findsNothing);
expect(find.byKey(attentionRowKey(a.key)), findsOneWidget);
});
testWidgets('$host row opens its run and only a Failed row is dismissed', (
tester,
) async {
final failed = attentionFixture(id: 1, title: 'Ship the release');
final decision = attentionFixture(
id: 2,
title: 'Approve the release',
status: 'waiting',
);
final source = ValueNotifier<List<AttentionEntry>>([failed, decision]);
addTearDown(source.dispose);
final opened = <AttentionEntry>[];
final dismissed = <AttentionEntry>[];
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: opened,
dismissed: dismissed,
cleared: <List<AttentionEntry>>[],
cupertino: native,
),
cupertino: native,
),
);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
await tester.tap(find.byKey(attentionRowKey(failed.key)));
await tester.pumpAndSettle();
expect(opened.map((entry) => entry.key), [failed.key]);
expect(
dismissed.map((entry) => entry.key),
[failed.key],
reason: 'opening a failed run is the operator dealing with it',
);
expect(find.byKey(attentionSheetKey), findsNothing);
await tester.tap(find.byKey(attentionBellKey));
await tester.pumpAndSettle();
await tester.tap(find.byKey(attentionRowKey(decision.key)));
await tester.pumpAndSettle();
expect(opened.map((entry) => entry.key), [failed.key, decision.key]);
expect(
dismissed.map((entry) => entry.key),
[failed.key],
reason: 'a decision stays until the operator answers it',
);
expect(find.byKey(attentionSheetKey), findsNothing);
});
}
expect(opened.map((entry) => entry.key), [failed.key, decision.key]);
expect(
dismissed.map((entry) => entry.key),
[failed.key],
reason: 'a decision stays until the operator answers it',
);
expect(find.byKey(attentionSheetKey), findsNothing);
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/attention/domain/attention_models.dart';
@@ -27,27 +26,13 @@ AttentionEntry attentionFixture({
})!;
}
Widget attentionApp(
Widget home, {
bool cupertino = false,
bool dark = false,
double textScale = 1,
}) {
Widget attentionApp(Widget home, {bool dark = false, double textScale = 1}) {
Widget scaled(BuildContext context, Widget? app) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(textScale)),
child: app!,
);
if (cupertino) {
return CupertinoApp(
theme: CupertinoThemeData(
brightness: dark ? Brightness.dark : Brightness.light,
),
builder: scaled,
home: home,
);
}
return MaterialApp(
theme: ThemeData(
platform: TargetPlatform.android,
@@ -63,14 +48,12 @@ class NeedsYouPage extends StatelessWidget {
const NeedsYouPage({
super.key,
required this.entries,
this.cupertino = false,
this.onOpen,
this.onDismiss,
this.onClearAll,
});
final List<AttentionEntry> entries;
final bool cupertino;
final ValueChanged<AttentionEntry>? onOpen;
final ValueChanged<AttentionEntry>? onDismiss;
final ValueChanged<List<AttentionEntry>>? onClearAll;
@@ -79,15 +62,11 @@ class NeedsYouPage extends StatelessWidget {
Widget build(BuildContext context) {
final bell = NeedsYouBell(
entries: entries,
cupertino: cupertino,
onOpen: onOpen ?? (_) {},
onDismiss: onDismiss ?? (_) {},
onClearAll: onClearAll ?? (_) {},
);
final body = Center(child: bell);
return cupertino
? CupertinoPageScaffold(child: SafeArea(child: body))
: Scaffold(body: SafeArea(child: body));
return Scaffold(body: SafeArea(child: Center(child: bell)));
}
}
@@ -101,14 +80,12 @@ class AttentionHarness extends StatelessWidget {
required this.opened,
required this.dismissed,
required this.cleared,
this.cupertino = false,
});
final ValueNotifier<List<AttentionEntry>> source;
final List<AttentionEntry> opened;
final List<AttentionEntry> dismissed;
final List<List<AttentionEntry>> cleared;
final bool cupertino;
@override
Widget build(BuildContext context) {
@@ -116,7 +93,6 @@ class AttentionHarness extends StatelessWidget {
valueListenable: source,
builder: (context, entries, _) => NeedsYouPage(
entries: entries,
cupertino: cupertino,
onOpen: opened.add,
onDismiss: (entry) {
dismissed.add(entry);
@@ -143,24 +119,16 @@ bool bellHasFocus(WidgetTester tester) {
final widget = tester.widget(find.byKey(attentionBellKey));
final node = switch (widget) {
IconButton() => widget.focusNode,
CupertinoButton() => widget.focusNode,
_ => null,
};
return node?.hasPrimaryFocus ?? false;
}
/// The accessible name of one row's Dismiss action, whichever host drew it.
/// The accessible name of one row's Dismiss action.
///
/// Material exposes it as the button tooltip, Cupertino as the xmark icon's
/// semantic label; both must name the row they remove.
/// The Material control exposes it as the button tooltip; it must name the row
/// it removes.
String attentionDismissName(WidgetTester tester, AttentionEntry entry) {
final key = attentionDismissKey(entry.key);
final xmark = find.descendant(
of: find.byKey(key),
matching: find.byIcon(CupertinoIcons.xmark),
);
if (xmark.evaluate().isNotEmpty) {
return tester.widget<Icon>(xmark).semanticLabel ?? '';
}
return tester.widget<IconButton>(find.byKey(key)).tooltip ?? '';
}
@@ -6,12 +6,11 @@ import 'package:pipelines_app/features/attention/ui/notification_permission_tile
import 'needs_you_test_support.dart';
/// The tile inside a normal page, so both native hosts can draw it. The page
/// scrolls like the Settings list does, so the tile is never given a fixed
/// The tile inside a normal page, so it is drawn the way Settings draws it. The
/// page scrolls like the Settings list does, so the tile is never given a fixed
/// height to overflow.
Widget _page({
required NotificationPermissionState state,
bool cupertino = false,
bool asked = false,
VoidCallback? onRequest,
}) => attentionApp(
@@ -24,124 +23,130 @@ Widget _page({
),
),
),
cupertino: cupertino,
);
void _noop() {}
void main() {
for (final native in [false, true]) {
final host = native ? 'Cupertino' : 'Material';
testWidgets('$host shows a compact row for each state', (tester) async {
final cases = <NotificationPermissionState, String>{
NotificationPermissionState.unsupported: notificationUnsupportedCopy,
NotificationPermissionState.needsSecureContext:
notificationInsecureCopy,
NotificationPermissionState.granted: notificationGrantedCopy,
NotificationPermissionState.denied: notificationDeniedCopy,
NotificationPermissionState.notRequested: notificationDefaultCopy,
};
for (final entry in cases.entries) {
await tester.pumpWidget(
_page(state: entry.key, cupertino: native, onRequest: _noop),
);
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), 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
? findsOneWidget
: findsNothing,
reason: '${entry.key}',
);
}
});
testWidgets('$host shows the asked wording without an action', (
tester,
) async {
await tester.pumpWidget(
_page(
state: NotificationPermissionState.notRequested,
asked: true,
cupertino: native,
),
testWidgets('Material shows a compact row for each state', (tester) async {
final cases = <NotificationPermissionState, String>{
NotificationPermissionState.unsupported: notificationUnsupportedCopy,
NotificationPermissionState.needsSecureContext: notificationInsecureCopy,
NotificationPermissionState.granted: notificationGrantedCopy,
NotificationPermissionState.denied: notificationDeniedCopy,
NotificationPermissionState.notRequested: notificationDefaultCopy,
};
for (final entry in cases.entries) {
await tester.pumpWidget(_page(state: entry.key, onRequest: _noop));
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), 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
? findsOneWidget
: findsNothing,
reason: '${entry.key}',
);
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 {
var requested = 0;
await tester.pumpWidget(
_page(
state: NotificationPermissionState.notRequested,
cupertino: native,
onRequest: () => requested++,
),
);
await tester.tap(find.byKey(notificationEnableKey));
await tester.pump();
expect(requested, 1);
});
testWidgets('Material shows the asked wording without an action', (
tester,
) async {
await tester.pumpWidget(
_page(state: NotificationPermissionState.notRequested, asked: true),
);
expect(find.text('Alerts are still off'), findsOneWidget);
expect(find.bySemanticsLabel(notificationDefaultAskedCopy), findsOne);
expect(find.bySemanticsLabel(notificationDefaultCopy), findsNothing);
});
testWidgets('$host tile wraps at 320 logical px and 2x in dark', (
tester,
) async {
tester.view.devicePixelRatio = 2;
tester.view.physicalSize = const Size(640, 1280);
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
testWidgets('Material Enable runs the explicit request', (tester) async {
var requested = 0;
await tester.pumpWidget(
_page(
state: NotificationPermissionState.notRequested,
onRequest: () => requested++,
),
);
await tester.tap(find.byKey(notificationEnableKey));
await tester.pump();
expect(requested, 1);
});
// The undecided state is the hardest: it carries the Enable action as well
// as the longest copy, so the section title must still have room to read.
await tester.pumpWidget(
attentionApp(
Scaffold(
body: SingleChildScrollView(
child: NotificationPermissionTile(
state: NotificationPermissionState.notRequested,
onRequest: _noop,
),
testWidgets('a stale cupertino flag still draws the Material row', (
tester,
) async {
await tester.pumpWidget(
attentionApp(
Scaffold(
body: SingleChildScrollView(
child: NotificationPermissionTile(
state: NotificationPermissionState.notRequested,
cupertino: true,
onRequest: _noop,
),
),
cupertino: native,
dark: true,
textScale: 2,
),
);
expect(tester.takeException(), isNull);
),
);
final view = notificationPermissionView(
NotificationPermissionState.notRequested,
);
final helper = tester.renderObject<RenderParagraph>(
find.text(view.helper),
);
expect(
helper.size.width,
greaterThan(100),
reason: 'the action must not squeeze the row copy',
);
final body = tester.renderObject<RenderParagraph>(
find.text(view.headline),
);
expect(body.didExceedMaxLines, isFalse);
expect(find.byKey(notificationEnableKey), findsOneWidget);
expect(
tester.widget(find.byKey(notificationEnableKey)),
isA<FilledButton>(),
);
expect(find.text(notificationEnableShortLabel), findsOneWidget);
});
final rect = tester.getRect(find.byKey(notificationStateKey));
expect(rect.left, greaterThanOrEqualTo(0));
expect(rect.right, lessThanOrEqualTo(320));
expect(tester.takeException(), isNull);
});
}
testWidgets('Material tile wraps at 320 logical px and 2x in dark', (
tester,
) async {
tester.view.devicePixelRatio = 2;
tester.view.physicalSize = const Size(640, 1280);
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
// The undecided state is the hardest: it carries the Enable action as well
// as the longest copy, so the section title must still have room to read.
await tester.pumpWidget(
attentionApp(
Scaffold(
body: SingleChildScrollView(
child: NotificationPermissionTile(
state: NotificationPermissionState.notRequested,
onRequest: _noop,
),
),
),
dark: true,
textScale: 2,
),
);
expect(tester.takeException(), isNull);
final view = notificationPermissionView(
NotificationPermissionState.notRequested,
);
final helper = tester.renderObject<RenderParagraph>(find.text(view.helper));
expect(
helper.size.width,
greaterThan(100),
reason: 'the action must not squeeze the row copy',
);
final body = tester.renderObject<RenderParagraph>(find.text(view.headline));
expect(body.didExceedMaxLines, isFalse);
expect(find.byKey(notificationEnableKey), findsOneWidget);
final rect = tester.getRect(find.byKey(notificationStateKey));
expect(rect.left, greaterThanOrEqualTo(0));
expect(rect.right, lessThanOrEqualTo(320));
expect(tester.takeException(), isNull);
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
@@ -34,61 +33,53 @@ class _Gateway extends FakeChatGateway {
}
void main() {
for (final cupertino in [false, true]) {
testWidgets(
'a pushed phone chat stays read and preserves underlying list chrome ($cupertino)',
(tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
SharedPreferences.setMockInitialValues({});
final gateway = _Gateway()..history = (_) async => chatPage([]);
addTearDown(gateway.close);
final bar = ShellBarRegistry();
addTearDown(bar.dispose);
final selected = ValueNotifier<String?>('s1');
addTearDown(selected.dispose);
final screen = ShellBarScope(
registry: bar,
destination: AppDestination.chat,
child: ValueListenableBuilder<String?>(
valueListenable: selected,
builder: (_, id, _) => ChatScreen(
gateway: gateway,
initialSessionId: id,
onBack: () => selected.value = null,
),
testWidgets(
'a pushed phone chat stays read and preserves underlying list chrome',
(tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
SharedPreferences.setMockInitialValues({});
final gateway = _Gateway()..history = (_) async => chatPage([]);
addTearDown(gateway.close);
final bar = ShellBarRegistry();
addTearDown(bar.dispose);
final selected = ValueNotifier<String?>('s1');
addTearDown(selected.dispose);
final screen = ShellBarScope(
registry: bar,
destination: AppDestination.chat,
child: ValueListenableBuilder<String?>(
valueListenable: selected,
builder: (_, id, _) => ChatScreen(
gateway: gateway,
initialSessionId: id,
onBack: () => selected.value = null,
),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: screen))
: MaterialApp(home: Scaffold(body: screen)),
);
await tester.pumpAndSettle();
final list = tester.widget<ChatSessionsScreen>(
find.byType(ChatSessionsScreen, skipOffstage: false),
);
final controller = list.controller!;
expect(controller.activeSessionId, 's1');
expect(bar.specFor(AppDestination.chat)?.actions, isNotEmpty);
gateway.emitEvent(chatTextFrame('New live answer', session: 's1'));
await tester.pumpAndSettle();
expect(controller.sessions.where(controller.isUnseen), isEmpty);
gateway.emitEvent(chatTextFrame('Different answer', session: 's2'));
await tester.pumpAndSettle();
expect(
controller.sessions
.where(controller.isUnseen)
.map((row) => row['id']),
['s2'],
);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(controller.activeSessionId, isNull);
expect(find.text('Open conversation'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
},
);
}
),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: screen)));
await tester.pumpAndSettle();
final list = tester.widget<ChatSessionsScreen>(
find.byType(ChatSessionsScreen, skipOffstage: false),
);
final controller = list.controller!;
expect(controller.activeSessionId, 's1');
expect(bar.specFor(AppDestination.chat)?.actions, isNotEmpty);
gateway.emitEvent(chatTextFrame('New live answer', session: 's1'));
await tester.pumpAndSettle();
expect(controller.sessions.where(controller.isUnseen), isEmpty);
gateway.emitEvent(chatTextFrame('Different answer', session: 's2'));
await tester.pumpAndSettle();
expect(
controller.sessions.where(controller.isUnseen).map((row) => row['id']),
['s2'],
);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(controller.activeSessionId, isNull);
expect(find.text('Open conversation'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
},
);
}
@@ -75,6 +75,24 @@ void main() {
return controller;
}
testWidgets('the panel filters entries through its Material field', (
tester,
) async {
await pump(tester);
final field = find.byType(TextField);
expect(field, findsOneWidget);
expect(
tester.widget<TextField>(field).decoration?.hintText,
'Filter files',
);
await tester.enterText(field, 'notes');
await tester.pumpAndSettle();
expect(find.text('notes.txt'), findsOneWidget);
expect(find.text('picture.png'), findsNothing);
expect(find.widgetWithText(TextButton, '~'), findsOneWidget);
expect(find.widgetWithText(TextButton, 'demo'), findsOneWidget);
});
testWidgets('text tap opens shared viewer and fetches inline URL', (
tester,
) async {
@@ -192,6 +192,13 @@ void main() {
await tester.pumpAndSettle();
expect(widthOf(tester, 'three'), 950);
expect(find.byType(ChatCenterStageStrip), findsNWidgets(2));
expect(
find.descendant(
of: find.byType(ChatCenterStageStrip).first,
matching: find.byType(InkWell),
),
findsOneWidget,
);
expect(find.text('draft'), findsOneWidget);
stage.value = false;
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/workspace/chat_mobile_panes.dart';
@@ -36,54 +35,48 @@ class _ThreadState extends State<_Thread> {
}
void main() {
for (final cupertino in [false, true]) {
for (final height in [32.0, 48.0]) {
testWidgets(
'peek title and switch fit $height height at 2x ($cupertino)',
(tester) async {
var activated = 0;
Size? bodySize;
final viewport = MediaQuery(
data: const MediaQueryData(textScaler: TextScaler.linear(2)),
child: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 320,
height: height,
child: ChatMobilePaneViewport(
peek: true,
active: false,
barReveal: const AlwaysStoppedAnimation(0),
onActivate: () => activated++,
label: 'A long working project name',
paneId: 'first',
child: LayoutBuilder(
builder: (context, constraints) {
bodySize = constraints.biggest;
return const SizedBox.expand();
},
),
),
for (final height in [32.0, 48.0]) {
testWidgets('peek title and switch fit $height height at 2x', (
tester,
) async {
var activated = 0;
Size? bodySize;
final viewport = MediaQuery(
data: const MediaQueryData(textScaler: TextScaler.linear(2)),
child: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 320,
height: height,
child: ChatMobilePaneViewport(
peek: true,
active: false,
barReveal: const AlwaysStoppedAnimation(0),
onActivate: () => activated++,
label: 'A long working project name',
paneId: 'first',
child: LayoutBuilder(
builder: (context, constraints) {
bodySize = constraints.biggest;
return const SizedBox.expand();
},
),
),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: viewport))
: MaterialApp(home: Scaffold(body: viewport)),
);
expect(find.text('A long working project name'), findsOneWidget);
expect(find.text('Switch'), findsOneWidget);
final headerSize = tester.getSize(find.byType(ChatPeekHeader));
expect(headerSize.height, lessThanOrEqualTo(height));
expect(bodySize!.height, closeTo(height - headerSize.height, .01));
await tester.tap(find.text('Switch'));
await tester.pump();
expect(activated, 1);
expect(tester.takeException(), isNull);
},
),
),
);
}
await tester.pumpWidget(MaterialApp(home: Scaffold(body: viewport)));
expect(find.text('A long working project name'), findsOneWidget);
expect(find.text('Switch'), findsOneWidget);
expect(find.byType(TextButton), findsOneWidget);
final headerSize = tester.getSize(find.byType(ChatPeekHeader));
expect(headerSize.height, lessThanOrEqualTo(height));
expect(bodySize!.height, closeTo(height - headerSize.height, .01));
await tester.tap(find.text('Switch'));
await tester.pump();
expect(activated, 1);
expect(tester.takeException(), isNull);
});
}
testWidgets('peek header reserves real body space and keeps reading state', (
tester,
@@ -3,56 +3,47 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace_entrance.dart';
void main() {
for (final cupertino in [false, true]) {
testWidgets('retained entrance moves the same child ($cupertino)', (
tester,
) async {
tester.platformDispatcher.accessibilityFeaturesTestValue =
const FakeAccessibilityFeatures(disableAnimations: false);
addTearDown(
tester.platformDispatcher.clearAccessibilityFeaturesTestValue,
);
final childKey = GlobalKey();
final child = TextField(key: childKey);
Widget host(bool visible, {bool reduced = false}) => MaterialApp(
home: MediaQuery(
data: MediaQueryData(disableAnimations: reduced),
child: SizedBox.expand(
child: ChatWorkspaceEntrance(
visible: visible,
cupertino: cupertino,
child: Material(child: child),
),
testWidgets('retained entrance moves the same child', (tester) async {
tester.platformDispatcher.accessibilityFeaturesTestValue =
const FakeAccessibilityFeatures(disableAnimations: false);
addTearDown(tester.platformDispatcher.clearAccessibilityFeaturesTestValue);
final childKey = GlobalKey();
final child = TextField(key: childKey);
Widget host(bool visible, {bool reduced = false}) => MaterialApp(
home: MediaQuery(
data: MediaQueryData(disableAnimations: reduced),
child: SizedBox.expand(
child: ChatWorkspaceEntrance(
visible: visible,
cupertino: false,
child: Material(child: child),
),
),
);
await tester.pumpWidget(host(false));
final element = childKey.currentContext;
final state = childKey.currentState;
expect(find.byKey(childKey), findsNothing);
await tester.pumpWidget(host(true));
final start = tester.getTopLeft(find.byKey(childKey));
await tester.pump();
await tester.pump(const Duration(milliseconds: 80));
final middle = tester.getTopLeft(find.byKey(childKey));
await tester.pumpAndSettle();
final end = tester.getTopLeft(find.byKey(childKey));
expect(cupertino ? middle.dx : middle.dy, greaterThan(0));
expect(
cupertino ? middle.dx : middle.dy,
lessThan(cupertino ? start.dx : start.dy),
);
expect(end, Offset.zero);
expect(childKey.currentContext, same(element));
expect(childKey.currentState, same(state));
await tester.enterText(find.byType(TextField), 'Retained draft');
await tester.pumpWidget(host(false));
await tester.pumpAndSettle();
await tester.pumpWidget(host(true, reduced: true));
expect(tester.getTopLeft(find.byKey(childKey)), Offset.zero);
expect(find.text('Retained draft'), findsOneWidget);
expect(childKey.currentState, same(state));
expect(tester.takeException(), isNull);
});
}
),
);
await tester.pumpWidget(host(false));
final element = childKey.currentContext;
final state = childKey.currentState;
expect(find.byKey(childKey), findsNothing);
await tester.pumpWidget(host(true));
final start = tester.getTopLeft(find.byKey(childKey));
await tester.pump();
await tester.pump(const Duration(milliseconds: 80));
final middle = tester.getTopLeft(find.byKey(childKey));
await tester.pumpAndSettle();
final end = tester.getTopLeft(find.byKey(childKey));
expect(middle.dy, greaterThan(0));
expect(middle.dy, lessThan(start.dy));
expect(end, Offset.zero);
expect(childKey.currentContext, same(element));
expect(childKey.currentState, same(state));
await tester.enterText(find.byType(TextField), 'Retained draft');
await tester.pumpWidget(host(false));
await tester.pumpAndSettle();
await tester.pumpWidget(host(true, reduced: true));
expect(tester.getTopLeft(find.byKey(childKey)), Offset.zero);
expect(find.text('Retained draft'), findsOneWidget);
expect(childKey.currentState, same(state));
expect(tester.takeException(), isNull);
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -164,95 +163,27 @@ void main() {
expect(clamped, lessThan(panned));
});
testWidgets('320px at 2x opens and closes on the dark Cupertino host', (
tester,
) async {
tester.view.physicalSize = const Size(320, 700);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final picked = <String>[];
testWidgets('expanded Fit is an activatable labelled button', (tester) async {
await tester.pumpWidget(
CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoPageScaffold(
child: Builder(
builder: (context) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: const TextScaler.linear(2)),
child: DefinitionGraphView(
graph: linearGraph(),
selectedStage: 'build',
onSelected: picked.add,
),
),
),
),
_materialHost(
graph: linearGraph(),
selected: 'build',
onSelected: (_) {},
),
);
await _settle(tester);
final inline = _inlineTransform(tester);
final inlineMatrix = Matrix4.copy(inline.value);
await tester.tap(find.byKey(const Key('graph-expand')));
await tester.pumpAndSettle();
expect(find.byType(GraphExpandedView), findsOneWidget);
final fit = tester
.getSemantics(_inExpanded(find.byKey(const Key('graph-fit'))))
.getSemanticsData();
expect(fit.label, graphFitLabel);
expect(fit.flagsCollection.isButton, isTrue);
expect(
_inExpanded(find.byType(CupertinoNavigationBarBackButton)),
findsOneWidget,
);
expect(_inExpanded(find.byKey(const Key('graph-fit'))), findsOneWidget);
expect(
tester.widget<GraphStageNode>(_inExpanded(_node('build'))).selected,
fit.hasAction(SemanticsAction.tap),
isTrue,
reason: 'Fit must expose its tap action on the labelled node',
);
expect(tester.takeException(), isNull);
await tester.tap(find.byType(CupertinoNavigationBarBackButton));
await tester.pumpAndSettle();
expect(find.byType(GraphExpandedView), findsNothing);
expect(tester.widget<GraphStageNode>(_node('build')).selected, isTrue);
expect(inline.value.storage, orderedEquals(inlineMatrix.storage));
expect(picked, isEmpty);
expect(tester.takeException(), isNull);
});
testWidgets('expanded Fit is an activatable labelled button on both hosts', (
tester,
) async {
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
await tester.pumpWidget(
cupertino
? CupertinoApp(
home: CupertinoPageScaffold(
child: DefinitionGraphView(
graph: linearGraph(),
selectedStage: 'build',
onSelected: (_) {},
),
),
)
: _materialHost(
graph: linearGraph(),
selected: 'build',
onSelected: (_) {},
),
);
await _settle(tester);
await tester.tap(find.byKey(const Key('graph-expand')));
await tester.pumpAndSettle();
final fit = tester
.getSemantics(_inExpanded(find.byKey(const Key('graph-fit'))))
.getSemanticsData();
expect(fit.label, graphFitLabel, reason: '$host Fit must be labelled');
expect(fit.flagsCollection.isButton, isTrue);
expect(
fit.hasAction(SemanticsAction.tap),
isTrue,
reason: '$host Fit must expose its tap action on the labelled node',
);
}
});
}
@@ -7,101 +7,79 @@ import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
import 'graph_viewport_fixtures.dart';
void main() {
testWidgets('Fit and Expand stay labelled, activatable buttons on both hosts', (
testWidgets('Fit and Expand stay labelled, activatable buttons', (
tester,
) async {
for (final cupertino in [false, true]) {
final host = cupertino ? 'cupertino' : 'material';
final controller = GraphViewportController();
addTearDown(controller.dispose);
var expands = 0;
await tester.pumpWidget(
viewportHost(
controller: controller,
child: viewportTargets([]),
cupertino: cupertino,
onExpand: () => expands += 1,
),
);
await settleViewport(tester);
final fitted = controller.snapshot;
expect(
find.ancestor(
of: find.byKey(const Key('graph-fit')),
matching: find.byType(GlassPill),
),
findsOneWidget,
);
final controller = GraphViewportController();
addTearDown(controller.dispose);
var expands = 0;
await tester.pumpWidget(
viewportHost(
controller: controller,
child: viewportTargets([]),
onExpand: () => expands += 1,
),
);
await settleViewport(tester);
final fitted = controller.snapshot;
expect(
find.ancestor(
of: find.byKey(const Key('graph-fit')),
matching: find.byType(GlassPill),
),
findsOneWidget,
);
for (final control in viewportControls().entries) {
final node = tester.getSemantics(find.byKey(control.key));
final data = node.getSemanticsData();
expect(
data.label,
control.value,
reason: '$host ${control.key} must have the web name',
);
expect(
data.flagsCollection.isButton,
isTrue,
reason: '$host ${control.key} must be announced as a button',
);
// A labelled button with no action is unusable with VoiceOver/TalkBack;
// this is the regression the excluded-button wrapper introduced.
expect(
data.hasAction(SemanticsAction.tap),
isTrue,
reason: '$host ${control.key} must expose a tap action',
);
}
// The exposed action must run the real callback, not just be announced.
await pinchViewport(tester, const Offset(200, 150), 2);
await tester.pumpAndSettle();
expect(controller.snapshot, isNot(fitted));
performViewportTap(tester, find.byKey(const Key('graph-fit')));
await tester.pump();
expect(controller.scale, closeTo(fitted.scale, 1e-9));
performViewportTap(tester, find.byKey(const Key('graph-expand')));
await tester.pump();
expect(expands, 1, reason: '$host Expand must activate');
for (final control in viewportControls().entries) {
final node = tester.getSemantics(find.byKey(control.key));
final data = node.getSemanticsData();
expect(data.label, control.value);
expect(data.flagsCollection.isButton, isTrue);
// A labelled button with no action is unusable with a screen reader;
// this is the regression the excluded-button wrapper introduced.
expect(data.hasAction(SemanticsAction.tap), isTrue);
}
// The exposed action must run the real callback, not just be announced.
await pinchViewport(tester, const Offset(200, 150), 2);
await tester.pumpAndSettle();
expect(controller.snapshot, isNot(fitted));
performViewportTap(tester, find.byKey(const Key('graph-fit')));
await tester.pump();
expect(controller.scale, closeTo(fitted.scale, 1e-9));
performViewportTap(tester, find.byKey(const Key('graph-expand')));
await tester.pump();
expect(expands, 1);
});
testWidgets('320px at 2x keeps native controls and gestures on both hosts', (
tester,
) async {
for (final cupertino in [false, true]) {
final controller = GraphViewportController();
addTearDown(controller.dispose);
await tester.pumpWidget(
viewportHost(
controller: controller,
child: viewportTargets([]),
cupertino: cupertino,
dark: cupertino,
textScale: 2,
viewport: const Size(320, 300),
onExpand: () {},
),
);
await settleViewport(tester);
expect(find.byKey(const Key('graph-fit')), findsOneWidget);
expect(find.byKey(const Key('graph-expand')), findsOneWidget);
expect(tester.takeException(), isNull);
testWidgets('320px at 2x keeps native controls and gestures', (tester) async {
final controller = GraphViewportController();
addTearDown(controller.dispose);
await tester.pumpWidget(
viewportHost(
controller: controller,
child: viewportTargets([]),
textScale: 2,
viewport: const Size(320, 300),
onExpand: () {},
),
);
await settleViewport(tester);
expect(find.byKey(const Key('graph-fit')), findsOneWidget);
expect(find.byKey(const Key('graph-expand')), findsOneWidget);
expect(tester.takeException(), isNull);
final before = controller.offset;
await dragViewport(
tester,
find.byKey(const Key('graph-viewport')),
const Offset(-30, -10),
);
expect(controller.offset, isNot(before));
await pinchViewport(tester, const Offset(160, 150), 2);
await tester.pumpAndSettle();
expect(controller.scale, greaterThan(0.3));
expect(tester.takeException(), isNull);
}
final before = controller.offset;
await dragViewport(
tester,
find.byKey(const Key('graph-viewport')),
const Offset(-30, -10),
);
expect(controller.offset, isNot(before));
await pinchViewport(tester, const Offset(160, 150), 2);
await tester.pumpAndSettle();
expect(controller.scale, greaterThan(0.3));
expect(tester.takeException(), isNull);
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -48,7 +47,6 @@ Widget viewportHost({
required GraphViewportController controller,
required Widget child,
VoidCallback? onExpand,
bool cupertino = false,
bool dark = false,
double textScale = 1,
Size viewport = defaultViewportSize,
@@ -65,14 +63,6 @@ Widget viewportHost({
),
),
);
if (cupertino) {
return CupertinoApp(
theme: CupertinoThemeData(
brightness: dark ? Brightness.dark : Brightness.light,
),
home: CupertinoPageScaffold(child: Center(child: graph)),
);
}
return MaterialApp(
theme: dark ? ThemeData.dark() : ThemeData.light(),
home: Scaffold(body: Center(child: graph)),
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -57,21 +56,6 @@ Widget _materialHost(
);
}
Widget _cupertinoHost(JsonMap graph, {ValueChanged<String>? onSelected}) {
return CupertinoApp(
home: CupertinoPageScaffold(
child: SizedBox(
width: 900,
height: 700,
child: DefinitionGraphView(
graph: graph,
onSelected: onSelected ?? (_) {},
),
),
),
);
}
/// Settles the two-frame measure-then-place contract.
Future<void> _settle(WidgetTester tester) async {
await tester.pump();
@@ -315,27 +299,4 @@ void main() {
expect(find.byType(GraphStageNode), findsNothing);
expect(find.byType(InteractiveViewer), findsNothing);
});
testWidgets('cupertino host composes native buttons and keeps identity', (
tester,
) async {
final picked = <String>[];
await tester.pumpWidget(
_cupertinoHost(linearGraph(), onSelected: picked.add),
);
await _settle(tester);
expect(
find.descendant(
of: find.byType(GraphStageNode),
matching: find.byType(CupertinoButton),
),
findsNWidgets(5),
);
expect(find.byType(Card), findsNothing);
_expectNoOverlaps(tester);
await _tapNode(tester, '#failure');
expect(picked, ['#failure']);
});
}
@@ -1,7 +1,6 @@
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -21,10 +20,6 @@ Widget _material(Widget child) => MaterialApp(
home: Scaffold(body: Center(child: child)),
);
Widget _cupertino(Widget child) => CupertinoApp(
home: CupertinoPageScaffold(child: Center(child: child)),
);
/// The node centred on an opaque page, inside its own repaint boundary so the
/// painted result can be read back as pixels.
Widget _framed(Key key, Widget Function(Widget) wrap, Widget child) => wrap(
@@ -153,58 +148,27 @@ void main() {
}
});
testWidgets('unselected cupertino node paints a visible container', (
tester,
) async {
final key = GlobalKey();
await tester.pumpWidget(
_framed(
key,
_cupertino,
GraphStageNode(node: _stage, onSelected: (_) {}),
),
);
final shot = await _shot(tester, key);
final rect = tester.getRect(find.byType(CupertinoButton));
// Just inside the left edge of the control, clear of the label's inset.
final body = shot.at(rect.centerLeft + const Offset(4, 0));
final page = shot.at(const Offset(4, 4));
expect(
_distance(body, page),
greaterThan(24),
reason: 'an unselected cupertino node needs its own visible surface',
);
});
testWidgets('selected state changes the painted surface in both hosts', (
tester,
) async {
for (final wrap in [_material, _cupertino]) {
final colors = <bool, Color>{};
for (final selected in [false, true]) {
final key = GlobalKey();
await tester.pumpWidget(
_framed(
key,
wrap,
GraphStageNode(
node: _stage,
selected: selected,
onSelected: (_) {},
),
),
);
final shot = await _shot(tester, key);
final rect = tester.getRect(find.byType(GraphStageNode));
colors[selected] = shot.at(rect.centerLeft + const Offset(4, 0));
}
expect(
_distance(colors[false]!, colors[true]!),
greaterThan(16),
reason:
'selection must be visible, not only announced: the surface fill '
'and the outlined border change together',
testWidgets('selected state changes the painted surface', (tester) async {
final colors = <bool, Color>{};
for (final selected in [false, true]) {
final key = GlobalKey();
await tester.pumpWidget(
_framed(
key,
_material,
GraphStageNode(node: _stage, selected: selected, onSelected: (_) {}),
),
);
final shot = await _shot(tester, key);
final rect = tester.getRect(find.byType(GraphStageNode));
colors[selected] = shot.at(rect.centerLeft + const Offset(4, 0));
}
expect(
_distance(colors[false]!, colors[true]!),
greaterThan(16),
reason:
'selection must be visible, not only announced: the surface fill '
'and the outlined border change together',
);
});
}
@@ -1,6 +1,5 @@
import 'dart:ui' show Tristate;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
@@ -17,10 +16,6 @@ Widget _material(Widget child) => MaterialApp(
home: Scaffold(body: Center(child: child)),
);
Widget _cupertino(Widget child) => CupertinoApp(
home: CupertinoPageScaffold(child: Center(child: child)),
);
/// Applies a 2x text scale below the app so the fixture renders as a real
/// scale-2 layout rather than a test-only text property.
Widget _scaled(Widget child) => Builder(
@@ -65,9 +60,7 @@ void main() {
expect(_semantics(tester).label, 'Success');
});
testWidgets('selected node is announced selected in both native hosts', (
tester,
) async {
testWidgets('selected node is announced selected', (tester) async {
await tester.pumpWidget(
_material(
GraphStageNode(node: _stage, selected: true, onSelected: (_) {}),
@@ -76,15 +69,6 @@ void main() {
expect(find.byType(Card), findsOneWidget);
expect(find.byType(InkWell), findsOneWidget);
_expectSelectable(tester, selected: true);
await tester.pumpWidget(
_cupertino(
GraphStageNode(node: _stage, selected: true, onSelected: (_) {}),
),
);
expect(find.byType(CupertinoButton), findsOneWidget);
expect(find.byType(Card), findsNothing);
_expectSelectable(tester, selected: true);
});
testWidgets('unselected node is not announced selected', (tester) async {
@@ -96,17 +80,15 @@ void main() {
});
testWidgets('keyboard activation selects the node', (tester) async {
for (final wrap in [_material, _cupertino]) {
final picked = <String>[];
await tester.pumpWidget(
wrap(GraphStageNode(node: _stage, onSelected: picked.add)),
);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.pumpAndSettle();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(picked, ['build']);
}
final picked = <String>[];
await tester.pumpWidget(
_material(GraphStageNode(node: _stage, onSelected: picked.add)),
);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.pumpAndSettle();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(picked, ['build']);
});
testWidgets('keyboard selection keeps focus inside the material node', (
@@ -144,46 +126,44 @@ void main() {
) async {
const label = 'implementer-with-an-unshortened-stage-label';
const node = GraphNode(key: label, terminal: false, stageIndex: 0);
for (final wrap in [_material, _cupertino]) {
await tester.pumpWidget(
wrap(
_scaled(
SizedBox(
width: 150,
child: GraphStageNode(node: node, onSelected: (_) {}),
),
await tester.pumpWidget(
_material(
_scaled(
SizedBox(
width: 150,
child: GraphStageNode(node: node, onSelected: (_) {}),
),
),
);
),
);
expect(tester.takeException(), isNull);
final text = tester.widget<Text>(_visual(label));
expect(text.data!.replaceAll('\u200B', ''), label);
expect(text.maxLines, isNull);
expect(text.overflow, isNull);
final paragraph = tester.renderObject<RenderParagraph>(_visual(label));
expect(paragraph.size.width, lessThanOrEqualTo(150));
expect(
paragraph.size.height,
greaterThan(50),
reason: 'the 2x label must occupy more than one 2x text line',
);
// No glyph may paint outside the paragraph: every laid-out line,
// including a hyphen-broken segment, fits the width the control gave it.
final painter = TextPainter(
text: paragraph.text,
textDirection: paragraph.textDirection,
textScaler: paragraph.textScaler,
textAlign: paragraph.textAlign,
)..layout(maxWidth: paragraph.size.width);
expect(
painter.computeLineMetrics().every(
(line) => line.width <= paragraph.size.width + 0.5,
),
isTrue,
reason: 'an unshortened label must wrap, not paint over the control',
);
}
expect(tester.takeException(), isNull);
final text = tester.widget<Text>(_visual(label));
expect(text.data!.replaceAll('\u200B', ''), label);
expect(text.maxLines, isNull);
expect(text.overflow, isNull);
final paragraph = tester.renderObject<RenderParagraph>(_visual(label));
expect(paragraph.size.width, lessThanOrEqualTo(150));
expect(
paragraph.size.height,
greaterThan(50),
reason: 'the 2x label must occupy more than one 2x text line',
);
// No glyph may paint outside the paragraph: every laid-out line,
// including a hyphen-broken segment, fits the width the control gave it.
final painter = TextPainter(
text: paragraph.text,
textDirection: paragraph.textDirection,
textScaler: paragraph.textScaler,
textAlign: paragraph.textAlign,
)..layout(maxWidth: paragraph.size.width);
expect(
painter.computeLineMetrics().every(
(line) => line.width <= paragraph.size.width + 0.5,
),
isTrue,
reason: 'an unshortened label must wrap, not paint over the control',
);
});
testWidgets('terminal shows its definition label and no invented status', (
@@ -207,7 +187,7 @@ void main() {
testWidgets('a recorded status is shown verbatim', (tester) async {
await tester.pumpWidget(
_cupertino(
_material(
GraphStageNode(
node: _stage,
recordedStatus: 'failed',
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -113,35 +112,6 @@ Widget _materialHost(
);
}
Widget _cupertinoHost(
JsonMap graph,
JsonMap run, {
ValueChanged<String>? onSelected,
double scale = 1,
}) {
return CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoPageScaffold(
child: Builder(
builder: (context) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(scale)),
child: SizedBox(
width: 320,
height: 700,
child: RunGraphView(
graph: graph,
run: run,
onStageSelected: onSelected ?? (_) {},
),
),
),
),
),
);
}
Future<void> _settle(WidgetTester tester) async {
await tester.pump();
await tester.pump();
@@ -450,39 +420,4 @@ void main() {
_expectNoOverlaps(tester);
expect(tester.takeException(), isNull);
});
testWidgets('dark Cupertino host keeps native nodes and evidence', (
tester,
) async {
final picked = <String>[];
await tester.pumpWidget(
_cupertinoHost(linearGraph(), _runningRun(), onSelected: picked.add),
);
await _settle(tester);
expect(find.byType(Card), findsNothing);
expect(
find.descendant(
of: find.byType(GraphStageNode),
matching: find.byType(CupertinoButton),
),
findsNWidgets(5),
);
expect(find.text(runGraphExecuted), findsOneWidget);
expect(find.text(runGraphNotExecuted), findsOneWidget);
expect(
tester.widget<GraphStageNode>(_node('plan')).recordedStatus,
'completed',
);
expect(
tester.widget<GraphStageNode>(_node('build')).recordedStatus,
'running',
);
_expectNoOverlaps(tester);
await tester.tap(_node('plan'));
await tester.pump();
expect(picked, ['plan']);
expect(tester.takeException(), isNull);
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -37,13 +36,6 @@ Widget _material(Widget child) => MaterialApp(
),
);
Widget _cupertino(Widget child, {bool dark = false}) => CupertinoApp(
theme: CupertinoThemeData(
brightness: dark ? Brightness.dark : Brightness.light,
),
home: CupertinoPageScaffold(child: child),
);
StageDefinitionView _view({String key = 'plan'}) => StageDefinitionView(
graph: _graph(),
stageKey: key,
@@ -138,26 +130,6 @@ void main() {
expect(_text('successful'), findsNothing);
});
testWidgets('Cupertino uses its theme roles in dark mode', (tester) async {
late Color secondary;
await tester.pumpWidget(
_cupertino(
Builder(
builder: (context) {
secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
return _view();
},
),
dark: true,
),
);
final identity = tester.widget<Text>(_text('Demo pipeline · v7'));
expect(identity.style?.color, secondary);
expect(_text('Plan the change.'), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('the Material helper opens one bar and Back closes it', (
tester,
) async {
@@ -198,44 +170,6 @@ void main() {
expect(find.byType(StageDefinitionView), findsNothing);
});
testWidgets('the Cupertino helper opens one native bar and Back closes it', (
tester,
) async {
await tester.pumpWidget(
CupertinoApp(
home: Builder(
builder: (context) => CupertinoPageScaffold(
child: CupertinoButton(
onPressed: () => openStageDefinition(
context,
graph: _graph(),
stageKey: '#success',
pipelineId: 41,
pipelineName: 'Demo pipeline',
version: 7,
),
child: const Text('Open terminal'),
),
),
),
),
);
await tester.tap(find.text('Open terminal'));
await tester.pumpAndSettle();
expect(_text('Success definition'), findsOneWidget);
expect(_text('#success definition'), findsNothing);
expect(find.byType(SegmentedBar), findsOneWidget);
expect(find.byType(CupertinoNavigationBarBackButton), findsOneWidget);
expect(_text('Incoming routes'), findsOneWidget);
await tester.tap(find.byType(CupertinoNavigationBarBackButton));
await tester.pumpAndSettle();
expect(_text('Open terminal'), findsOneWidget);
expect(find.byType(StageDefinitionView), findsNothing);
});
testWidgets('the Material helper titles a terminal with its display label', (
tester,
) async {
@@ -270,7 +204,11 @@ void main() {
testWidgets('selectable blocks force the host strut for one line rhythm', (
tester,
) async {
await tester.pumpWidget(_cupertino(_view()));
// Tall enough that the raw section below the prompt is built.
tester.view.physicalSize = const Size(800, 2000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(_material(_view()));
final selectable = tester
.widgetList<SelectableText>(find.byType(SelectableText))
@@ -1,6 +1,5 @@
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';
@@ -45,7 +44,6 @@ void main() {
Future<void> mount(
WidgetTester tester, {
required bool cupertino,
ValueChanged<num>? onSelected,
}) async {
gateway.reply = {
@@ -60,29 +58,24 @@ void main() {
builder: (context, _) =>
RunsList(controller: controller, onSelected: onSelected ?? (_) {}),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: list))
: MaterialApp(home: Scaffold(body: list)),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: list)));
}
testWidgets(
'the filter sheet searches and filters runs',
'filters runs from the filter sheet',
(tester) async {
num? selectedRun;
await mount(
tester,
cupertino: false,
onSelected: (id) => selectedRun = id,
);
await mount(tester, onSelected: (id) => selectedRun = id);
// The text filter lives in the filter sheet.
expect(find.byType(TextField), findsNothing);
expect(find.text('Alpha'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('runs.filter')));
await tester.pumpAndSettle();
await tester.enterText(find.byType(TextField), 'Beta');
await tester.enterText(
find.byKey(const ValueKey('runs.filter.query')),
'Beta',
);
await tester.pumpAndSettle();
await tester.tapAt(const Offset(4, 4));
await tester.pumpAndSettle();
@@ -147,9 +140,9 @@ void main() {
gateway.gate = Completer<void>();
final loading = controller.load();
await tester.pumpWidget(
CupertinoApp(
home: CupertinoPageScaffold(
child: AnimatedBuilder(
MaterialApp(
home: Scaffold(
body: AnimatedBuilder(
animation: controller,
builder: (_, child) =>
RunsList(controller: controller, onSelected: (_) {}),
@@ -158,7 +151,7 @@ void main() {
),
);
await tester.pump();
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
expect(find.byType(CircularProgressIndicator), findsOneWidget);
gateway.gate!.complete();
await loading;
await tester.pumpAndSettle();
@@ -173,49 +166,45 @@ void main() {
expect(find.textContaining('offline'), findsNothing);
expect(tester.takeException(), isNull);
},
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
variant: TargetPlatformVariant.only(TargetPlatform.android),
);
for (final cupertino in [false, true]) {
testWidgets('the attention bell is one of the actions '
'(${cupertino ? 'Cupertino' : 'Material'})', (tester) async {
await mount(tester, cupertino: cupertino);
await tester.pumpAndSettle();
final bell = find.byType(NeedsYouRunsHeading);
expect(bell, findsOneWidget);
// Not in a row of its own: it shares the actions' line, before filter.
final filter = find.byKey(const ValueKey('runs.filter'));
expect(
(tester.getCenter(bell).dy - tester.getCenter(filter).dy).abs(),
lessThan(2),
);
expect(tester.getCenter(bell).dx, lessThan(tester.getCenter(filter).dx));
expect(
find.descendant(of: find.byType(RunsFilters), matching: bell),
findsNothing,
);
expect(tester.takeException(), isNull);
});
}
testWidgets('the attention bell is one of the actions', (tester) async {
await mount(tester);
await tester.pumpAndSettle();
final bell = find.byType(NeedsYouRunsHeading);
expect(bell, findsOneWidget);
// Not in a row of its own: it shares the actions' line, before filter.
final filter = find.byKey(const ValueKey('runs.filter'));
expect(
(tester.getCenter(bell).dy - tester.getCenter(filter).dy).abs(),
lessThan(2),
);
expect(tester.getCenter(bell).dx, lessThan(tester.getCenter(filter).dx));
expect(
find.descendant(of: find.byType(RunsFilters), matching: bell),
findsNothing,
);
expect(tester.takeException(), isNull);
});
for (final cupertino in [false, true]) {
testWidgets('rows lead with the status glyph, not a status word '
'(${cupertino ? 'Cupertino' : 'Material'})', (tester) async {
await mount(tester, cupertino: cupertino);
await tester.pumpAndSettle();
final icons = tester
.widgetList<RunStatusIcon>(find.byType(RunStatusIcon))
.map((icon) => (icon.state, icon.label))
.toList();
expect(
icons,
unorderedEquals([('running', 'running'), ('failed', 'failed')]),
);
expect(find.text('failed'), findsNothing);
expect(
tester.getCenter(find.byType(RunStatusIcon).first).dx,
lessThan(tester.getTopLeft(find.text('Alpha')).dx),
);
});
}
testWidgets('rows lead with the status glyph, not a status word', (
tester,
) async {
await mount(tester);
await tester.pumpAndSettle();
final icons = tester
.widgetList<RunStatusIcon>(find.byType(RunStatusIcon))
.map((icon) => (icon.state, icon.label))
.toList();
expect(
icons,
unorderedEquals([('running', 'running'), ('failed', 'failed')]),
);
expect(find.text('failed'), findsNothing);
expect(
tester.getCenter(find.byType(RunStatusIcon).first).dx,
lessThan(tester.getTopLeft(find.text('Alpha')).dx),
);
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/servers/machine_access.dart';
@@ -64,96 +63,90 @@ Future<void> addServer(
}
void main() {
for (final cupertino in [false, true]) {
testWidgets('a new machine asks for its own password ($cupertino)', (
tester,
) async {
final connections = ServerConnections(
store: MemoryServerCatalogStore(
catalog: ServerCatalog(
servers: [
SavedServer.validated(
id: 'mac',
name: 'Mac',
endpoints: ['ws://10.0.0.75:8083/connect'],
),
],
selectedId: 'mac',
),
testWidgets('a new machine asks for its own password', (tester) async {
final connections = ServerConnections(
store: MemoryServerCatalogStore(
catalog: ServerCatalog(
servers: [
SavedServer.validated(
id: 'mac',
name: 'Mac',
endpoints: ['ws://10.0.0.75:8083/connect'],
),
],
selectedId: 'mac',
),
onSelected: (_) async {},
);
addTearDown(connections.dispose);
await connections.load();
final auth = FakeAuthenticator()
..verdicts['mac'] = const MachineAccessResult(MachineAccess.connected);
connections.authenticator = auth;
final body = SingleChildScrollView(
child: SavedServersSection(connections: connections),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
home: CupertinoPageScaffold(child: SafeArea(child: body)),
)
: MaterialApp(home: Scaffold(body: body)),
);
expect(find.text('Connected'), findsOneWidget);
// The new machine is unknown to the authenticator until saved; a
// password verdict arrives for whatever id the editor assigned.
auth.verdicts.addAll({
for (final id in ['pending']) id: const MachineAccessResult(
MachineAccess.needsPassword,
),
});
await tester.tap(find.text('Add server'));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('server-profile-name')), 'tank');
await tester.enterText(
find.byKey(const Key('server-profile-addresses')),
'ws://10.0.0.100:8082/connect',
);
// Whatever id the editor chose, that machine wants a password.
connections.addListener(() {
for (final server in connections.catalog.servers) {
auth.verdicts.putIfAbsent(
server.id,
() => const MachineAccessResult(MachineAccess.needsPassword),
);
auth.passwords.putIfAbsent(server.id, () => 'tank-secret');
}
});
await revealSave(tester);
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
final tank = connections.catalog.servers.firstWhere((s) => s.name == 'tank');
expect(auth.probes, [tank.id]);
// Saved, and the editor now asks this machine's password; the first
// machine's sign-in is not reused.
expect(find.byKey(const Key('server-profile-password')), findsOneWidget);
expect(find.textContaining('asks for its own password'), findsOneWidget);
await tester.enterText(
find.byKey(const Key('server-profile-password')),
'wrong',
);
await tester.tap(find.byKey(const Key('server-profile-sign-in')));
await tester.pumpAndSettle();
expect(find.text('Wrong password.'), findsOneWidget);
expect(find.byKey(const Key('server-profile-password')), findsOneWidget);
await tester.enterText(
find.byKey(const Key('server-profile-password')),
'tank-secret',
);
await tester.tap(find.byKey(const Key('server-profile-sign-in')));
await tester.pumpAndSettle();
expect(auth.signIns, [(tank.id, 'wrong'), (tank.id, 'tank-secret')]);
// Back on the list: both machines connected, each on its own sign-in.
expect(find.byKey(const Key('server-profile-password')), findsNothing);
expect(find.text('Connected'), findsNWidgets(2));
expect(find.text('Address: ws://10.0.0.100:8082/connect'), findsOneWidget);
expect(connections.catalog.active?.id, 'mac');
),
onSelected: (_) async {},
);
addTearDown(connections.dispose);
await connections.load();
final auth = FakeAuthenticator()
..verdicts['mac'] = const MachineAccessResult(MachineAccess.connected);
connections.authenticator = auth;
final body = SingleChildScrollView(
child: SavedServersSection(connections: connections),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: body)));
expect(find.text('Connected'), findsOneWidget);
// The new machine is unknown to the authenticator until saved; a
// password verdict arrives for whatever id the editor assigned.
auth.verdicts.addAll({
for (final id in ['pending'])
id: const MachineAccessResult(MachineAccess.needsPassword),
});
}
await tester.tap(find.text('Add server'));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('server-profile-name')),
'tank',
);
await tester.enterText(
find.byKey(const Key('server-profile-addresses')),
'ws://10.0.0.100:8082/connect',
);
// Whatever id the editor chose, that machine wants a password.
connections.addListener(() {
for (final server in connections.catalog.servers) {
auth.verdicts.putIfAbsent(
server.id,
() => const MachineAccessResult(MachineAccess.needsPassword),
);
auth.passwords.putIfAbsent(server.id, () => 'tank-secret');
}
});
await revealSave(tester);
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
final tank = connections.catalog.servers.firstWhere(
(s) => s.name == 'tank',
);
expect(auth.probes, [tank.id]);
// Saved, and the editor now asks this machine's password; the first
// machine's sign-in is not reused.
expect(find.byKey(const Key('server-profile-password')), findsOneWidget);
expect(find.textContaining('asks for its own password'), findsOneWidget);
await tester.enterText(
find.byKey(const Key('server-profile-password')),
'wrong',
);
await tester.tap(find.byKey(const Key('server-profile-sign-in')));
await tester.pumpAndSettle();
expect(find.text('Wrong password.'), findsOneWidget);
expect(find.byKey(const Key('server-profile-password')), findsOneWidget);
await tester.enterText(
find.byKey(const Key('server-profile-password')),
'tank-secret',
);
await tester.tap(find.byKey(const Key('server-profile-sign-in')));
await tester.pumpAndSettle();
expect(auth.signIns, [(tank.id, 'wrong'), (tank.id, 'tank-secret')]);
// Back on the list: both machines connected, each on its own sign-in.
expect(find.byKey(const Key('server-profile-password')), findsNothing);
expect(find.text('Connected'), findsNWidgets(2));
expect(find.text('Address: ws://10.0.0.100:8082/connect'), findsOneWidget);
expect(connections.catalog.active?.id, 'mac');
});
testWidgets('an unreachable machine stays saved with the reason shown', (
tester,
@@ -172,7 +165,8 @@ void main() {
server.id,
() => const MachineAccessResult(
MachineAccess.unreachable,
detail: 'The HTTPS certificate of 100.85.25.33:8443 does not '
detail:
'The HTTPS certificate of 100.85.25.33:8443 does not '
'cover an IP address.',
),
);
@@ -198,7 +192,10 @@ void main() {
await tester.tap(find.byKey(const Key('server-sign-in-later')));
await tester.pumpAndSettle();
expect(connections.catalog.servers.single.name, 'Mac by IP');
expect(find.textContaining('Unreachable: The HTTPS certificate'), findsOneWidget);
expect(
find.textContaining('Unreachable: The HTTPS certificate'),
findsOneWidget,
);
});
testWidgets('a saved machine that wants a password offers Sign in', (
@@ -218,7 +215,9 @@ void main() {
addTearDown(connections.dispose);
await connections.load();
final auth = FakeAuthenticator()
..verdicts['tank'] = const MachineAccessResult(MachineAccess.needsPassword)
..verdicts['tank'] = const MachineAccessResult(
MachineAccess.needsPassword,
)
..passwords['tank'] = 'tank-secret';
connections.authenticator = auth;
await tester.pumpWidget(
@@ -231,7 +230,10 @@ void main() {
await tester.pumpAndSettle();
await tester.tap(find.text('Sign in to tank'));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('machine-password')), 'tank-secret');
await tester.enterText(
find.byKey(const Key('machine-password')),
'tank-secret',
);
await tester.tap(find.byKey(const Key('machine-sign-in')));
await tester.pumpAndSettle();
expect(auth.signIns, [('tank', 'tank-secret')]);
@@ -248,7 +250,9 @@ void main() {
endpoints: ['ws://10.0.0.75:8083/connect'],
);
final auth = FakeAuthenticator()
..verdicts['mac'] = const MachineAccessResult(MachineAccess.needsPassword);
..verdicts['mac'] = const MachineAccessResult(
MachineAccess.needsPassword,
);
SavedServer? saved;
await tester.pumpWidget(
MaterialApp(
@@ -269,7 +273,10 @@ void main() {
);
await tester.tap(find.text('Edit'));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('server-profile-name')), 'Studio');
await tester.enterText(
find.byKey(const Key('server-profile-name')),
'Studio',
);
await revealSave(tester);
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/settings/storage/storage_screen.dart';
@@ -7,8 +6,7 @@ import '../../../../tool/storage_probe_fixture.dart';
Future<void> _mount(
WidgetTester tester,
StorageProbeGateway gateway,
bool cupertino, {
StorageProbeGateway gateway, {
double width = 900,
double scale = 1,
}) async {
@@ -20,11 +18,7 @@ Future<void> _mount(
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(scale)),
child: child!,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(builder: builder, home: screen)
: MaterialApp(builder: builder, home: screen),
);
await tester.pumpWidget(MaterialApp(builder: builder, home: screen));
await tester.pumpAndSettle();
}
@@ -43,83 +37,72 @@ Finder _field(String label) => find.descendant(
matching: find.byType(EditableText),
);
void main() {
for (final cupertino in [false, true]) {
final style = cupertino ? 'Cupertino' : 'Material';
testWidgets(
'$style usage and partial measurement remain honest at 2x narrow',
(tester) async {
final gateway = StorageProbeGateway();
await _mount(tester, gateway, cupertino, width: 560, scale: 2);
expect(find.text('At least 15.0 GiB used'), findsOneWidget);
expect(
find.text('Measurement is incomplete. See details below.'),
findsOneWidget,
);
expect(find.text('Database'), findsOneWidget);
expect(find.textContaining('6 November 2026'), findsOneWidget);
expect(find.text('Worktrees'), findsOneWidget);
await _tap(tester, 'Preview cleanup');
expect(find.text('Cleanup preview'), findsOneWidget);
expect(
find.text('Protected · worktree active-item · 4.00 GiB'),
findsOneWidget,
);
expect(tester.takeException(), isNull);
},
testWidgets('usage and partial measurement remain honest at 2x narrow', (
tester,
) async {
final gateway = StorageProbeGateway();
await _mount(tester, gateway, width: 560, scale: 2);
expect(find.text('At least 15.0 GiB used'), findsOneWidget);
expect(
find.text('Measurement is incomplete. See details below.'),
findsOneWidget,
);
testWidgets(
'$style cleanup cancellation does not mutate and confirmation uses token',
(tester) async {
final gateway = StorageProbeGateway();
await _mount(tester, gateway, cupertino);
await _tap(tester, 'Preview cleanup');
await _tap(tester, 'Apply cleanup');
expect(find.text('Apply cleanup?'), findsOneWidget);
await _tap(tester, 'Cancel');
expect(
gateway.calls.where((call) => call.type == 'apply_storage_cleanup'),
isEmpty,
);
await _tap(tester, 'Apply cleanup');
await _tap(tester, 'Remove items');
expect(
gateway.calls
.singleWhere((call) => call.type == 'apply_storage_cleanup')
.fields['storage_cleanup_token'],
'fixture-preview-token',
);
expect(find.text('Cleanup result'), findsOneWidget);
expect(
find.text('Worktree became active and was kept.'),
findsOneWidget,
);
expect(tester.takeException(), isNull);
},
expect(find.text('Database'), findsOneWidget);
expect(find.textContaining('6 November 2026'), findsOneWidget);
expect(find.text('Worktrees'), findsOneWidget);
await _tap(tester, 'Preview cleanup');
expect(find.text('Cleanup preview'), findsOneWidget);
expect(
find.text('Protected · worktree active-item · 4.00 GiB'),
findsOneWidget,
);
testWidgets('$style invalid limits do not send a policy', (tester) async {
expect(tester.takeException(), isNull);
});
testWidgets(
'cleanup cancellation does not mutate and confirmation uses token',
(tester) async {
final gateway = StorageProbeGateway();
await _mount(tester, gateway, cupertino);
await tester.ensureVisible(_field('Retain data for days'));
await tester.enterText(_field('Retain data for days'), '-1');
await _tap(tester, 'Save policy');
await _mount(tester, gateway);
await _tap(tester, 'Preview cleanup');
await _tap(tester, 'Apply cleanup');
expect(find.text('Apply cleanup?'), findsOneWidget);
await _tap(tester, 'Cancel');
expect(
find.textContaining('Enter a whole number of days'),
findsOneWidget,
);
expect(
gateway.calls.where((call) => call.type == 'set_storage_policy'),
gateway.calls.where((call) => call.type == 'apply_storage_cleanup'),
isEmpty,
);
});
testWidgets(
'$style unsupported server has an actionable error and no fake usage',
(tester) async {
final gateway = StorageProbeGateway()..unsupported = true;
await _mount(tester, gateway, cupertino);
expect(find.text('Unknown command: get_storage'), findsOneWidget);
expect(find.text('Server storage'), findsNothing);
expect(find.text('Refresh storage'), findsOneWidget);
},
await _tap(tester, 'Apply cleanup');
await _tap(tester, 'Remove items');
expect(
gateway.calls
.singleWhere((call) => call.type == 'apply_storage_cleanup')
.fields['storage_cleanup_token'],
'fixture-preview-token',
);
expect(find.text('Cleanup result'), findsOneWidget);
expect(find.text('Worktree became active and was kept.'), findsOneWidget);
expect(tester.takeException(), isNull);
},
);
testWidgets('invalid limits do not send a policy', (tester) async {
final gateway = StorageProbeGateway();
await _mount(tester, gateway);
await tester.ensureVisible(_field('Retain data for days'));
await tester.enterText(_field('Retain data for days'), '-1');
await _tap(tester, 'Save policy');
expect(find.textContaining('Enter a whole number of days'), findsOneWidget);
expect(
gateway.calls.where((call) => call.type == 'set_storage_policy'),
isEmpty,
);
}
});
testWidgets('unsupported server has an actionable error and no fake usage', (
tester,
) async {
final gateway = StorageProbeGateway()..unsupported = true;
await _mount(tester, gateway);
expect(find.text('Unknown command: get_storage'), findsOneWidget);
expect(find.text('Server storage'), findsNothing);
expect(find.text('Refresh storage'), findsOneWidget);
});
}