Merge main into pipelines/run-20261111-0456-cupertino-out-runs-ui-part-1-2ad5

This commit is contained in:
2026-11-11 05:13:28 +00:00
56 changed files with 1177 additions and 2822 deletions
@@ -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/application/pipelines_app.dart';
@@ -12,83 +11,66 @@ import 'pipelines_replies.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
void main() {
for (final cupertino in [false, true]) {
testWidgets(
'the /pipelines route renders real rows, detail and source ($cupertino)',
(tester) async {
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
if (cupertino) {
tester.platformDispatcher.platformBrightnessTestValue =
Brightness.dark;
addTearDown(
tester.platformDispatcher.clearPlatformBrightnessTestValue,
);
}
testWidgets('the /pipelines route renders real rows, detail and source', (
tester,
) async {
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final fixture = PipelineFixture();
final channel = FakeChannel()..readyCompleter.complete();
var sockets = 0;
final client = PipelinesClient(
channelFactory: (_) {
sockets++;
return channel;
},
);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(
uri: Uri.parse('/pipelines'),
),
);
addTearDown(provider.dispose);
await tester.pumpWidget(
PipelinesApp(
server: webServer(),
client: client,
cupertino: cupertino,
routeInformationProvider: provider,
),
);
await tester.pump();
await replyPipelines(tester, channel, fixture);
await tester.pump();
expect(find.text('Alpha review'), findsOneWidget);
expect(find.text('2 stages · 1 schedule'), findsOneWidget);
expect(find.text('Pipelines — Not implemented'), findsNothing);
expect(sockets, 1);
// The shell owns the only navigation bar; the embedded screen adds no
// second bar.
expect(find.byType(SegmentedBar), findsOneWidget);
if (cupertino) {
expect(find.byType(CupertinoPageScaffold), findsOneWidget);
expect(find.byType(Material), findsNothing);
} else {
expect(find.byType(Scaffold), findsOneWidget);
}
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pump();
await replyPipelineDetail(tester, channel, fixture);
await tester.pump();
expect(find.text('hash-alpha'), findsOneWidget);
await tester.tap(find.byKey(const Key('pipeline-detail-tab-source')));
await tester.pump();
expect(
selectableText(
'name: Alpha review\nstages:\n review:\n type: model',
),
findsOneWidget,
);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
final fixture = PipelineFixture();
final channel = FakeChannel()..readyCompleter.complete();
var sockets = 0;
final client = PipelinesClient(
channelFactory: (_) {
sockets++;
return channel;
},
);
}
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')),
);
addTearDown(provider.dispose);
await tester.pumpWidget(
PipelinesApp(
server: webServer(),
client: client,
cupertino: false,
routeInformationProvider: provider,
),
);
await tester.pump();
await replyPipelines(tester, channel, fixture);
await tester.pump();
expect(find.text('Alpha review'), findsOneWidget);
expect(find.text('2 stages · 1 schedule'), findsOneWidget);
expect(find.text('Pipelines — Not implemented'), findsNothing);
expect(sockets, 1);
// The shell owns the only navigation bar; the embedded screen adds no
// second bar.
expect(find.byType(SegmentedBar), findsOneWidget);
expect(find.byType(Scaffold), findsOneWidget);
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pump();
await replyPipelineDetail(tester, channel, fixture);
await tester.pump();
expect(find.text('hash-alpha'), findsOneWidget);
await tester.tap(find.byKey(const Key('pipeline-detail-tab-source')));
await tester.pump();
expect(
selectableText(
'name: Alpha review\nstages:\n review:\n type: model',
),
findsOneWidget,
);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
}
+59 -66
View File
@@ -1,5 +1,4 @@
import '../features/settings/settings_topic_test_helper.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/pipelines_app.dart';
@@ -20,7 +19,6 @@ import 'pipelines_replies.dart';
void main() {
Future<PlatformRouteInformationProvider> pumpApp(
WidgetTester tester, {
required bool cupertino,
required String location,
required Size size,
}) async {
@@ -37,7 +35,7 @@ void main() {
PipelinesApp(
server: webServer(),
client: PipelinesClient(channelFactory: (_) => channel),
cupertino: cupertino,
cupertino: false,
routeInformationProvider: provider,
),
);
@@ -52,82 +50,77 @@ void main() {
.widget<FloatingDestinationBar>(find.byType(FloatingDestinationBar))
.currentIndex;
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
for (final size in [const Size(390, 844), const Size(1200, 800)]) {
testWidgets('$host ${size.width}: the Pipelines bar gear opens Settings '
'as a page and Back returns', (tester) async {
final provider = await pumpApp(
tester,
cupertino: cupertino,
location: '/pipelines',
size: size,
);
// Four tabs; Settings is none of them.
expect(
tester
.widget<FloatingDestinationBar>(
find.byType(FloatingDestinationBar),
)
.items
.map((item) => item.label),
['Pipelines', 'Runs', 'Chat', 'Search'],
);
expect(
find.byKey(const ValueKey('shell.destination.settings')),
findsNothing,
);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
await tapBarAction(
tester,
find.byKey(const Key('pipelines-open-settings')),
'Settings',
);
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/settings');
expect(find.byType(SettingsScreen), findsOneWidget);
expect(find.text('Quick switch animation'), findsOneWidget);
await selectSettingsTopic(tester, 'Connection');
expect(find.text('Server URL'), findsOneWidget);
// A page of Pipelines: Back in its bar, Pipelines still selected.
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
expect(find.byKey(const ValueKey('shell.search')), findsNothing);
expect(selectedTab(tester), 0);
expect(tester.takeException(), isNull);
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/pipelines');
expect(find.byKey(const Key('pipelines-open-settings')), findsWidgets);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
}
testWidgets('$host: the /settings deep link opens the Settings page and '
'the system Back closes it to Pipelines', (tester) async {
for (final size in [const Size(390, 844), const Size(1200, 800)]) {
testWidgets('${size.width}: the Pipelines bar gear opens Settings '
'as a page and Back returns', (tester) async {
final provider = await pumpApp(
tester,
cupertino: cupertino,
location: '/settings',
size: const Size(390, 844),
location: '/pipelines',
size: size,
);
// Four tabs; Settings is none of them.
expect(
tester
.widget<FloatingDestinationBar>(
find.byType(FloatingDestinationBar),
)
.items
.map((item) => item.label),
['Pipelines', 'Runs', 'Chat', 'Search'],
);
expect(
find.byKey(const ValueKey('shell.destination.settings')),
findsNothing,
);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
await tapBarAction(
tester,
find.byKey(const Key('pipelines-open-settings')),
'Settings',
);
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/settings');
expect(find.byType(SettingsScreen), findsOneWidget);
expect(find.text('Quick switch animation'), findsOneWidget);
await selectSettingsTopic(tester, 'Connection');
expect(find.text('Server URL'), findsOneWidget);
// A page of Pipelines: Back in its bar, Pipelines still selected.
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
expect(find.byKey(const ValueKey('shell.search')), findsNothing);
expect(selectedTab(tester), 0);
expect(tester.takeException(), isNull);
final handled = await tester.binding.handlePopRoute();
expect(handled, isTrue, reason: 'Back closes the page, not the app');
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/pipelines');
expect(find.byKey(const Key('pipelines-open-settings')), findsWidgets);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
}
testWidgets('the /settings deep link opens the Settings page and '
'the system Back closes it to Pipelines', (tester) async {
final provider = await pumpApp(
tester,
location: '/settings',
size: const Size(390, 844),
);
await tester.pump();
expect(find.byType(SettingsScreen), findsOneWidget);
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
expect(selectedTab(tester), 0);
final handled = await tester.binding.handlePopRoute();
expect(handled, isTrue, reason: 'Back closes the page, not the app');
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/pipelines');
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
}
@@ -1,7 +1,6 @@
import '../features/settings/settings_topic_test_helper.dart';
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/pipelines_app.dart';
@@ -16,89 +15,73 @@ import 'pipelines_replies.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
void main() {
for (final cupertino in [false, true]) {
testWidgets('Settings shares socket and one native bar ($cupertino)', (
tester,
) async {
SharedPreferences.setMockInitialValues({});
if (cupertino) {
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
}
final channel = FakeChannel()..readyCompleter.complete();
var sockets = 0;
final client = PipelinesClient(
channelFactory: (_) {
sockets++;
return channel;
},
);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')),
);
addTearDown(provider.dispose);
await tester.pumpWidget(
PipelinesApp(
server: webServer(),
client: client,
cupertino: cupertino,
routeInformationProvider: provider,
),
);
await tester.pump();
expect(
requestOf(channel, 'ping'),
isNull,
reason: 'Unvisited settings must not issue hidden requests',
);
await replyPipelines(tester, channel, PipelineFixture());
testWidgets('Settings shares socket and one native bar', (tester) async {
SharedPreferences.setMockInitialValues({});
final channel = FakeChannel()..readyCompleter.complete();
var sockets = 0;
final client = PipelinesClient(
channelFactory: (_) {
sockets++;
return channel;
},
);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')),
);
addTearDown(provider.dispose);
await tester.pumpWidget(
PipelinesApp(
server: webServer(),
client: client,
cupertino: false,
routeInformationProvider: provider,
),
);
await tester.pump();
expect(
requestOf(channel, 'ping'),
isNull,
reason: 'Unvisited settings must not issue hidden requests',
);
await replyPipelines(tester, channel, PipelineFixture());
await tapBarAction(
tester,
find.byKey(const Key('pipelines-open-settings')),
'Settings',
);
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/settings');
expect(find.text('Quick switch animation'), findsOneWidget);
await selectSettingsTopic(tester, 'Connection');
expect(find.text('Server URL'), findsOneWidget);
if (cupertino) {
final title = tester.widget<Text>(find.text('Connection').last);
expect(
title.style!.color!.computeLuminance(),
greaterThan(0.5),
reason: 'Cupertino dark host must not inherit light Material text',
);
}
expect(find.text('Settings — Not implemented'), findsNothing);
expect(sockets, 1);
expect(find.byType(SegmentedBar), findsOneWidget);
final ping = requestOf(channel, 'ping')!;
channel.incoming.add(
jsonEncode({
'id': ping['id'],
'type': 'pong',
'build': {'version': 'settings-fixture'},
'time': 'fixture time',
'protocol': 2,
}),
);
await tester.pump();
await tester.pump();
expect(find.textContaining('settings-fixture'), findsOneWidget);
expect(
find.text(
'Protocol mismatch: this page speaks protocol 1, '
'the server reports 2.',
),
findsOneWidget,
reason: 'a mismatched server must stay visibly flagged in Settings',
);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
}
await tapBarAction(
tester,
find.byKey(const Key('pipelines-open-settings')),
'Settings',
);
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/settings');
expect(find.text('Quick switch animation'), findsOneWidget);
await selectSettingsTopic(tester, 'Connection');
expect(find.text('Server URL'), findsOneWidget);
expect(find.text('Settings — Not implemented'), findsNothing);
expect(sockets, 1);
expect(find.byType(SegmentedBar), findsOneWidget);
final ping = requestOf(channel, 'ping')!;
channel.incoming.add(
jsonEncode({
'id': ping['id'],
'type': 'pong',
'build': {'version': 'settings-fixture'},
'time': 'fixture time',
'protocol': 2,
}),
);
await tester.pump();
await tester.pump();
expect(find.textContaining('settings-fixture'), findsOneWidget);
expect(
find.text(
'Protocol mismatch: this page speaks protocol 1, '
'the server reports 2.',
),
findsOneWidget,
reason: 'a mismatched server must stay visibly flagged in Settings',
);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
}
@@ -22,7 +22,6 @@ Future<({PlatformRouteInformationProvider provider, FakeChannel channel})>
mount(
WidgetTester tester, {
String route = '/pipelines',
bool cupertino = false,
TabLocationsStore? store,
}) async {
tester.view.physicalSize = const Size(560, 1000);
@@ -39,7 +38,7 @@ mount(
PipelinesApp(
server: webServer(),
client: client,
cupertino: cupertino,
cupertino: false,
serverId: 'navigation-test',
routeInformationProvider: provider,
tabLocationsStore: store,
@@ -58,44 +57,41 @@ Future<void> tab(WidgetTester tester, String name) async {
void main() {
setUp(() => SharedPreferences.setMockInitialValues({}));
for (final cupertino in [false, true]) {
testWidgets(
'Settings is retained inside Pipelines across tab switches ($cupertino)',
(tester) async {
final app = await mount(tester, cupertino: cupertino);
await replyPipelines(tester, app.channel, PipelineFixture());
await tester.pumpAndSettle();
await tapBarAction(
tester,
find.byKey(const Key('pipelines-open-settings')),
'Settings',
);
await tester.pumpAndSettle();
expect(app.provider.value.uri.path, '/settings');
final settingsState = tester.state(find.byType(SettingsScreen));
await tab(tester, 'chat');
expect(app.provider.value.uri.path, '/chat');
await tab(tester, 'pipelines');
expect(app.provider.value.uri.path, '/settings');
expect(tester.state(find.byType(SettingsScreen)), same(settingsState));
await tab(tester, 'pipelines');
expect(
app.provider.value.uri.path,
'/settings',
reason: 'tab retap is not Back',
);
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(
app.provider.value.uri.path,
'/pipelines',
reason: 'explicit Back still exits Settings',
);
expect(tester.takeException(), isNull);
},
testWidgets('Settings is retained inside Pipelines across tab switches', (
tester,
) async {
final app = await mount(tester);
await replyPipelines(tester, app.channel, PipelineFixture());
await tester.pumpAndSettle();
await tapBarAction(
tester,
find.byKey(const Key('pipelines-open-settings')),
'Settings',
);
}
await tester.pumpAndSettle();
expect(app.provider.value.uri.path, '/settings');
final settingsState = tester.state(find.byType(SettingsScreen));
await tab(tester, 'chat');
expect(app.provider.value.uri.path, '/chat');
await tab(tester, 'pipelines');
expect(app.provider.value.uri.path, '/settings');
expect(tester.state(find.byType(SettingsScreen)), same(settingsState));
await tab(tester, 'pipelines');
expect(
app.provider.value.uri.path,
'/settings',
reason: 'tab retap is not Back',
);
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(
app.provider.value.uri.path,
'/pipelines',
reason: 'explicit Back still exits Settings',
);
expect(tester.takeException(), isNull);
});
testWidgets(
'per-tab locations survive app recreation; an explicit deep link wins',
(tester) async {
@@ -209,24 +205,19 @@ void main() {
);
expect(tester.takeException(), isNull);
});
for (final cupertino in [false, true]) {
testWidgets('ordinary root with query restores its tab ($cupertino)', (
tester,
) async {
final store = MemoryTabLocationsStore()
..value = const TabLocationsSnapshot(
routes: {AppDestination.pipelines: AppRoute.settings},
);
final app = await mount(
tester,
route: '/?appearance=cupertino',
cupertino: cupertino,
store: store,
testWidgets('ordinary root with query restores its tab', (tester) async {
final store = MemoryTabLocationsStore()
..value = const TabLocationsSnapshot(
routes: {AppDestination.pipelines: AppRoute.settings},
);
await tester.pumpAndSettle();
expect(app.provider.value.uri.path, '/settings');
expect(find.byType(SettingsScreen), findsOneWidget);
expect(tester.takeException(), isNull);
});
}
final app = await mount(
tester,
route: '/?appearance=cupertino',
store: store,
);
await tester.pumpAndSettle();
expect(app.provider.value.uri.path, '/settings');
expect(find.byType(SettingsScreen), findsOneWidget);
expect(tester.takeException(), isNull);
});
}
@@ -1,5 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
@@ -52,19 +50,13 @@ FakeGateway archiveGateway(PipelineFixture fixture, {String? refusal}) {
});
}
Future<void> pump(
WidgetTester tester,
FakeGateway gateway, {
bool cupertino = false,
}) async {
Future<void> pump(WidgetTester tester, FakeGateway gateway) async {
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final screen = PipelinesScreen(gateway: gateway);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen),
);
await tester.pumpWidget(MaterialApp(home: screen));
await tester.pumpAndSettle();
}
@@ -161,24 +153,4 @@ void main() {
await tester.pumpAndSettle();
expect(rowNamed('Alpha review'), findsOneWidget);
});
testWidgets('Cupertino archives through the action sheet and alert', (
tester,
) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
try {
final gateway = archiveGateway(PipelineFixture());
await pump(tester, gateway, cupertino: true);
await tester.tap(rowNamed('Beta deploy'));
await tester.pumpAndSettle();
await openMenuItem(tester, 'pipeline-archive');
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
await tester.tap(find.byKey(const Key('pipeline-archive-confirm')));
await tester.pumpAndSettle();
expect(gateway.callsOf('archive_pipeline'), hasLength(1));
expect(rowNamed('Beta deploy'), findsNothing);
} finally {
debugDefaultTargetPlatformOverride = null;
}
});
}
@@ -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';
@@ -21,44 +20,31 @@ class _Gateway implements ApiGateway {
Stream<JsonMap> get frames => const Stream.empty();
}
Widget _host(
_Gateway gateway, {
bool cupertino = false,
String source = '# stage build',
}) {
Widget _host(_Gateway gateway, {String source = '# stage build'}) {
final body = Column(
children: [
const Text('Pipeline source remains available'),
PipelineDefinitionValidation(gateway: gateway, source: source),
],
);
return cupertino
? CupertinoApp(
home: CupertinoPageScaffold(child: SafeArea(child: body)),
)
: MaterialApp(home: Scaffold(body: body));
return MaterialApp(home: Scaffold(body: body));
}
void main() {
for (final cupertino in [false, true]) {
testWidgets(
'definition warnings stay visible on ${cupertino ? 'Cupertino' : 'Material'}',
(tester) async {
final gateway = _Gateway()
..answer = () async => {
'type': 'validated',
'warnings': ['Review prompt exceeds 2000 bytes.', '', 42],
};
await tester.pumpWidget(_host(gateway, cupertino: cupertino));
await tester.pumpAndSettle();
expect(find.text('Definition warnings'), findsOneWidget);
expect(find.text('Review prompt exceeds 2000 bytes.'), findsOneWidget);
expect(find.text('42'), findsNothing);
expect(gateway.calls.single, {'source': '# stage build'});
expect(tester.takeException(), isNull);
},
);
}
testWidgets('definition warnings stay visible', (tester) async {
final gateway = _Gateway()
..answer = () async => {
'type': 'validated',
'warnings': ['Review prompt exceeds 2000 bytes.', '', 42],
};
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(find.text('Definition warnings'), findsOneWidget);
expect(find.text('Review prompt exceeds 2000 bytes.'), findsOneWidget);
expect(find.text('42'), findsNothing);
expect(gateway.calls.single, {'source': '# stage build'});
expect(tester.takeException(), isNull);
});
testWidgets(
'loading validation never hides detail and a source is checked once',
@@ -1,7 +1,5 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/layout/app_list_row.dart';
@@ -211,34 +209,4 @@ void main() {
);
expect(tester.takeException(), isNull);
});
testWidgets('Cupertino keeps the shared row with the same row identity', (
tester,
) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
try {
await tester.pumpWidget(
CupertinoApp(
home: PipelinesScreen(gateway: gatewayFor(PipelineFixture())),
),
);
await tester.pumpAndSettle();
expect(
tester
.widget<AppListRow>(find.byKey(const Key('pipeline-row-1')))
.cupertino,
isTrue,
);
expect(find.text('2 stages · 1 schedule'), findsOneWidget);
expect(find.textContaining('v2 · #'), findsNothing);
expect(find.byKey(const Key('pipeline-avatar-1')), findsOneWidget);
expect(find.byKey(const Key('pipeline-status-1')), findsOneWidget);
} finally {
debugDefaultTargetPlatformOverride = null;
}
});
}
@@ -1,45 +1,35 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_scope_control.dart';
void main() {
for (final cupertino in [false, true]) {
for (final width in [120.0, 500.0]) {
testWidgets(
'native scope remains usable at $width, Cupertino=$cupertino',
(tester) async {
var scope = PipelineScope.all;
final control = StatefulBuilder(
builder: (context, setState) => Center(
child: SizedBox(
width: width,
child: PipelineScopeControl(
scope: scope,
onSelected: (value) => setState(() => scope = value),
),
),
for (final width in [120.0, 500.0]) {
testWidgets('native scope remains usable at $width', (tester) async {
var scope = PipelineScope.all;
final control = StatefulBuilder(
builder: (context, setState) => Center(
child: SizedBox(
width: width,
child: PipelineScopeControl(
scope: scope,
onSelected: (value) => setState(() => scope = value),
),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: control))
: MaterialApp(home: Scaffold(body: control)),
);
await tester.pumpAndSettle();
if (width == 120) {
await tester.tap(find.byKey(const Key('pipeline-scope')));
await tester.pumpAndSettle();
await tester.tap(find.text('Scheduled').last);
} else {
await tester.tap(find.text('Scheduled'));
}
await tester.pumpAndSettle();
expect(scope, PipelineScope.scheduled);
expect(tester.takeException(), isNull);
},
),
),
);
}
await tester.pumpWidget(MaterialApp(home: Scaffold(body: control)));
await tester.pumpAndSettle();
if (width == 120) {
await tester.tap(find.byKey(const Key('pipeline-scope')));
await tester.pumpAndSettle();
await tester.tap(find.text('Scheduled').last);
} else {
await tester.tap(find.text('Scheduled'));
}
await tester.pumpAndSettle();
expect(scope, PipelineScope.scheduled);
expect(tester.takeException(), isNull);
});
}
testWidgets('wide scope control hugs its labels', (tester) async {
@@ -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/pipelines/screen.dart';
@@ -8,68 +7,62 @@ import 'package:pipelines_app/ui/layout/app_list_row.dart';
import 'fixtures.dart';
/// The pipeline Summary is flat on both hosts: facts in the shared grid,
/// Schedules with Add as its heading's only action (no body Refresh), and
/// versions as the shared list row.
/// The pipeline Summary is flat: facts in the shared grid, Schedules with Add
/// as its heading's only action (no body Refresh), and versions as the shared
/// list row.
void main() {
for (final cupertino in [false, true]) {
testWidgets('pipeline Summary is a facts grid with flat sections '
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
final gateway = FakeGateway((type, fields) {
return switch (type) {
'list_pipelines' => pipelineListReply([
pipelineSummary(id: 1, name: 'Alpha review', version: 3),
]),
'list_runs' => runListReply([]),
'get_pipeline' => pipelineDetailReply(
pipelineDetail(
id: 1,
name: 'Alpha review',
version: 3,
latestVersion: 3,
versions: [versionSummary(2), versionSummary(3)],
),
testWidgets('pipeline Summary is a facts grid with flat sections', (
tester,
) async {
final gateway = FakeGateway((type, fields) {
return switch (type) {
'list_pipelines' => pipelineListReply([
pipelineSummary(id: 1, name: 'Alpha review', version: 3),
]),
'list_runs' => runListReply([]),
'get_pipeline' => pipelineDetailReply(
pipelineDetail(
id: 1,
name: 'Alpha review',
version: 3,
latestVersion: 3,
versions: [versionSummary(2), versionSummary(3)],
),
'list_schedules' => {'type': 'schedules', 'schedules': <dynamic>[]},
_ => errorReply('unexpected $type'),
};
});
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final screen = PipelinesScreen(gateway: gateway);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: screen))
: MaterialApp(home: screen),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pumpAndSettle();
expect(find.byKey(pipelineSummaryFactsKey), findsOneWidget);
// Short facts share a line instead of one label/value row each.
final latest = tester.getRect(
find.byKey(const ValueKey('pipeline-summary-latest-version')),
);
final versionCreated = tester.getRect(
find.byKey(const ValueKey('pipeline-summary-version-created')),
);
expect(versionCreated.top, moreOrLessEquals(latest.top));
expect(versionCreated.left, greaterThan(latest.right));
expect(find.text('Refresh'), findsNothing);
expect(find.text(scheduleAddLabel), findsNothing);
expect(find.byKey(scheduleAddKey), findsOneWidget);
expect(find.byType(CupertinoListSection), findsNothing);
expect(find.byType(ListTile), findsNothing);
final row = tester.widget<AppListRow>(
find.byKey(const Key('pipeline-version-3')),
);
expect(row.selected, isTrue);
expect(row.cupertino, cupertino);
expect(tester.takeException(), isNull);
),
'list_schedules' => {'type': 'schedules', 'schedules': <dynamic>[]},
_ => errorReply('unexpected $type'),
};
});
}
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final screen = PipelinesScreen(gateway: gateway);
await tester.pumpWidget(MaterialApp(home: screen));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pumpAndSettle();
expect(find.byKey(pipelineSummaryFactsKey), findsOneWidget);
// Short facts share a line instead of one label/value row each.
final latest = tester.getRect(
find.byKey(const ValueKey('pipeline-summary-latest-version')),
);
final versionCreated = tester.getRect(
find.byKey(const ValueKey('pipeline-summary-version-created')),
);
expect(versionCreated.top, moreOrLessEquals(latest.top));
expect(versionCreated.left, greaterThan(latest.right));
expect(find.text('Refresh'), findsNothing);
expect(find.text(scheduleAddLabel), findsNothing);
expect(find.byKey(scheduleAddKey), findsOneWidget);
expect(find.byType(ListTile), findsNothing);
final row = tester.widget<AppListRow>(
find.byKey(const Key('pipeline-version-3')),
);
expect(row.selected, isTrue);
expect(row.cupertino, isFalse);
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:pipelines_app/features/pipelines/widgets/pipeline_tabs.dart';
@@ -26,64 +25,52 @@ void main() {
);
});
for (final cupertino in [false, true]) {
for (final width in [320.0, 390.0, 720.0, 1200.0]) {
testWidgets('floating tabs at $width, 2x, Cupertino=$cupertino', (
tester,
) async {
tester.view.physicalSize = Size(width, 640);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
PipelineDetailTab? selected;
final body = Align(
alignment: Alignment.bottomCenter,
child: PipelineDetailTabs(
selected: PipelineDetailTab.summary,
onSelected: (value) => selected = value,
),
for (final width in [320.0, 390.0, 720.0, 1200.0]) {
testWidgets('floating tabs at $width, 2x', (tester) async {
tester.view.physicalSize = Size(width, 640);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
PipelineDetailTab? selected;
final body = Align(
alignment: Alignment.bottomCenter,
child: PipelineDetailTabs(
selected: PipelineDetailTab.summary,
onSelected: (value) => selected = value,
),
);
Widget scaled(BuildContext context, Widget? child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(2)),
child: child!,
);
await tester.pumpWidget(
MaterialApp(builder: scaled, home: Scaffold(body: body)),
);
await tester.pumpAndSettle();
// One floating bar of separate round tab buttons.
expect(find.byType(FloatingDestinationBar), findsOneWidget);
final pill = tester.getRect(find.byKey(FloatingDestinationBar.rowKey));
// Sized to its three tabs at the right edge, on a phone as when wide.
expect(pill.right, width - 16);
expect(
pill.width,
FloatingDestinationBar.rowWidth(
cupertino: false,
tabs: PipelineDetailTab.values.length,
),
);
for (final tab in PipelineDetailTab.values) {
final rect = tester.getRect(
find.byKey(ValueKey('pipeline-detail-tab-${tab.name}')),
);
Widget scaled(BuildContext context, Widget? child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(2)),
child: child!,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
builder: scaled,
home: CupertinoPageScaffold(child: body),
)
: MaterialApp(
builder: scaled,
home: Scaffold(body: body),
),
);
await tester.pumpAndSettle();
// One floating bar of separate round tab buttons.
expect(find.byType(FloatingDestinationBar), findsOneWidget);
final pill = tester.getRect(find.byKey(FloatingDestinationBar.rowKey));
// Sized to its three tabs at the right edge, on a phone as when wide.
expect(pill.right, width - 16);
expect(
pill.width,
FloatingDestinationBar.rowWidth(
cupertino: cupertino,
tabs: PipelineDetailTab.values.length,
),
);
for (final tab in PipelineDetailTab.values) {
final rect = tester.getRect(
find.byKey(ValueKey('pipeline-detail-tab-${tab.name}')),
);
expect(rect.left, greaterThanOrEqualTo(pill.left), reason: tab.name);
expect(rect.right, lessThanOrEqualTo(pill.right), reason: tab.name);
}
await tester.tap(find.byKey(const Key('pipeline-detail-tab-source')));
await tester.pumpAndSettle();
expect(selected, PipelineDetailTab.source);
expect(tester.takeException(), isNull);
});
}
expect(rect.left, greaterThanOrEqualTo(pill.left), reason: tab.name);
expect(rect.right, lessThanOrEqualTo(pill.right), reason: tab.name);
}
await tester.tap(find.byKey(const Key('pipeline-detail-tab-source')));
await tester.pumpAndSettle();
expect(selected, PipelineDetailTab.source);
expect(tester.takeException(), isNull);
});
}
}
@@ -1,15 +1,11 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/layout/app_list_row.dart';
import '../../native_back.dart';
import 'package:pipelines_app/features/graph/widgets/definition_graph_view.dart';
import 'package:pipelines_app/features/pipelines/pipeline_repository.dart';
import 'package:pipelines_app/features/pipelines/pipelines_controller.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_detail_panel.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'fixtures.dart';
import 'test_helpers.dart';
@@ -110,66 +106,6 @@ void main() {
expect(find.byKey(const Key('pipeline-detail')), findsOneWidget);
});
testWidgets('iOS uses Cupertino scaffolds, list tiles and segmented tabs', (
tester,
) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final fixture = PipelineFixture();
try {
await tester.pumpWidget(
CupertinoApp(home: PipelinesScreen(gateway: gatewayFor(fixture))),
);
await tester.pumpAndSettle();
expect(find.byType(CupertinoPageScaffold), findsOneWidget);
// The shared list row, in its Cupertino form.
expect(
tester
.widget<AppListRow>(find.byKey(const Key('pipeline-row-1')))
.cupertino,
isTrue,
);
expect(find.byType(CupertinoActionSheet), findsNothing);
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pumpAndSettle();
// The tabs are the floating glass Cupertino tab bar.
expect(
find.descendant(
of: find.byKey(const Key('pipeline-detail-tabs')),
matching: find.byType(FloatingDestinationBar),
),
findsOneWidget,
);
// Versions are the shared row in its Cupertino form, flat on the page.
expect(
tester
.widget<AppListRow>(find.byKey(const Key('pipeline-version-1')))
.cupertino,
isTrue,
);
expect(find.byType(CupertinoListSection), findsNothing);
await tester.tap(find.byKey(const Key('pipeline-version-1')));
await tester.pumpAndSettle();
expect(find.text('Viewing v1 (latest v2).'), findsOneWidget);
await tester.tap(find.byKey(const Key('pipeline-detail-tab-source')));
await tester.pump();
expect(
selectableText(
'name: Alpha review\nstages:\n review:\n type: model\n'
'# selected version 1',
),
findsOneWidget,
);
} finally {
debugDefaultTargetPlatformOverride = null;
}
});
testWidgets('3x text in a very short panel keeps the tabs reachable', (
tester,
) async {
@@ -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/pipelines/screen.dart';
@@ -136,21 +135,15 @@ void main() {
expect(find.text('Beta deploy'), findsOneWidget);
});
for (final cupertino in [false, true]) {
testWidgets('Schedules opens from the bar (cupertino: $cupertino)', (
tester,
) async {
var opened = 0;
final screen = PipelinesScreen(
gateway: gatewayFor(PipelineFixture()),
onOpenSchedules: () => opened++,
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('pipelines-open-schedules')));
expect(opened, 1);
});
}
testWidgets('Schedules opens from the bar', (tester) async {
var opened = 0;
final screen = PipelinesScreen(
gateway: gatewayFor(PipelineFixture()),
onOpenSchedules: () => opened++,
);
await tester.pumpWidget(MaterialApp(home: screen));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('pipelines-open-schedules')));
expect(opened, 1);
});
}
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
@@ -53,17 +52,14 @@ JsonMap noRun() => {'type': 'run', 'run_detail': null};
Future<void> pumpScreen(
WidgetTester tester,
FakeGateway gateway,
List<int> navigated, {
bool cupertino = false,
}) async {
List<int> navigated,
) async {
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final screen = PipelinesScreen(gateway: gateway, onRunStarted: navigated.add);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen),
);
await tester.pumpWidget(MaterialApp(home: screen));
await tester.pumpAndSettle();
}
@@ -582,74 +578,6 @@ void main() {
expect(navigated, [86]);
});
testWidgets('the Cupertino host shows the same native prompt and words', (
tester,
) async {
final fixture = PipelineFixture();
final navigated = <int>[];
final gateway = launchGateway(
fixture,
onLaunch: (fields) => acceptedRun(84),
);
await pumpScreen(tester, gateway, navigated, cupertino: true);
await openDetail(tester);
await tester.tap(find.byKey(runPipelineActionKey));
await tester.pumpAndSettle();
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
expect(find.byType(AlertDialog), findsNothing);
expect(find.text('Run Alpha review'), findsOneWidget);
expect(find.text(runPipelinePromptLabel), findsOneWidget);
expect(find.text(runPipelineWorkspaceLabel), findsOneWidget);
expect(find.text(runPipelineNotifyLabel), findsOneWidget);
expect(
find.descendant(
of: find.byType(CupertinoAlertDialog),
matching: find.text(runPipelineConfirmLabel),
),
findsOneWidget,
);
expect(find.text(runPipelineCancelLabel), findsOneWidget);
expect(gateway.callsOf('run_pipeline'), isEmpty);
await tester.tap(find.byKey(runPipelineCancelKey));
await tester.pumpAndSettle();
expect(find.byType(CupertinoAlertDialog), findsNothing);
expect(gateway.callsOf('run_pipeline'), isEmpty);
});
testWidgets('Cupertino field labels and helper use theme label roles', (
tester,
) async {
final fixture = PipelineFixture();
final gateway = launchGateway(
fixture,
onLaunch: (fields) => acceptedRun(87),
);
await pumpScreen(tester, gateway, <int>[], cupertino: true);
await openDetail(tester);
await tester.tap(find.byKey(runPipelineActionKey));
await tester.pumpAndSettle();
final context = tester.element(find.byType(CupertinoAlertDialog));
final theme = CupertinoTheme.of(context);
final labelStyle = theme.textTheme.textStyle;
for (final label in [
runPipelinePromptLabel,
runPipelineWorkspaceLabel,
runPipelineNotifyLabel,
]) {
final style = tester.widget<Text>(find.text(label)).style;
expect(style?.color, labelStyle.color, reason: label);
expect(style?.fontSize, labelStyle.fontSize, reason: label);
}
final helper = tester
.widget<Text>(find.text(runPipelineWorkspaceHelper))
.style;
expect(helper?.color, CupertinoColors.secondaryLabel.resolveFrom(context));
expect(helper?.fontSize, theme.textTheme.tabLabelTextStyle.fontSize);
});
testWidgets('Schedule… leaves the run dialog for the schedule editor', (
tester,
) async {
@@ -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/servers/server_catalog.dart';
@@ -26,20 +25,13 @@ class _ControlledStore extends MemoryServerCatalogStore {
Future<void> _openEditor(
WidgetTester tester,
ServerConnections connections,
bool cupertino, {
ServerConnections connections, {
bool edit = false,
}) async {
final body = SingleChildScrollView(
child: SavedServersSection(connections: connections),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
home: CupertinoPageScaffold(child: SafeArea(child: body)),
)
: MaterialApp(home: Scaffold(body: body)),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: body)));
if (edit) await openSavedServerMenu(tester);
await tester.tap(find.text(edit ? 'Edit Home' : 'Add server'));
await tester.pumpAndSettle();
@@ -56,125 +48,114 @@ Future<void> _openEditor(
}
void main() {
for (final cupertino in [false, true]) {
testWidgets('Back cancels an unsaved draft ($cupertino)', (tester) async {
testWidgets('Back cancels an unsaved draft', (tester) async {
final store = _ControlledStore();
final connections = ServerConnections(
store: store,
onSelected: (_) async => fail('Cancel must not select a server'),
);
addTearDown(connections.dispose);
await _openEditor(tester, connections);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(find.byKey(const Key('server-profile-name')), findsNothing);
expect(store.writes, isEmpty);
expect(connections.catalog.servers, isEmpty);
});
testWidgets('failed edit keeps draft and blocks duplicate save', (
tester,
) async {
final original = SavedServer.validated(
id: 'home',
name: 'Home',
endpoints: ['wss://home.test/connect'],
);
final store = _ControlledStore(
catalog: ServerCatalog(servers: [original], selectedId: original.id),
)..pending = Completer<bool>();
final activations = <SavedServer?>[];
final connections = ServerConnections(
store: store,
onSelected: (server) async => activations.add(server),
);
addTearDown(connections.dispose);
await connections.load();
await _openEditor(tester, connections, edit: true);
await tester.tap(find.text('Save server'));
await tester.pump();
expect(find.text('Saving server…'), findsOneWidget);
final button = find.widgetWithText(FilledButton, 'Saving server…');
expect(tester.widget<FilledButton>(button).onPressed, isNull);
await tester.tap(find.text('Saving server…'));
await tester.binding.handlePopRoute();
await tester.pump();
expect(find.byKey(const Key('server-profile-name')), findsOneWidget);
expect(store.writes, hasLength(1));
expect(connections.catalog.active?.name, 'Home');
expect(activations, isEmpty);
store.pending!.complete(false);
await tester.pumpAndSettle();
expect(find.textContaining('could not be saved'), findsOneWidget);
final name = tester.widget<EditableText>(
find.descendant(
of: find.byKey(const Key('server-profile-name')),
matching: find.byType(EditableText),
),
);
final addresses = tester.widget<EditableText>(
find.descendant(
of: find.byKey(const Key('server-profile-addresses')),
matching: find.byType(EditableText),
),
);
expect(name.controller.text, 'My home');
expect(addresses.controller.text, contains('ws://192.168.1.2:8083'));
expect(connections.catalog.active?.name, 'Home');
store.pending = null;
await tester.ensureVisible(find.text('Save server'));
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('server-profile-name')), findsNothing);
expect(connections.catalog.active?.name, 'My home');
expect(store.catalog?.active?.endpoints, hasLength(2));
expect(store.writes, hasLength(2));
expect(activations.single?.id, original.id);
expect(tester.takeException(), isNull);
});
testWidgets(
'activation failure retry does not duplicate new profile',
(tester) async {
final store = _ControlledStore();
var attempts = 0;
final connections = ServerConnections(
store: store,
onSelected: (_) async => fail('Cancel must not select a server'),
onSelected: (_) async {
if (++attempts == 1) throw StateError('Connection unavailable');
},
);
addTearDown(connections.dispose);
await _openEditor(tester, connections, cupertino);
await tester.binding.handlePopRoute();
await connections.load();
await _openEditor(tester, connections);
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
expect(find.textContaining('Connection unavailable'), findsOneWidget);
expect(find.byKey(const Key('server-profile-name')), findsOneWidget);
expect(store.catalog?.servers, hasLength(1));
final savedId = store.catalog!.servers.single.id;
await tester.ensureVisible(find.text('Save server'));
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
expect(attempts, 2);
expect(store.catalog?.servers, hasLength(1));
expect(store.catalog?.servers.single.id, savedId);
expect(find.byKey(const Key('server-profile-name')), findsNothing);
expect(store.writes, isEmpty);
expect(connections.catalog.servers, isEmpty);
});
testWidgets(
'failed edit keeps draft and blocks duplicate save ($cupertino)',
(tester) async {
final original = SavedServer.validated(
id: 'home',
name: 'Home',
endpoints: ['wss://home.test/connect'],
);
final store = _ControlledStore(
catalog: ServerCatalog(servers: [original], selectedId: original.id),
)..pending = Completer<bool>();
final activations = <SavedServer?>[];
final connections = ServerConnections(
store: store,
onSelected: (server) async => activations.add(server),
);
addTearDown(connections.dispose);
await connections.load();
await _openEditor(tester, connections, cupertino, edit: true);
await tester.tap(find.text('Save server'));
await tester.pump();
expect(find.text('Saving server…'), findsOneWidget);
final button = find.widgetWithText(
cupertino ? CupertinoButton : FilledButton,
'Saving server…',
);
expect(
cupertino
? tester.widget<CupertinoButton>(button).onPressed
: tester.widget<FilledButton>(button).onPressed,
isNull,
);
await tester.tap(find.text('Saving server…'));
await tester.binding.handlePopRoute();
await tester.pump();
expect(find.byKey(const Key('server-profile-name')), findsOneWidget);
expect(store.writes, hasLength(1));
expect(connections.catalog.active?.name, 'Home');
expect(activations, isEmpty);
store.pending!.complete(false);
await tester.pumpAndSettle();
expect(find.textContaining('could not be saved'), findsOneWidget);
final name = tester.widget<EditableText>(
find.descendant(
of: find.byKey(const Key('server-profile-name')),
matching: find.byType(EditableText),
),
);
final addresses = tester.widget<EditableText>(
find.descendant(
of: find.byKey(const Key('server-profile-addresses')),
matching: find.byType(EditableText),
),
);
expect(name.controller.text, 'My home');
expect(addresses.controller.text, contains('ws://192.168.1.2:8083'));
expect(connections.catalog.active?.name, 'Home');
store.pending = null;
await tester.ensureVisible(find.text('Save server'));
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('server-profile-name')), findsNothing);
expect(connections.catalog.active?.name, 'My home');
expect(store.catalog?.active?.endpoints, hasLength(2));
expect(store.writes, hasLength(2));
expect(activations.single?.id, original.id);
expect(tester.takeException(), isNull);
},
);
testWidgets(
'activation failure retry does not duplicate new profile ($cupertino)',
(tester) async {
final store = _ControlledStore();
var attempts = 0;
final connections = ServerConnections(
store: store,
onSelected: (_) async {
if (++attempts == 1) throw StateError('Connection unavailable');
},
);
addTearDown(connections.dispose);
await connections.load();
await _openEditor(tester, connections, cupertino);
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
expect(find.textContaining('Connection unavailable'), findsOneWidget);
expect(find.byKey(const Key('server-profile-name')), findsOneWidget);
expect(store.catalog?.servers, hasLength(1));
final savedId = store.catalog!.servers.single.id;
await tester.ensureVisible(find.text('Save server'));
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
expect(attempts, 2);
expect(store.catalog?.servers, hasLength(1));
expect(store.catalog?.servers.single.id, savedId);
expect(find.byKey(const Key('server-profile-name')), findsNothing);
expect(tester.takeException(), isNull);
},
);
}
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:pipelines_app/core/servers/server_catalog.dart';
@@ -108,95 +107,79 @@ void main() {
},
);
for (final cupertino in [false, true]) {
testWidgets('add, edit and select ordered server aliases ($cupertino)', (
tester,
) async {
final calls = <String?>[];
final connections = ServerConnections(
store: MemoryServerCatalogStore(),
onSelected: (s) async => calls.add(s?.id),
);
addTearDown(connections.dispose);
await connections.load();
final body = SingleChildScrollView(
child: SavedServersSection(connections: connections),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
home: CupertinoPageScaffold(child: SafeArea(child: body)),
)
: MaterialApp(home: Scaffold(body: body)),
);
await tester.tap(find.text('Add server'));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('server-profile-name')),
'Home',
);
await tester.enterText(
find.byKey(const Key('server-profile-addresses')),
'wss://tail.example/connect\nws://192.168.1.2:8083/connect',
);
await revealSave(tester);
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
expect(connections.catalog.active?.name, 'Home');
expect(connections.catalog.active?.endpoints, [
'wss://tail.example/connect',
'ws://192.168.1.2:8083/connect',
]);
expect(
find.text('Backup address: ws://192.168.1.2:8083/connect'),
findsOneWidget,
);
await openSavedServerMenu(tester);
await tester.tap(find.text('Edit Home'));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('server-profile-name')),
'My home',
);
await revealSave(tester);
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
expect(connections.catalog.active?.name, 'My home');
expect(calls, hasLength(2));
expect(calls.first, calls.last);
expect(tester.takeException(), isNull);
});
testWidgets('add, edit and select ordered server aliases', (tester) async {
final calls = <String?>[];
final connections = ServerConnections(
store: MemoryServerCatalogStore(),
onSelected: (s) async => calls.add(s?.id),
);
addTearDown(connections.dispose);
await connections.load();
final body = SingleChildScrollView(
child: SavedServersSection(connections: connections),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: body)));
await tester.tap(find.text('Add server'));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('server-profile-name')),
'Home',
);
await tester.enterText(
find.byKey(const Key('server-profile-addresses')),
'wss://tail.example/connect\nws://192.168.1.2:8083/connect',
);
await revealSave(tester);
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
expect(connections.catalog.active?.name, 'Home');
expect(connections.catalog.active?.endpoints, [
'wss://tail.example/connect',
'ws://192.168.1.2:8083/connect',
]);
expect(
find.text('Backup address: ws://192.168.1.2:8083/connect'),
findsOneWidget,
);
await openSavedServerMenu(tester);
await tester.tap(find.text('Edit Home'));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('server-profile-name')),
'My home',
);
await revealSave(tester);
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
expect(connections.catalog.active?.name, 'My home');
expect(calls, hasLength(2));
expect(calls.first, calls.last);
expect(tester.takeException(), isNull);
});
testWidgets('invalid server addresses stay in editor ($cupertino)', (
tester,
) async {
final connections = ServerConnections(
store: MemoryServerCatalogStore(),
onSelected: (_) async {},
);
addTearDown(connections.dispose);
final body = SavedServersSection(connections: connections);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body)),
);
await tester.tap(find.text('Add server'));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('server-profile-name')),
'Home',
);
await tester.enterText(
find.byKey(const Key('server-profile-addresses')),
'not-a-url',
);
await revealSave(tester);
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('server-profile-addresses')), findsOneWidget);
expect(connections.catalog.servers, isEmpty);
expect(find.textContaining('valid URL'), findsOneWidget);
});
}
testWidgets('invalid server addresses stay in editor', (tester) async {
final connections = ServerConnections(
store: MemoryServerCatalogStore(),
onSelected: (_) async {},
);
addTearDown(connections.dispose);
final body = SavedServersSection(connections: connections);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: body)));
await tester.tap(find.text('Add server'));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('server-profile-name')),
'Home',
);
await tester.enterText(
find.byKey(const Key('server-profile-addresses')),
'not-a-url',
);
await revealSave(tester);
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('server-profile-addresses')), findsOneWidget);
expect(connections.catalog.servers, isEmpty);
expect(find.textContaining('valid URL'), findsOneWidget);
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -18,47 +17,31 @@ class _Store implements AnimationSpeedStore {
void main() {
tearDown(() => timeDilation = 1);
for (final cupertino in [false, true]) {
testWidgets(
'native slider updates global speed and Reset restores normal ($cupertino)',
(tester) async {
final store = _Store();
final controller = AnimationSpeedController(store: store);
final section = SettingsAnimationSection(controller: controller);
await tester.pumpWidget(
cupertino
? CupertinoApp(
home: CupertinoPageScaffold(
child: SingleChildScrollView(child: section),
),
)
: MaterialApp(
home: Scaffold(body: SingleChildScrollView(child: section)),
),
);
if (cupertino) {
final slider = tester.widget<CupertinoSlider>(
find.byType(CupertinoSlider),
);
slider.onChanged!(1.8);
slider.onChangeEnd!(1.8);
} else {
final slider = tester.widget<Slider>(find.byType(Slider));
slider.onChanged!(1.8);
slider.onChangeEnd!(1.8);
}
await tester.pump();
expect(find.text('1.8×'), findsWidgets);
expect(timeDilation, closeTo(1 / 1.8, 0.001));
expect(store.saved, 1.8);
await tester.tap(find.text('Reset'));
await tester.pump();
expect(controller.speed, 1);
expect(timeDilation, 1);
expect(store.saved, 1);
expect(tester.takeException(), isNull);
controller.dispose();
},
);
}
testWidgets(
'layout slider updates global speed and Reset restores normal',
(tester) async {
final store = _Store();
final controller = AnimationSpeedController(store: store);
final section = SettingsAnimationSection(controller: controller);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(body: SingleChildScrollView(child: section)),
),
);
final slider = tester.widget<Slider>(find.byType(Slider));
slider.onChanged!(1.8);
slider.onChangeEnd!(1.8);
await tester.pump();
expect(find.text('1.8×'), findsWidgets);
expect(timeDilation, closeTo(1 / 1.8, 0.001));
expect(store.saved, 1.8);
await tester.tap(find.text('Reset'));
await tester.pump();
expect(controller.speed, 1);
expect(timeDilation, 1);
expect(store.saved, 1);
expect(tester.takeException(), isNull);
controller.dispose();
},
);
}
@@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/settings/settings_custom_font_actions.dart';
@@ -12,7 +11,6 @@ import 'package:pipelines_app/features/settings/settings_row.dart';
import 'package:pipelines_app/ui/theme/app_font.dart';
import 'package:pipelines_app/ui/theme/app_font_controller.dart';
import 'package:pipelines_app/ui/theme/app_font_store.dart';
import 'package:pipelines_app/ui/theme/custom_fonts/custom_font.dart';
import 'package:pipelines_app/ui/theme/custom_fonts/custom_font_draft.dart';
import 'package:pipelines_app/ui/theme/custom_fonts/custom_font_library.dart';
import 'package:pipelines_app/ui/theme/custom_fonts/font_bytes_store.dart';
@@ -42,7 +40,6 @@ class _Harness {
Future<void> _pump(
WidgetTester tester,
_Harness harness, {
bool cupertino = false,
FontFilePicker? pick,
}) async {
final section = SingleChildScrollView(
@@ -51,11 +48,7 @@ Future<void> _pump(
pickFiles: pick ?? harness.pick,
),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: section))
: MaterialApp(home: Scaffold(body: section)),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: section)));
await tester.pumpAndSettle();
}
@@ -243,35 +236,4 @@ void main() {
final row = tester.widget<SettingsRow>(find.byKey(settingsAddFontKey));
expect(row.enabled, isTrue);
});
testWidgets('Cupertino: an added font has the checkmark and options', (
tester,
) async {
final harness = _Harness()..next = <PickedFontFile>[regular];
await _pump(tester, harness, cupertino: true);
await tester.tap(find.text(addCustomFontText));
await tester.pumpAndSettle();
await tester.tap(find.text('Add'));
await tester.pumpAndSettle();
final CustomFont font = harness.fonts.customFonts.single;
final row = find.byKey(settingsFontKey(font));
expect(
find.descendant(
of: row,
matching: find.byIcon(CupertinoIcons.check_mark),
),
findsOneWidget,
);
// The options button is its own control beside the row.
expect(find.bySemanticsLabel(customFontActionsTooltip), findsOneWidget);
await tester.tap(find.byIcon(CupertinoIcons.ellipsis_circle));
await tester.pumpAndSettle();
await tester.tap(find.text(removeCustomFontText));
await tester.pumpAndSettle();
await tester.tap(find.widgetWithText(CupertinoDialogAction, 'Remove'));
await tester.pumpAndSettle();
expect(harness.fonts.customFonts, isEmpty);
expect(harness.fonts.selected, AppFont.system);
});
}
@@ -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/notification_service/notification_service_bridge.dart';
@@ -8,7 +7,6 @@ import '../notification_service/fake_notification_service.dart';
Widget _host(
NotificationServiceBridge bridge, {
required bool cupertino,
Future<void> Function()? requestPermission,
}) {
final body = SingleChildScrollView(
@@ -17,59 +15,44 @@ Widget _host(
requestNotificationPermission: requestPermission,
),
);
return cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body));
return MaterialApp(home: Scaffold(body: body));
}
bool _switchValue(WidgetTester tester, {required bool cupertino}) {
bool _switchValue(WidgetTester tester) {
final tile = find.byKey(DeviceDeliveryKeys.toggle);
if (cupertino) {
return tester
.widget<CupertinoSwitch>(
find.descendant(of: tile, matching: find.byType(CupertinoSwitch)),
)
.value;
}
return tester.widget<SwitchListTile>(tile).value;
}
void main() {
for (final cupertino in [false, true]) {
final style = cupertino ? 'Cupertino' : 'Material';
testWidgets('shows the switch, status and ntfy note', (tester) async {
final service = FakeNotificationService();
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
expect(find.text(deviceDeliverySwitchLabel), findsOneWidget);
expect(_switchValue(tester), isTrue);
expect(find.text('Connected'), findsOneWidget);
expect(find.text(deviceDeliveryNote), findsOneWidget);
expect(find.text(deviceDeliveryBatteryLabel), findsOneWidget);
expect(find.byKey(DeviceDeliveryKeys.permission), findsNothing);
});
testWidgets('$style shows the switch, status and ntfy note', (
tester,
) async {
final service = FakeNotificationService();
await tester.pumpWidget(_host(service, cupertino: cupertino));
await tester.pumpAndSettle();
expect(find.text(deviceDeliverySwitchLabel), findsOneWidget);
expect(_switchValue(tester, cupertino: cupertino), isTrue);
expect(find.text('Connected'), findsOneWidget);
expect(find.text(deviceDeliveryNote), findsOneWidget);
expect(find.text(deviceDeliveryBatteryLabel), findsOneWidget);
expect(find.byKey(DeviceDeliveryKeys.permission), findsNothing);
});
testWidgets('$style switching off stops delivery', (tester) async {
final service = FakeNotificationService();
await tester.pumpWidget(_host(service, cupertino: cupertino));
await tester.pumpAndSettle();
await tester.tap(find.byKey(DeviceDeliveryKeys.toggle));
await tester.pumpAndSettle();
expect(service.calls.last.$1, 'setEnabled');
expect(service.calls.last.$2, {'enabled': false});
expect(_switchValue(tester, cupertino: cupertino), isFalse);
expect(find.text('Off'), findsOneWidget);
// The grants only matter while delivery is on.
expect(find.text(deviceDeliveryBatteryLabel), findsNothing);
});
}
testWidgets('switching off stops delivery', (tester) async {
final service = FakeNotificationService();
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
await tester.tap(find.byKey(DeviceDeliveryKeys.toggle));
await tester.pumpAndSettle();
expect(service.calls.last.$1, 'setEnabled');
expect(service.calls.last.$2, {'enabled': false});
expect(_switchValue(tester), isFalse);
expect(find.text('Off'), findsOneWidget);
// The grants only matter while delivery is on.
expect(find.text(deviceDeliveryBatteryLabel), findsNothing);
});
testWidgets('live status pushed by the service is shown', (tester) async {
final service = FakeNotificationService();
await tester.pumpWidget(_host(service, cupertino: false));
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
service.push(service.copy(state: DeliveryState.reconnecting));
await tester.pumpAndSettle();
@@ -80,7 +63,7 @@ void main() {
tester,
) async {
final service = FakeNotificationService();
await tester.pumpWidget(_host(service, cupertino: false));
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
await tester.tap(find.text(deviceDeliveryBatteryLabel));
await tester.pumpAndSettle();
@@ -103,7 +86,6 @@ void main() {
await tester.pumpWidget(
_host(
service,
cupertino: false,
requestPermission: () async {
asked++;
service.current = service.copy(notificationsAllowed: true);
@@ -128,7 +110,7 @@ void main() {
notificationsAllowed: false,
);
await tester.pumpWidget(
_host(service, cupertino: false, requestPermission: () async => asked++),
_host(service, requestPermission: () async => asked++),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(DeviceDeliveryKeys.toggle));
@@ -139,7 +121,7 @@ void main() {
});
testWidgets('a failing platform is reported, not hidden', (tester) async {
await tester.pumpWidget(_host(_FailingService(), cupertino: false));
await tester.pumpWidget(_host(_FailingService()));
await tester.pumpAndSettle();
expect(find.byKey(DeviceDeliveryKeys.error), findsOneWidget);
});
@@ -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/features/settings/settings_font_section.dart';
@@ -29,19 +28,11 @@ class _Harness {
);
}
Future<void> _pump(
WidgetTester tester,
_Harness harness, {
bool cupertino = false,
}) async {
Future<void> _pump(WidgetTester tester, _Harness harness) async {
final section = SingleChildScrollView(
child: SettingsFontSection(controller: harness.fonts),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: section))
: MaterialApp(home: Scaffold(body: section)),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: section)));
await tester.pumpAndSettle();
}
@@ -102,28 +93,6 @@ void main() {
expect(harness.fonts.family, 'Source Sans 3');
});
testWidgets('Cupertino: the chosen row carries the checkmark', (
tester,
) async {
final harness = _Harness();
await _pump(tester, harness, cupertino: true);
expect(find.byType(RadioListTile<FontChoice>), findsNothing);
expect(_familyOf(tester, AppFont.system), 'CupertinoSystemText');
Finder check(AppFont font) => find.descendant(
of: find.byKey(settingsFontKey(font)),
matching: find.byIcon(CupertinoIcons.check_mark),
);
expect(check(AppFont.system), findsOneWidget);
await tester.tap(find.text('Inter'));
await tester.pumpAndSettle();
expect(check(AppFont.system), findsNothing);
expect(check(AppFont.inter), findsOneWidget);
expect(harness.store.id, AppFont.inter.id);
expect(harness.fonts.family, 'Inter');
});
testWidgets('a failed save is said under the group', (tester) async {
final harness = _Harness();
harness.store.failSaves = true;
@@ -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/server_catalog.dart';
@@ -15,7 +14,6 @@ import 'package:pipelines_app/features/settings/settings_layout.dart';
import 'package:pipelines_app/features/settings/settings_screen.dart';
import 'package:pipelines_app/features/settings/settings_store.dart';
import 'package:pipelines_app/features/settings/settings_trust_warning.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
import 'fake_channel.dart';
import 'settings_topic_test_helper.dart';
@@ -94,29 +92,6 @@ void main() {
);
});
testWidgets('Cupertino uses inset-grouped sections on the grouped page', (
tester,
) async {
await _pump(tester, cupertino: true);
expect(find.byType(Card), findsNothing);
expect(find.byType(CupertinoListSection), findsWidgets);
for (final section in tester.widgetList<CupertinoListSection>(
find.byType(CupertinoListSection),
)) {
expect(section.type, CupertinoListSectionType.insetGrouped);
}
final context = tester.element(find.byType(SettingsGroup).first);
expect(
find.byWidgetPredicate(
(widget) =>
widget is ColoredBox &&
widget.color == AppColors.groupedBackground.resolveFrom(context),
),
findsWidgets,
);
});
testWidgets('the notification tile is the section\'s only title', (
tester,
) async {
@@ -131,77 +106,54 @@ void main() {
expect(find.text('Connection').last, findsOneWidget);
});
testWidgets('Cupertino keeps the compact secondary field label', (
tester,
) async {
await _pump(tester, cupertino: true);
final label = tester.widget<Text>(find.text('Server URL'));
final context = tester.element(find.text('Server URL'));
expect(
label.style?.color,
CupertinoColors.secondaryLabel.resolveFrom(context),
testWidgets('server rows show which server is selected', (tester) async {
final connections = ServerConnections(
store: MemoryServerCatalogStore(
catalog: ServerCatalog(
servers: [
SavedServer.validated(
id: 'Home',
name: 'Home',
endpoints: const ['wss://home.test/connect'],
),
SavedServer.validated(
id: 'Work',
name: 'Work',
endpoints: const ['wss://work.test/connect'],
),
],
selectedId: 'Home',
),
),
onSelected: (_) async {},
);
expect(find.byType(CupertinoTextField), findsNWidgets(2));
addTearDown(connections.dispose);
await connections.load();
final body = SingleChildScrollView(
child: SavedServersSection(connections: connections),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: body)));
expect(find.byType(SavedServerRow), findsNWidgets(2));
expect(find.text('Pipelines and runs server'), findsOneWidget);
expect(
find.byWidgetPredicate(
(widget) => widget is Icon && widget.semanticLabel == 'Selected',
),
findsOneWidget,
);
expect(find.text('Address: wss://work.test/connect'), findsOneWidget);
expect(find.byKey(savedServerMenuKey('Home')), findsOneWidget);
expect(find.text('Add server'), findsOneWidget);
// Tapping another server's row uses it.
await tester.tap(find.text('Work'));
await tester.pumpAndSettle();
expect(connections.catalog.active?.id, 'Work');
});
for (final cupertino in [false, true]) {
testWidgets('server rows show which server is selected ($cupertino)', (
tester,
) async {
final connections = ServerConnections(
store: MemoryServerCatalogStore(
catalog: ServerCatalog(
servers: [
SavedServer.validated(
id: 'Home',
name: 'Home',
endpoints: const ['wss://home.test/connect'],
),
SavedServer.validated(
id: 'Work',
name: 'Work',
endpoints: const ['wss://work.test/connect'],
),
],
selectedId: 'Home',
),
),
onSelected: (_) async {},
);
addTearDown(connections.dispose);
await connections.load();
final body = SingleChildScrollView(
child: SavedServersSection(connections: connections),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body)),
);
expect(find.byType(SavedServerRow), findsNWidgets(2));
expect(find.text('Pipelines and runs server'), findsOneWidget);
expect(
find.byWidgetPredicate(
(widget) => widget is Icon && widget.semanticLabel == 'Selected',
),
findsOneWidget,
);
expect(find.text('Address: wss://work.test/connect'), findsOneWidget);
expect(find.byKey(savedServerMenuKey('Home')), findsOneWidget);
expect(find.text('Add server'), findsOneWidget);
// Tapping another server's row uses it.
await tester.tap(find.text('Work'));
await tester.pumpAndSettle();
expect(connections.catalog.active?.id, 'Work');
});
}
}
Future<void> _pump(
WidgetTester tester, {
bool cupertino = false,
NotificationController? notifications,
Size size = const Size(800, 1600),
double topPadding = 0,
@@ -224,15 +176,10 @@ Future<void> _pump(
child: child!,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
builder: padded,
home: CupertinoPageScaffold(child: screen),
)
: MaterialApp(
builder: padded,
home: Scaffold(body: screen),
),
MaterialApp(
builder: padded,
home: Scaffold(body: screen),
),
);
await tester.pump();
await tester.pump();
@@ -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';
@@ -33,120 +32,96 @@ JsonMap _reply(bool run, bool needs, bool reply) => {
},
};
Widget _host(ApiGateway gateway, {required bool cupertino}) {
Widget _host(ApiGateway gateway) {
final body = SingleChildScrollView(
child: SettingsNtfySection(gateway: gateway, connected: true),
);
return cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body));
return MaterialApp(home: Scaffold(body: body));
}
bool _checked(WidgetTester tester, String key, {required bool cupertino}) {
bool _checked(WidgetTester tester, String key) {
final tile = find.byKey(ntfySettingKey(key));
if (cupertino) {
return tester
.widget<CupertinoSwitch>(
find.descendant(of: tile, matching: find.byType(CupertinoSwitch)),
)
.value;
}
return tester.widget<CheckboxListTile>(tile).value!;
}
void main() {
for (final cupertino in [false, true]) {
final style = cupertino ? 'Cupertino' : 'Material';
testWidgets('loads the stored values', (tester) async {
final gateway = _Gateway((_, _) => _reply(true, false, true));
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(gateway.calls.single.$1, 'notification_settings');
expect(find.text('Notify when any run ends'), findsOneWidget);
expect(
find.text('Otherwise only runs started with Notify me'),
findsOneWidget,
);
expect(find.text('Chat needs your answer or approval'), findsOneWidget);
expect(find.text('Chat reply finished'), findsOneWidget);
expect(find.text(ntfySectionSubtitle), findsOneWidget);
expect(_checked(tester, 'run_finished'), isTrue);
expect(_checked(tester, 'chat_needs_you'), isFalse);
expect(_checked(tester, 'chat_reply_finished'), isTrue);
});
testWidgets('$style loads the stored values', (tester) async {
final gateway = _Gateway((_, _) => _reply(true, false, true));
await tester.pumpWidget(_host(gateway, cupertino: cupertino));
await tester.pumpAndSettle();
expect(gateway.calls.single.$1, 'notification_settings');
expect(find.text('Notify when any run ends'), findsOneWidget);
expect(
find.text('Otherwise only runs started with Notify me'),
findsOneWidget,
);
expect(find.text('Chat needs your answer or approval'), findsOneWidget);
expect(find.text('Chat reply finished'), findsOneWidget);
expect(find.text(ntfySectionSubtitle), findsOneWidget);
expect(_checked(tester, 'run_finished', cupertino: cupertino), isTrue);
expect(_checked(tester, 'chat_needs_you', cupertino: cupertino), isFalse);
expect(
_checked(tester, 'chat_reply_finished', cupertino: cupertino),
isTrue,
);
});
testWidgets('shows the server default: only marked runs', (tester) async {
// The server's defaults: run ends notify only for "Notify me" runs.
final gateway = _Gateway((_, _) => _reply(false, true, false));
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(_checked(tester, 'run_finished'), isFalse);
expect(_checked(tester, 'chat_needs_you'), isTrue);
expect(_checked(tester, 'chat_reply_finished'), isFalse);
});
testWidgets('$style shows the server default: only marked runs', (
tester,
) async {
// The server's defaults: run ends notify only for "Notify me" runs.
final gateway = _Gateway((_, _) => _reply(false, true, false));
await tester.pumpWidget(_host(gateway, cupertino: cupertino));
await tester.pumpAndSettle();
expect(_checked(tester, 'run_finished', cupertino: cupertino), isFalse);
expect(_checked(tester, 'chat_needs_you', cupertino: cupertino), isTrue);
expect(
_checked(tester, 'chat_reply_finished', cupertino: cupertino),
isFalse,
);
testWidgets('toggling writes only that setting', (tester) async {
final gateway = _Gateway((type, fields) {
if (type == 'set_notification_settings') {
return _reply(true, true, true);
}
return _reply(true, true, false);
});
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
await tester.tap(find.byKey(ntfySettingKey('chat_reply_finished')));
await tester.pumpAndSettle();
expect(gateway.calls, hasLength(2));
expect(gateway.calls.last.$1, 'set_notification_settings');
expect(gateway.calls.last.$2, {
'notification_settings': {'chat_reply_finished': true},
});
expect(_checked(tester, 'chat_reply_finished'), isTrue);
expect(find.byKey(ntfyErrorKey), findsNothing);
});
testWidgets('$style toggling writes only that setting', (tester) async {
final gateway = _Gateway((type, fields) {
if (type == 'set_notification_settings') {
return _reply(true, true, true);
}
return _reply(true, true, false);
});
await tester.pumpWidget(_host(gateway, cupertino: cupertino));
await tester.pumpAndSettle();
await tester.tap(find.byKey(ntfySettingKey('chat_reply_finished')));
await tester.pumpAndSettle();
expect(gateway.calls, hasLength(2));
expect(gateway.calls.last.$1, 'set_notification_settings');
expect(gateway.calls.last.$2, {
'notification_settings': {'chat_reply_finished': true},
});
expect(
_checked(tester, 'chat_reply_finished', cupertino: cupertino),
isTrue,
);
expect(find.byKey(ntfyErrorKey), findsNothing);
testWidgets('failure reverts and shows the refusal', (tester) async {
final pending = Completer<JsonMap>();
final gateway = _Gateway((type, _) {
if (type == 'set_notification_settings') return pending.future;
return _reply(true, true, false);
});
testWidgets('$style failure reverts and shows the refusal', (tester) async {
final pending = Completer<JsonMap>();
final gateway = _Gateway((type, _) {
if (type == 'set_notification_settings') return pending.future;
return _reply(true, true, false);
});
await tester.pumpWidget(_host(gateway, cupertino: cupertino));
await tester.pumpAndSettle();
await tester.tap(find.byKey(ntfySettingKey('run_finished')));
await tester.pump();
// The change shows at once and the group is disabled while it saves.
expect(_checked(tester, 'run_finished', cupertino: cupertino), isFalse);
await tester.tap(find.byKey(ntfySettingKey('chat_needs_you')));
await tester.pump();
expect(gateway.calls, hasLength(2));
pending.completeError(const ProtocolError('settings are read-only'));
await tester.pumpAndSettle();
expect(_checked(tester, 'run_finished', cupertino: cupertino), isTrue);
expect(_checked(tester, 'chat_needs_you', cupertino: cupertino), isTrue);
expect(
find.text('Could not save: settings are read-only'),
findsOneWidget,
);
});
}
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
await tester.tap(find.byKey(ntfySettingKey('run_finished')));
await tester.pump();
// The change shows at once and the group is disabled while it saves.
expect(_checked(tester, 'run_finished'), isFalse);
await tester.tap(find.byKey(ntfySettingKey('chat_needs_you')));
await tester.pump();
expect(gateway.calls, hasLength(2));
pending.completeError(const ProtocolError('settings are read-only'));
await tester.pumpAndSettle();
expect(_checked(tester, 'run_finished'), isTrue);
expect(_checked(tester, 'chat_needs_you'), isTrue);
expect(
find.text('Could not save: settings are read-only'),
findsOneWidget,
);
});
testWidgets('disabled while loading and offline', (tester) async {
final pending = Completer<JsonMap>();
final gateway = _Gateway((_, _) => pending.future);
await tester.pumpWidget(_host(gateway, cupertino: false));
await tester.pumpWidget(_host(gateway));
await tester.pump();
expect(find.text('Loading…'), findsOneWidget);
await tester.tap(find.byKey(ntfySettingKey('run_finished')));
@@ -181,7 +156,7 @@ void main() {
if (fail) throw const ProtocolError('no store');
return _reply(false, true, false);
});
await tester.pumpWidget(_host(gateway, cupertino: false));
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(
find.text('Could not load notification settings: no store'),
@@ -210,38 +185,27 @@ void main() {
testWidgets('hidden when the server does not send it', (tester) async {
final gateway = _Gateway((_, _) => _reply(true, true, false));
await tester.pumpWidget(_host(gateway, cupertino: false));
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(find.byKey(ntfySettingKey('ntfy_enabled')), findsNothing);
expect(find.text(ntfySectionSubtitle), findsOneWidget);
});
for (final cupertino in [false, true]) {
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} shows and writes it',
(tester) async {
final gateway = _Gateway(
(type, _) => withNtfy(type == 'set_notification_settings'),
);
await tester.pumpWidget(_host(gateway, cupertino: cupertino));
await tester.pumpAndSettle();
expect(find.text('Also send to ntfy'), findsOneWidget);
expect(find.text(ntfySectionAppSubtitle), findsOneWidget);
expect(
_checked(tester, 'ntfy_enabled', cupertino: cupertino),
isFalse,
);
await tester.tap(find.byKey(ntfySettingKey('ntfy_enabled')));
await tester.pumpAndSettle();
expect(gateway.calls.last.$2, {
'notification_settings': {'ntfy_enabled': true},
});
expect(
_checked(tester, 'ntfy_enabled', cupertino: cupertino),
isTrue,
);
},
testWidgets('shows and writes it', (tester) async {
final gateway = _Gateway(
(type, _) => withNtfy(type == 'set_notification_settings'),
);
}
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(find.text('Also send to ntfy'), findsOneWidget);
expect(find.text(ntfySectionAppSubtitle), findsOneWidget);
expect(_checked(tester, 'ntfy_enabled'), isFalse);
await tester.tap(find.byKey(ntfySettingKey('ntfy_enabled')));
await tester.pumpAndSettle();
expect(gateway.calls.last.$2, {
'notification_settings': {'ntfy_enabled': true},
});
expect(_checked(tester, 'ntfy_enabled'), isTrue);
});
});
}
@@ -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/settings_animation_section.dart';
@@ -18,55 +17,42 @@ class _Store implements QuickSwitchAnimationStore {
}
void main() {
for (final cupertino in [false, true]) {
testWidgets('chooses and saves quick switch animation ($cupertino)', (
tester,
) async {
final store = _Store();
final controller = QuickSwitchAnimationController(store: store);
final speed = AnimationSpeedController();
final child = SettingsAnimationSection(
controller: speed,
quickSwitchController: controller,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
home: CupertinoPageScaffold(
child: SingleChildScrollView(child: child),
),
)
: MaterialApp(
home: Scaffold(body: SingleChildScrollView(child: child)),
),
);
expect(find.text('Quick switch animation'), findsOneWidget);
expect(
cupertino ? find.byType(CupertinoSlider) : find.byType(Slider),
findsOneWidget,
);
await tester.tap(find.text('Tape'));
await tester.pumpAndSettle();
await tester.tap(find.text('Card deck').last);
await tester.pumpAndSettle();
expect(controller.value, QuickSwitchAnimation.cardStack);
expect(store.saved, 'cardStack');
expect(
find.text(QuickSwitchAnimation.cardStack.description),
findsOneWidget,
);
store.success = false;
await tester.tap(find.text('Card deck'));
await tester.pumpAndSettle();
await tester.tap(find.text('Swap').last);
await tester.pumpAndSettle();
expect(
find.text('Could not save; applies until reload.'),
findsOneWidget,
);
expect(tester.takeException(), isNull);
controller.dispose();
speed.dispose();
});
}
testWidgets('chooses and saves quick switch animation', (tester) async {
final store = _Store();
final controller = QuickSwitchAnimationController(store: store);
final speed = AnimationSpeedController();
final child = SettingsAnimationSection(
controller: speed,
quickSwitchController: controller,
);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(body: SingleChildScrollView(child: child)),
),
);
expect(find.text('Quick switch animation'), findsOneWidget);
expect(find.byType(Slider), findsOneWidget);
await tester.tap(find.text('Tape'));
await tester.pumpAndSettle();
await tester.tap(find.text('Card deck').last);
await tester.pumpAndSettle();
expect(controller.value, QuickSwitchAnimation.cardStack);
expect(store.saved, 'cardStack');
expect(
find.text(QuickSwitchAnimation.cardStack.description),
findsOneWidget,
);
store.success = false;
await tester.tap(find.text('Card deck'));
await tester.pumpAndSettle();
await tester.tap(find.text('Swap').last);
await tester.pumpAndSettle();
expect(
find.text('Could not save; applies until reload.'),
findsOneWidget,
);
expect(tester.takeException(), isNull);
controller.dispose();
speed.dispose();
});
}
@@ -11,7 +11,6 @@ import 'package:pipelines_app/features/settings/settings_store.dart';
import 'fake_channel.dart';
import 'settings_topic_test_helper.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
void main() {
testWidgets('renders idle settings without opening a connection', (
@@ -258,23 +257,6 @@ void main() {
expect(find.byKey(SettingsKeys.connect), findsOneWidget);
});
testWidgets('an explicit Cupertino host uses Cupertino fields and buttons', (
tester,
) async {
final factory = FakeChannelFactory();
final client = transport.PipelinesClient(channelFactory: factory.call);
addTearDown(client.dispose);
await _pump(tester, client, cupertino: true);
expect(find.byType(SegmentedBar), findsOneWidget);
expect(find.byType(CupertinoTextField), findsNWidgets(2));
expect(find.byType(TextField), findsNothing);
expect(find.byType(FilledButton), findsNothing);
expect(find.byKey(SettingsKeys.connect), findsOneWidget);
expect(find.text('Trusted LAN/VPN only'), findsOneWidget);
});
testWidgets('narrow window with large text scrolls without overflow', (
tester,
) async {
@@ -375,26 +357,11 @@ Future<void> _pump(
transport.PipelinesClient client, {
SettingsStore? store,
TargetPlatform platform = TargetPlatform.android,
bool cupertino = false,
double textScale = 1,
Size size = const Size(800, 1200),
}) async {
await tester.binding.setSurfaceSize(size);
addTearDown(() => tester.binding.setSurfaceSize(null));
if (cupertino) {
await tester.pumpWidget(
CupertinoApp(
home: SettingsScreen(
client: client,
store: store ?? MemorySettingsStore(),
),
),
);
await tester.pump();
await tester.pump();
await selectSettingsTopic(tester, 'Connection');
return;
}
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: platform),