Merge commit '8b1ca066aca07861622b4b1350b7988531ccd5e0' into pipelines/run-20261111-0456-cupertino-out-runs-ui-part-1-2ad5

This commit is contained in:
2026-11-11 05:29:23 +00:00
35 changed files with 716 additions and 1497 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/core/api_gateway.dart';
@@ -12,11 +11,6 @@ Widget _host(Widget child) => MaterialApp(
home: Scaffold(body: child),
);
Widget _cupertinoHost(Widget child) => CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoPageScaffold(child: child),
);
JsonMap _usageFrame(JsonMap usage) => {
'session_id': 's',
'kind': 'usage',
@@ -49,10 +43,7 @@ JsonMap _claudeAccount(DateTime now) => {
],
};
Future<FakeChatGateway> _thread(
WidgetTester tester, {
bool cupertino = false,
}) async {
Future<FakeChatGateway> _thread(WidgetTester tester) async {
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => chatPage([]);
@@ -61,7 +52,7 @@ Future<FakeChatGateway> _thread(
sessionId: 's',
onBack: () {},
);
await tester.pumpWidget(cupertino ? _cupertinoHost(thread) : _host(thread));
await tester.pumpWidget(_host(thread));
await tester.pumpAndSettle();
return gateway;
}
@@ -141,69 +132,62 @@ void main() {
});
// Chat details is Material only (a dialog, or a sheet on a phone).
for (final cupertino in [false]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('$host: account usage shows windows, plan and age', (
tester,
) async {
final gateway = await _thread(tester, cupertino: cupertino);
gateway.emitEvent(
_usageFrame({
'scope': 'session',
'total_tokens': 1200,
'account': _claudeAccount(DateTime.now()),
}),
);
await tester.pump();
await _openInfo(tester);
expect(find.text('Account usage'), findsOneWidget);
expect(find.text('Claude Code · Max plan'), findsOneWidget);
expect(find.text('5-hour'), findsOneWidget);
expect(find.text('42% used · resets in 2h 14m'), findsOneWidget);
expect(find.text('Weekly'), findsOneWidget);
expect(find.text('93% used · resets in 3d 5h'), findsOneWidget);
expect(find.text('as of just now'), findsOneWidget);
final bars = tester
.widgetList<LinearProgressIndicator>(
find.byType(LinearProgressIndicator),
)
.toList();
expect(bars.map((bar) => bar.value), [
closeTo(.42, 1e-9),
closeTo(.934, 1e-9),
]);
expect(bars.first.semanticsLabel, '5-hour quota');
// Token metrics are still shown beside the quota.
expect(find.text('1,200'), findsOneWidget);
});
testWidgets(
'$host: unknown quota hides the section; no-API harness says so',
(tester) async {
final gateway = await _thread(tester, cupertino: cupertino);
gateway.emitEvent(_usageFrame({'scope': 'session', 'total_tokens': 5}));
await tester.pump();
await _openInfo(tester);
expect(find.byKey(const Key('chat-account-usage')), findsNothing);
expect(find.text('Account usage'), findsNothing);
expect(find.byType(LinearProgressIndicator), findsNothing);
gateway.emitEvent(
_usageFrame({
'scope': 'session',
'total_tokens': 6,
'account': {'harness': 'OpenCode', 'unsupported': true},
}),
);
await tester.pumpAndSettle();
expect(find.text('Account usage'), findsOneWidget);
expect(find.text('Not reported by OpenCode'), findsOneWidget);
expect(find.byType(LinearProgressIndicator), findsNothing);
},
testWidgets('account usage shows windows, plan and age', (tester) async {
final gateway = await _thread(tester);
gateway.emitEvent(
_usageFrame({
'scope': 'session',
'total_tokens': 1200,
'account': _claudeAccount(DateTime.now()),
}),
);
}
await tester.pump();
await _openInfo(tester);
expect(find.text('Account usage'), findsOneWidget);
expect(find.text('Claude Code · Max plan'), findsOneWidget);
expect(find.text('5-hour'), findsOneWidget);
expect(find.text('42% used · resets in 2h 14m'), findsOneWidget);
expect(find.text('Weekly'), findsOneWidget);
expect(find.text('93% used · resets in 3d 5h'), findsOneWidget);
expect(find.text('as of just now'), findsOneWidget);
final bars = tester
.widgetList<LinearProgressIndicator>(
find.byType(LinearProgressIndicator),
)
.toList();
expect(bars.map((bar) => bar.value), [
closeTo(.42, 1e-9),
closeTo(.934, 1e-9),
]);
expect(bars.first.semanticsLabel, '5-hour quota');
// Token metrics are still shown beside the quota.
expect(find.text('1,200'), findsOneWidget);
});
testWidgets('unknown quota hides the section; no-API harness says so', (
tester,
) async {
final gateway = await _thread(tester);
gateway.emitEvent(_usageFrame({'scope': 'session', 'total_tokens': 5}));
await tester.pump();
await _openInfo(tester);
expect(find.byKey(const Key('chat-account-usage')), findsNothing);
expect(find.text('Account usage'), findsNothing);
expect(find.byType(LinearProgressIndicator), findsNothing);
gateway.emitEvent(
_usageFrame({
'scope': 'session',
'total_tokens': 6,
'account': {'harness': 'OpenCode', 'unsupported': true},
}),
);
await tester.pumpAndSettle();
expect(find.text('Account usage'), findsOneWidget);
expect(find.text('Not reported by OpenCode'), findsOneWidget);
expect(find.byType(LinearProgressIndicator), findsNothing);
});
testWidgets('an account-only frame keeps the recorded token metrics', (
tester,
@@ -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/conversation/chat_background_tasks_controller.dart';
@@ -8,85 +7,75 @@ import 'package:pipelines_app/features/chat/conversation/chat_task_metadata_view
import 'chat_background_tasks_fixtures.dart';
void main() {
for (final cupertino in [false, true]) {
testWidgets(
'recorded facts wrap at 2x, tick without requests, dispose clock ($cupertino)',
(tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
var now = DateTime.utc(2026, 11, 6, 10);
var clockReads = 0;
final gateway = TasksGateway()
..shells = (_) async => {
'chat_shells': [
{
'id': 'a',
'status': 'running',
'command': 'Review integration changes',
'started_at': now
.subtract(const Duration(minutes: 2))
.millisecondsSinceEpoch,
'progress':
'Checking the targeted tests and reviewing the remaining findings',
'tool_count': 18,
'token_count': 12450,
},
],
};
final controller = ChatBackgroundTasksController(gateway, 's');
addTearDown(controller.dispose);
addTearDown(gateway.close);
final panel = ChatBackgroundTasksPanel(
controller: controller,
clock: () {
clockReads++;
return now;
testWidgets('recorded facts wrap at 2x, tick without requests, dispose clock', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
var now = DateTime.utc(2026, 11, 6, 10);
var clockReads = 0;
final gateway = TasksGateway()
..shells = (_) async => {
'chat_shells': [
{
'id': 'a',
'status': 'running',
'command': 'Review integration changes',
'started_at': now
.subtract(const Duration(minutes: 2))
.millisecondsSinceEpoch,
'progress':
'Checking the targeted tests and reviewing the remaining findings',
'tool_count': 18,
'token_count': 12450,
},
);
Widget builder(BuildContext context, Widget? child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: const TextScaler.linear(2)),
child: child!,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
builder: builder,
home: CupertinoPageScaffold(
child: SingleChildScrollView(child: panel),
),
)
: MaterialApp(
builder: builder,
home: Scaffold(body: SingleChildScrollView(child: panel)),
),
);
await tester.pumpAndSettle();
expect(find.text('2m 0s'), findsOneWidget);
expect(find.text('18'), findsOneWidget);
expect(find.text('12,450'), findsOneWidget);
expect(find.textContaining('6 November 2026'), findsOneWidget);
final requests = gateway.calls.length;
now = now.add(const Duration(seconds: 11));
await tester.pump(const Duration(seconds: 11));
expect(find.text('2m 11s'), findsOneWidget);
expect(gateway.calls.length, requests);
expect(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
isEmpty,
);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
final stoppedAt = clockReads;
await tester.pump(const Duration(seconds: 11));
expect(clockReads, stoppedAt);
expect(tester.takeException(), isNull);
],
};
final controller = ChatBackgroundTasksController(gateway, 's');
addTearDown(controller.dispose);
addTearDown(gateway.close);
final panel = ChatBackgroundTasksPanel(
controller: controller,
clock: () {
clockReads++;
return now;
},
);
}
Widget builder(BuildContext context, Widget? child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: const TextScaler.linear(2)),
child: child!,
);
await tester.pumpWidget(
MaterialApp(
builder: builder,
home: Scaffold(body: SingleChildScrollView(child: panel)),
),
);
await tester.pumpAndSettle();
expect(find.text('2m 0s'), findsOneWidget);
expect(find.text('18'), findsOneWidget);
expect(find.text('12,450'), findsOneWidget);
expect(find.textContaining('6 November 2026'), findsOneWidget);
final requests = gateway.calls.length;
now = now.add(const Duration(seconds: 11));
await tester.pump(const Duration(seconds: 11));
expect(find.text('2m 11s'), findsOneWidget);
expect(gateway.calls.length, requests);
expect(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
isEmpty,
);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
final stoppedAt = clockReads;
await tester.pump(const Duration(seconds: 11));
expect(clockReads, stoppedAt);
expect(tester.takeException(), isNull);
});
testWidgets(
'selected detail keeps full metadata and requests only its output',
@@ -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/conversation/chat_background_task_card.dart';
@@ -36,74 +35,68 @@ void main() {
},
);
for (final cupertino in [false, true]) {
testWidgets(
'one task has GUI hierarchy, no duplicate path, explicit lazy details ($cupertino)',
(tester) async {
tester.view.physicalSize = const Size(560, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final now = DateTime.utc(2026, 11, 6, 23, 44, 40);
final gateway = TasksGateway()
..shells = (_) async => {
'chat_shells': [
{
'id': 'example',
'status': 'running',
'task_type': 'local_agent',
'command': example,
'description': example,
'progress': example,
'started_at': now
.subtract(const Duration(minutes: 4, seconds: 40))
.millisecondsSinceEpoch,
'tool_count': 37,
'token_count': 120905,
},
],
};
final controller = ChatBackgroundTasksController(gateway, 's');
addTearDown(controller.dispose);
addTearDown(gateway.close);
final panel = SingleChildScrollView(
child: ChatBackgroundTasksPanel(
controller: controller,
clock: () => now,
),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: panel))
: MaterialApp(home: Scaffold(body: panel)),
);
await tester.pumpAndSettle();
expect(find.byType(ChatBackgroundTaskCard), findsOneWidget);
expect(find.byType(ChatTaskSurface), findsOneWidget);
expect(find.text(example), findsOneWidget);
expect(find.text('4m 40s'), findsOneWidget);
expect(find.text('Running'), findsOneWidget);
expect(find.text('120,905'), findsOneWidget);
expect(find.text('Tokens'), findsOneWidget);
expect(find.text('37'), findsOneWidget);
expect(find.text('Tool calls'), findsOneWidget);
expect(find.text('Details'), findsOneWidget);
expect(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
isEmpty,
);
await tester.tap(find.byKey(const ValueKey('chat-bg-task-example')));
await tester.pumpAndSettle();
expect(find.text(example), findsOneWidget);
expect(find.text('Hide details'), findsOneWidget);
expect(find.text('Output'), findsOneWidget);
expect(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
hasLength(1),
);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
},
);
}
testWidgets(
'one task has GUI hierarchy, no duplicate path, explicit lazy details',
(tester) async {
tester.view.physicalSize = const Size(560, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final now = DateTime.utc(2026, 11, 6, 23, 44, 40);
final gateway = TasksGateway()
..shells = (_) async => {
'chat_shells': [
{
'id': 'example',
'status': 'running',
'task_type': 'local_agent',
'command': example,
'description': example,
'progress': example,
'started_at': now
.subtract(const Duration(minutes: 4, seconds: 40))
.millisecondsSinceEpoch,
'tool_count': 37,
'token_count': 120905,
},
],
};
final controller = ChatBackgroundTasksController(gateway, 's');
addTearDown(controller.dispose);
addTearDown(gateway.close);
final panel = SingleChildScrollView(
child: ChatBackgroundTasksPanel(
controller: controller,
clock: () => now,
),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: panel)));
await tester.pumpAndSettle();
expect(find.byType(ChatBackgroundTaskCard), findsOneWidget);
expect(find.byType(ChatTaskSurface), findsOneWidget);
expect(find.text(example), findsOneWidget);
expect(find.text('4m 40s'), findsOneWidget);
expect(find.text('Running'), findsOneWidget);
expect(find.text('120,905'), findsOneWidget);
expect(find.text('Tokens'), findsOneWidget);
expect(find.text('37'), findsOneWidget);
expect(find.text('Tool calls'), findsOneWidget);
expect(find.text('Details'), findsOneWidget);
expect(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
isEmpty,
);
await tester.tap(find.byKey(const ValueKey('chat-bg-task-example')));
await tester.pumpAndSettle();
expect(find.text(example), findsOneWidget);
expect(find.text('Hide details'), findsOneWidget);
expect(find.text('Output'), findsOneWidget);
expect(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
hasLength(1),
);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
},
);
}
@@ -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';
@@ -8,15 +7,9 @@ import 'package:pipelines_app/features/chat/conversation/chat_background_tasks.d
import 'chat_background_tasks_fixtures.dart';
Widget host(
TasksGateway gateway, {
bool cupertino = false,
String session = 's',
}) {
Widget host(TasksGateway gateway, {String session = 's'}) {
final button = ChatBackgroundTasks(gateway: gateway, sessionId: session);
return cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: button))
: MaterialApp(home: Scaffold(body: button));
return MaterialApp(home: Scaffold(body: button));
}
Future<void> open(WidgetTester tester) async {
@@ -25,86 +18,75 @@ Future<void> open(WidgetTester tester) async {
}
void main() {
for (final cupertino in [false, true]) {
testWidgets(
'count updates live, no eager output, Back/Done only close modal ($cupertino)',
(tester) async {
final gateway = TasksGateway()
..shells = (_) async => {
'chat_shells': [task('a')],
};
addTearDown(gateway.close);
await tester.pumpWidget(host(gateway, cupertino: cupertino));
await tester.pumpAndSettle();
expect(find.text('1 task'), findsOneWidget);
expect(find.text('command a'), findsNothing);
expect(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
isEmpty,
);
await open(tester);
expect(find.text('command a'), findsOneWidget);
gateway.shell('b', 'running');
await tester.pumpAndSettle();
expect(find.text('2 running'), findsOneWidget);
expect(find.text('command b'), findsOneWidget);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(
find.byKey(const Key('chat-background-tasks-modal')),
findsNothing,
);
expect(find.text('2 tasks'), findsOneWidget);
await open(tester);
await tester.tap(find.text('Done'));
await tester.pumpAndSettle();
expect(find.text('2 tasks'), findsOneWidget);
expect(
gateway.calls.where((call) => call.type == 'chat_shells'),
hasLength(1),
);
},
);
testWidgets(
'count updates live, no eager output, Back/Done only close modal',
(tester) async {
final gateway = TasksGateway()
..shells = (_) async => {
'chat_shells': [task('a')],
};
addTearDown(gateway.close);
await tester.pumpWidget(host(gateway));
await tester.pumpAndSettle();
expect(find.text('1 task'), findsOneWidget);
expect(find.text('command a'), findsNothing);
expect(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
isEmpty,
);
await open(tester);
expect(find.text('command a'), findsOneWidget);
gateway.shell('b', 'running');
await tester.pumpAndSettle();
expect(find.text('2 running'), findsOneWidget);
expect(find.text('command b'), findsOneWidget);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(
find.byKey(const Key('chat-background-tasks-modal')),
findsNothing,
);
expect(find.text('2 tasks'), findsOneWidget);
await open(tester);
await tester.tap(find.text('Done'));
await tester.pumpAndSettle();
expect(find.text('2 tasks'), findsOneWidget);
expect(
gateway.calls.where((call) => call.type == 'chat_shells'),
hasLength(1),
);
},
);
testWidgets(
'session switch closes its own modal and drops late output ($cupertino)',
(tester) async {
final gateway = TasksGateway()
..shells = (_) async => {
'chat_shells': [task('a')],
};
final page = Completer<JsonMap>();
gateway.output = (_) => page.future;
addTearDown(gateway.close);
await tester.pumpWidget(host(gateway, cupertino: cupertino));
await tester.pumpAndSettle();
await open(tester);
await tester.tap(find.byKey(const ValueKey('chat-bg-task-a')));
await tester.pump();
gateway.shells = (_) async => {'chat_shells': []};
await tester.pumpWidget(
host(gateway, cupertino: cupertino, session: 'other'),
);
await tester.pumpAndSettle();
page.complete({
'chat_shell_output': {'output': 'old session output'},
});
await tester.pumpAndSettle();
expect(
find.byKey(const Key('chat-background-tasks-modal')),
findsNothing,
);
// The other session runs nothing: no control, never a "0 tasks".
expect(find.text('0 tasks'), findsNothing);
expect(
find.byKey(const Key('chat-background-tasks-button')),
findsNothing,
);
expect(find.text('old session output'), findsNothing);
expect(tester.takeException(), isNull);
},
);
}
testWidgets('session switch closes its own modal and drops late output', (
tester,
) async {
final gateway = TasksGateway()
..shells = (_) async => {
'chat_shells': [task('a')],
};
final page = Completer<JsonMap>();
gateway.output = (_) => page.future;
addTearDown(gateway.close);
await tester.pumpWidget(host(gateway));
await tester.pumpAndSettle();
await open(tester);
await tester.tap(find.byKey(const ValueKey('chat-bg-task-a')));
await tester.pump();
gateway.shells = (_) async => {'chat_shells': []};
await tester.pumpWidget(host(gateway, session: 'other'));
await tester.pumpAndSettle();
page.complete({
'chat_shell_output': {'output': 'old session output'},
});
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-background-tasks-modal')), findsNothing);
// The other session runs nothing: no control, never a "0 tasks".
expect(find.text('0 tasks'), findsNothing);
expect(find.byKey(const Key('chat-background-tasks-button')), findsNothing);
expect(find.text('old session output'), findsNothing);
expect(tester.takeException(), isNull);
});
testWidgets(
'owner disposal removes only its modal, not an unrelated top route',
@@ -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';
@@ -88,21 +87,12 @@ List<String> _pageLines() => [
for (var index = 0; index < 200; index++) 'line $index',
];
Widget _host(
_TasksGateway gateway, {
bool cupertino = false,
int syncToken = 0,
}) {
Widget _host(_TasksGateway gateway, {int syncToken = 0}) {
final child = ChatBackgroundTasks(
gateway: gateway,
sessionId: 's',
syncToken: syncToken,
);
if (cupertino) {
return CupertinoApp(
home: CupertinoPageScaffold(child: SingleChildScrollView(child: child)),
);
}
return MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: Scaffold(body: SingleChildScrollView(child: child)),
@@ -431,37 +421,6 @@ void main() {
expect(gateway.fieldsFor('chat_shells'), hasLength(2));
});
testWidgets('the Cupertino host keeps native buttons and the same facts', (
tester,
) async {
final gateway = _TasksGateway();
gateway.shells = () async => _snapshot([_running('sh1')]);
gateway.output = (_) async => {
'chat_shell_output': {
'shell': _running('sh1'),
'output': 'native output',
},
};
addTearDown(gateway.close);
await tester.pumpWidget(_host(gateway, cupertino: true));
await tester.pumpAndSettle();
await _openTasks(tester);
expect(find.byType(CupertinoButton), findsWidgets);
expect(find.text('1 running'), findsOneWidget);
await _tapTask(tester, 'sh1');
expect(find.text('Command'), findsNothing);
expect(find.text('Running'), findsOneWidget);
expect(
tester
.widget<SelectableText>(find.byKey(const Key('chat-bg-task-output')))
.data,
'native output',
);
});
testWidgets('a long output page scrolls inside a bounded pane', (
tester,
) async {
@@ -598,37 +557,6 @@ void main() {
expect(composer.bottom, lessThanOrEqualTo(568));
});
testWidgets('the Cupertino row elides its labels instead of overflowing', (
tester,
) async {
tester.view.physicalSize = const Size(320, 568);
tester.view.devicePixelRatio = 1;
tester.platformDispatcher.textScaleFactorTestValue = 2;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
final gateway = _TasksGateway();
gateway.shells = () async => _snapshot([
_running('sh1', command: 'go test ./... -run TestSomethingLongEnough'),
]);
gateway.output = (_) async => {
'chat_shell_output': {
'shell': _running('sh1'),
'output': 'native output',
},
};
addTearDown(gateway.close);
await tester.pumpWidget(_host(gateway, cupertino: true));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
await _tapTask(tester, 'sh1');
expect(tester.takeException(), isNull);
expect(find.text('Task identity'), findsOneWidget);
});
testWidgets('the conversation mounts only the live task badge', (
tester,
) async {
@@ -1,7 +1,6 @@
import 'dart:io';
import 'dart:math' as math;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_bar_tint.dart';
@@ -25,25 +24,19 @@ double _ratio(Color a, Color b) {
/// The colours one host draws a chat's bar and composer with.
typedef _Host = ({Color page, Color raised, Color shade});
/// Every palette colour's shade on one host and brightness, read through
/// Every palette colour's shade on one brightness, read through
/// the app's own [chatColorShade] under the app's theme.
Future<Map<String, _Host>> _hostColours(
WidgetTester tester, {
required bool cupertino,
required bool dark,
}) async {
final result = <String, _Host>{};
final brightness = dark ? Brightness.dark : Brightness.light;
Widget probe() => Builder(
builder: (context) {
for (final name in chatColorNames) {
result[name] = (
page: cupertino
? AppColors.background.resolveFrom(context)
: Theme.of(context).colorScheme.surface,
raised: cupertino
? CupertinoColors.systemGrey5.resolveFrom(context)
: Theme.of(context).colorScheme.surfaceContainerHigh,
page: Theme.of(context).colorScheme.surface,
raised: Theme.of(context).colorScheme.surfaceContainerHigh,
shade: chatColorShade(context, name)!,
);
}
@@ -51,91 +44,76 @@ Future<Map<String, _Host>> _hostColours(
},
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
theme: appCupertinoTheme.copyWith(brightness: brightness),
home: probe(),
)
: MaterialApp(
theme: dark ? appDarkTheme() : appLightTheme(),
home: probe(),
),
MaterialApp(theme: dark ? appDarkTheme() : appLightTheme(), home: probe()),
);
return result;
}
void main() {
final rows = <String>['host\ttheme\tcolour\tmeasure\tratio\tminimum'];
final rows = <String>['theme\tcolour\tmeasure\tratio\tminimum'];
tearDownAll(() {
final out = Platform.environment['CHAT_BAR_CONTRAST_OUT'];
if (out != null) File(out).writeAsStringSync('${rows.join('\n')}\n');
});
for (final cupertino in [false, true]) {
for (final dark in [false, true]) {
final host = cupertino ? 'cupertino' : 'material';
final theme = dark ? 'dark' : 'light';
testWidgets('$host $theme: every chat colour meets AA in the bar and '
'the focus ring', (tester) async {
final colours = await _hostColours(
tester,
cupertino: cupertino,
dark: dark,
for (final dark in [false, true]) {
final theme = dark ? 'dark' : 'light';
testWidgets('$theme: every chat colour meets AA in the bar and '
'the focus ring', (tester) async {
final colours = await _hostColours(tester, dark: dark);
expect(colours.keys, chatColorNames);
void check(String name, String what, double ratio, double minimum) {
rows.add(
'$theme\t$name\t$what\t'
'${ratio.toStringAsFixed(2)}\t$minimum',
);
expect(colours.keys, chatColorNames);
void check(String name, String what, double ratio, double minimum) {
rows.add(
'$host\t$theme\t$name\t$what\t'
'${ratio.toStringAsFixed(2)}\t$minimum',
);
expect(
ratio,
greaterThanOrEqualTo(minimum),
reason: '$host $theme $name: $what',
);
}
expect(
ratio,
greaterThanOrEqualTo(minimum),
reason: '$theme $name: $what',
);
}
for (final MapEntry(key: name, value: c) in colours.entries) {
for (final inactive in [false, true]) {
final tint = ChatBarTint.from(
shade: c.shade,
raised: c.raised,
dark: dark,
inactive: inactive,
);
// The glass lies over the bar's scrim, the page's colour.
final pill = Color.alphaBlend(tint.fill, c.page);
check(
name,
inactive ? 'inactive bar label' : 'bar label',
_ratio(tint.foreground, pill),
4.5,
);
// Solid under the system's high-contrast setting.
final solid = ChatBarTint.from(
shade: c.shade,
raised: c.raised,
dark: dark,
inactive: inactive,
solid: true,
);
check(
name,
inactive ? 'inactive solid bar label' : 'solid bar label',
_ratio(solid.foreground, solid.fill),
4.5,
);
}
final ring = chatSeededScheme(c.shade, dark: dark).primary;
check(name, 'focus ring vs page', _ratio(ring, c.page), 3);
final composer = Color.alphaBlend(
c.raised.withValues(alpha: GlassPill.fillOpacity),
c.page,
for (final MapEntry(key: name, value: c) in colours.entries) {
for (final inactive in [false, true]) {
final tint = ChatBarTint.from(
shade: c.shade,
raised: c.raised,
dark: dark,
inactive: inactive,
);
// The glass lies over the bar's scrim, the page's colour.
final pill = Color.alphaBlend(tint.fill, c.page);
check(
name,
inactive ? 'inactive bar label' : 'bar label',
_ratio(tint.foreground, pill),
4.5,
);
// Solid under the system's high-contrast setting.
final solid = ChatBarTint.from(
shade: c.shade,
raised: c.raised,
dark: dark,
inactive: inactive,
solid: true,
);
check(
name,
inactive ? 'inactive solid bar label' : 'solid bar label',
_ratio(solid.foreground, solid.fill),
4.5,
);
check(name, 'focus ring vs composer', _ratio(ring, composer), 3);
}
});
}
final ring = chatSeededScheme(c.shade, dark: dark).primary;
check(name, 'focus ring vs page', _ratio(ring, c.page), 3);
final composer = Color.alphaBlend(
c.raised.withValues(alpha: GlassPill.fillOpacity),
c.page,
);
check(name, 'focus ring vs composer', _ratio(ring, composer), 3);
}
});
}
}
@@ -13,7 +13,6 @@ import 'package:pipelines_app/ui/theme/app_theme.dart';
/// A header in the app's theme, with one model-style control, Files, and an
/// optional split-pane activity around it.
Widget _header({
required bool cupertino,
String? color,
Brightness brightness = Brightness.light,
bool? inactive,
@@ -27,16 +26,11 @@ Widget _header({
chatColor: color,
controls: [
Builder(
builder: (context) => cupertino
? CupertinoButton(
onPressed: () {},
child: chatBarCupertinoContent(context, const Text('Model')),
)
: TextButton(
style: chatBarTextButtonStyle(context),
onPressed: () {},
child: const Text('Model'),
),
builder: (context) => TextButton(
style: chatBarTextButtonStyle(context),
onPressed: () {},
child: const Text('Model'),
),
),
],
actions: [
@@ -55,22 +49,14 @@ Widget _header({
alignment: Alignment.topCenter,
child: SizedBox(width: 900, height: 120, child: header),
);
return cupertino
? CupertinoApp(
theme: appCupertinoTheme.copyWith(brightness: brightness),
home: CupertinoPageScaffold(child: body),
)
: MaterialApp(
theme: brightness == Brightness.dark
? appDarkTheme()
: appLightTheme(),
home: Scaffold(body: body),
);
return MaterialApp(
theme: brightness == Brightness.dark ? appDarkTheme() : appLightTheme(),
home: Scaffold(body: body),
);
}
Future<BuildContext> _pump(
WidgetTester tester, {
required bool cupertino,
String? color,
Brightness brightness = Brightness.light,
bool? inactive,
@@ -80,12 +66,7 @@ Future<BuildContext> _pump(
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
_header(
cupertino: cupertino,
color: color,
brightness: brightness,
inactive: inactive,
),
_header(color: color, brightness: brightness, inactive: inactive),
);
await tester.pumpAndSettle();
return tester.element(find.byType(ChatThreadHeader));
@@ -113,113 +94,91 @@ final _files = find.byType(ChatBarAction);
final _back = find.byKey(const Key('chat-back'));
void main() {
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('$host: a chat with no colour keeps the neutral bar', (
tester,
) async {
final context = await _pump(tester, cupertino: cupertino);
expect(find.byKey(const Key('chat-bar-tint')), findsNothing);
expect(find.byType(ChatBarTintScope), findsNothing);
expect(_titleFill(tester), isNull);
for (final pill in tester.widgetList<GlassPill>(find.byType(GlassPill))) {
expect(pill.fill, isNull);
}
final neutral = cupertino
? CupertinoColors.label.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
expect(_textColor(tester, 'Model'), isSameColorAs(neutral));
});
for (final brightness in Brightness.values) {
testWidgets('$host ${brightness.name}: a coloured chat tints every '
'glass piece and takes its foreground', (tester) async {
final context = await _pump(
tester,
cupertino: cupertino,
color: 'teal',
brightness: brightness,
);
final dark = brightness == Brightness.dark;
final shade = chatColorShade(context, 'teal')!;
final raised = cupertino
? CupertinoColors.systemGrey5.resolveFrom(context)
: Theme.of(context).colorScheme.surfaceContainerHigh;
final expected = ChatBarTint.from(
shade: shade,
raised: raised,
dark: dark,
);
expect(expected.fill.a, closeTo(GlassPill.fillOpacity, 1e-6));
expect(
expected.fill.withValues(alpha: 1),
Color.alphaBlend(
shade.withValues(alpha: dark ? chatBarTintDark : chatBarTintLight),
raised,
),
);
expect(
expected.foreground,
chatSeededScheme(shade, dark: dark).onPrimaryContainer,
);
expect(find.byKey(const Key('chat-bar-tint')), findsOneWidget);
// Back, title, the control island and the Files island.
final pills = tester.widgetList<GlassPill>(find.byType(GlassPill));
expect(pills.length, greaterThanOrEqualTo(4));
for (final pill in pills) {
expect(pill.fill, expected.fill);
}
expect(_titleFill(tester), expected.fill);
expect(_textColor(tester, 'Colour chat'), expected.foreground);
expect(_textColor(tester, 'Model'), expected.foreground);
expect(_iconIn(tester, _files), expected.foreground);
});
testWidgets('a chat with no colour keeps the neutral bar', (tester) async {
final context = await _pump(tester);
expect(find.byKey(const Key('chat-bar-tint')), findsNothing);
expect(find.byType(ChatBarTintScope), findsNothing);
expect(_titleFill(tester), isNull);
for (final pill in tester.widgetList<GlassPill>(find.byType(GlassPill))) {
expect(pill.fill, isNull);
}
final neutral = Theme.of(context).colorScheme.onSurfaceVariant;
expect(_textColor(tester, 'Model'), isSameColorAs(neutral));
});
testWidgets('$host: an inactive split pane fades its bar tint to half', (
tester,
) async {
for (final brightness in Brightness.values) {
testWidgets('${brightness.name}: a coloured chat tints every '
'glass piece and takes its foreground', (tester) async {
final context = await _pump(
tester,
cupertino: cupertino,
color: 'orange',
inactive: true,
color: 'teal',
brightness: brightness,
);
final shade = chatColorShade(context, 'orange')!;
final raised = cupertino
? CupertinoColors.systemGrey5.resolveFrom(context)
: Theme.of(context).colorScheme.surfaceContainerHigh;
final faded = ChatBarTint.from(
final dark = brightness == Brightness.dark;
final shade = chatColorShade(context, 'teal')!;
final raised = Theme.of(context).colorScheme.surfaceContainerHigh;
final expected = ChatBarTint.from(
shade: shade,
raised: raised,
dark: false,
inactive: true,
dark: dark,
);
expect(expected.fill.a, closeTo(GlassPill.fillOpacity, 1e-6));
expect(
faded.fill.withValues(alpha: 1),
expected.fill.withValues(alpha: 1),
Color.alphaBlend(
shade.withValues(alpha: chatBarTintLight * chatBarInactiveFade),
shade.withValues(alpha: dark ? chatBarTintDark : chatBarTintLight),
raised,
),
);
expect(_titleFill(tester), faded.fill);
// The same pane turning active takes the full tint.
await tester.pumpWidget(
_header(cupertino: cupertino, color: 'orange', inactive: false),
expect(
expected.foreground,
chatSeededScheme(shade, dark: dark).onPrimaryContainer,
);
await tester.pumpAndSettle();
final full = ChatBarTint.from(shade: shade, raised: raised, dark: false);
expect(_titleFill(tester), full.fill);
expect(full.fill, isNot(faded.fill));
expect(find.byKey(const Key('chat-bar-tint')), findsOneWidget);
// Back, title, the control island and the Files island.
final pills = tester.widgetList<GlassPill>(find.byType(GlassPill));
expect(pills.length, greaterThanOrEqualTo(4));
for (final pill in pills) {
expect(pill.fill, expected.fill);
}
expect(_titleFill(tester), expected.fill);
expect(_textColor(tester, 'Colour chat'), expected.foreground);
expect(_textColor(tester, 'Model'), expected.foreground);
expect(_iconIn(tester, _files), expected.foreground);
});
}
testWidgets('Material: bar icons take the seeded onPrimaryContainer', (
testWidgets('an inactive split pane fades its bar tint to half', (
tester,
) async {
final context = await _pump(tester, cupertino: false, color: 'purple');
final context = await _pump(tester, color: 'orange', inactive: true);
final shade = chatColorShade(context, 'orange')!;
final raised = Theme.of(context).colorScheme.surfaceContainerHigh;
final faded = ChatBarTint.from(
shade: shade,
raised: raised,
dark: false,
inactive: true,
);
expect(
faded.fill.withValues(alpha: 1),
Color.alphaBlend(
shade.withValues(alpha: chatBarTintLight * chatBarInactiveFade),
raised,
),
);
expect(_titleFill(tester), faded.fill);
// The same pane turning active takes the full tint.
await tester.pumpWidget(_header(color: 'orange', inactive: false));
await tester.pumpAndSettle();
final full = ChatBarTint.from(shade: shade, raised: raised, dark: false);
expect(_titleFill(tester), full.fill);
expect(full.fill, isNot(faded.fill));
});
testWidgets('bar icons take the seeded onPrimaryContainer', (tester) async {
final context = await _pump(tester, color: 'purple');
final shade = chatColorShade(context, 'purple')!;
final foreground = ColorScheme.fromSeed(
seedColor: shade,
@@ -227,23 +186,4 @@ void main() {
expect(_iconIn(tester, _back), foreground);
expect(_iconIn(tester, _files), foreground);
});
testWidgets('Cupertino: the colour is the bar tint, so Back and Files take '
'it natively', (tester) async {
final context = await _pump(tester, cupertino: true, color: 'purple');
final tint = chatBarTintOf(context, 'purple')!;
final inBar = tester.element(_files);
expect(CupertinoTheme.of(inBar).primaryColor, tint.foreground);
expect(_iconIn(tester, _files), tint.foreground);
// The stock Back draws its chevron in its text style's colour.
final chevron = tester.element(
find.descendant(of: _back, matching: find.byType(RichText)).first,
);
expect(
DefaultTextStyle.of(chevron).style.color,
isSameColorAs(tint.foreground),
);
// Outside the bar the theme's tint is untouched.
expect(CupertinoTheme.of(context).primaryColor, isNot(tint.foreground));
});
}
@@ -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/conversation/chat_bar_tint.dart';
@@ -123,17 +122,4 @@ void main() {
await tester.pumpAndSettle();
expect(_ring(tester).side.color.a, 0);
});
testWidgets('Cupertino composer rings in the theme primary colour', (
tester,
) async {
await tester.pumpWidget(composerThread(gateway, cupertino: true));
await tester.pumpAndSettle();
await _focusField(tester);
final primary = CupertinoTheme.of(
tester.element(find.byKey(const Key('chat-composer-field'))),
).primaryColor;
expect(_ring(tester).side.color, isSameColorAs(primary));
});
}
@@ -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/conversation/chat_thread_view.dart';
@@ -8,57 +7,48 @@ import 'chat_thread_fixtures.dart';
void main() {
// Chat details is Material only (a dialog, or a sheet on a phone).
for (final cupertino in [false]) {
testWidgets(
'usage updates leave transcript widgets alone but refresh Info ($cupertino)',
(tester) async {
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => chatPage([
chatMessage(
'a1',
'assistant',
parts: [
{'type': 'text', 'text': '**Existing answer**'},
],
),
]);
final thread = ChatThreadView(
gateway: gateway,
sessionId: 's',
onBack: () {},
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: thread))
: MaterialApp(home: Scaffold(body: thread)),
);
await tester.pumpAndSettle();
final answer = tester.widget<ChatMessageView>(
find.byType(ChatMessageView),
);
gateway.emitEvent({
'session_id': 's',
'kind': 'usage',
'usage': {'scope': 'session', 'total_tokens': 123},
});
await tester.pumpAndSettle();
expect(
tester.widget<ChatMessageView>(find.byType(ChatMessageView)),
same(answer),
);
await tester.tap(find.byKey(const Key('chat-info')));
await tester.pumpAndSettle();
expect(find.text('123'), findsOneWidget);
gateway.emitEvent({
'session_id': 's',
'kind': 'usage',
'usage': {'scope': 'session', 'total_tokens': 456},
});
await tester.pumpAndSettle();
expect(find.text('456'), findsOneWidget);
expect(find.text('123'), findsNothing);
},
testWidgets('usage updates leave transcript widgets alone but refresh Info', (
tester,
) async {
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => chatPage([
chatMessage(
'a1',
'assistant',
parts: [
{'type': 'text', 'text': '**Existing answer**'},
],
),
]);
final thread = ChatThreadView(
gateway: gateway,
sessionId: 's',
onBack: () {},
);
}
await tester.pumpWidget(MaterialApp(home: Scaffold(body: thread)));
await tester.pumpAndSettle();
final answer = tester.widget<ChatMessageView>(find.byType(ChatMessageView));
gateway.emitEvent({
'session_id': 's',
'kind': 'usage',
'usage': {'scope': 'session', 'total_tokens': 123},
});
await tester.pumpAndSettle();
expect(
tester.widget<ChatMessageView>(find.byType(ChatMessageView)),
same(answer),
);
await tester.tap(find.byKey(const Key('chat-info')));
await tester.pumpAndSettle();
expect(find.text('123'), findsOneWidget);
gateway.emitEvent({
'session_id': 's',
'kind': 'usage',
'usage': {'scope': 'session', 'total_tokens': 456},
});
await tester.pumpAndSettle();
expect(find.text('456'), findsOneWidget);
expect(find.text('123'), findsNothing);
});
}
@@ -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';
@@ -252,7 +251,6 @@ void main() {
await _pump(tester, client, platform: TargetPlatform.iOS);
expect(find.byType(CupertinoTextField), findsNothing);
expect(find.byType(TextField), findsWidgets);
expect(find.byKey(SettingsKeys.connect), findsOneWidget);
});
@@ -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_tabs.dart';
@@ -33,7 +32,7 @@ class _PageState extends State<_Page> {
controller: scroll,
child: Column(
children: [
CupertinoTextField(controller: text),
TextField(controller: text),
for (var i = 0; i < 80; i++) Text('${widget.name} item $i'),
],
),
@@ -41,84 +40,66 @@ class _PageState extends State<_Page> {
}
void main() {
for (final cupertino in [false, true]) {
testWidgets('lazy topic pages retain draft and scroll ($cupertino)', (
tester,
) async {
final mounts = <SettingsTopic, int>{};
final tabs = SettingsTopicTabs(
pages: {
for (final topic in SettingsTopic.values)
topic: (_) => _Page(
name: topic.name,
onMount: () =>
mounts.update(topic, (count) => count + 1, ifAbsent: () => 1),
),
},
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: tabs))
: MaterialApp(home: Scaffold(body: tabs)),
);
expect(mounts, {SettingsTopic.appearance: 1});
final appearance = tester.state<_PageState>(find.byType(_Page));
appearance.text.text = 'Keep this draft';
appearance.scroll.jumpTo(150);
await tester.pump();
await selectSettingsTopic(tester, 'Connection');
expect(mounts, {
SettingsTopic.appearance: 1,
SettingsTopic.connection: 1,
});
final connection = tester.state<_PageState>(find.byType(_Page));
connection.text.text = 'Unsubmitted server';
connection.scroll.jumpTo(280);
await selectSettingsTopic(tester, 'Appearance');
expect(tester.state(find.byType(_Page)), same(appearance));
expect(appearance.text.text, 'Keep this draft');
expect(appearance.scroll.offset, 150);
await selectSettingsTopic(tester, 'Connection');
expect(tester.state(find.byType(_Page)), same(connection));
expect(connection.text.text, 'Unsubmitted server');
expect(connection.scroll.offset, 280);
expect(mounts.values, everyElement(1));
});
testWidgets('lazy topic pages retain draft and scroll', (tester) async {
final mounts = <SettingsTopic, int>{};
final tabs = SettingsTopicTabs(
pages: {
for (final topic in SettingsTopic.values)
topic: (_) => _Page(
name: topic.name,
onMount: () =>
mounts.update(topic, (count) => count + 1, ifAbsent: () => 1),
),
},
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: tabs)));
expect(mounts, {SettingsTopic.appearance: 1});
final appearance = tester.state<_PageState>(find.byType(_Page));
appearance.text.text = 'Keep this draft';
appearance.scroll.jumpTo(150);
await tester.pump();
await selectSettingsTopic(tester, 'Connection');
expect(mounts, {SettingsTopic.appearance: 1, SettingsTopic.connection: 1});
final connection = tester.state<_PageState>(find.byType(_Page));
connection.text.text = 'Unsubmitted server';
connection.scroll.jumpTo(280);
await selectSettingsTopic(tester, 'Appearance');
expect(tester.state(find.byType(_Page)), same(appearance));
expect(appearance.text.text, 'Keep this draft');
expect(appearance.scroll.offset, 150);
await selectSettingsTopic(tester, 'Connection');
expect(tester.state(find.byType(_Page)), same(connection));
expect(connection.text.text, 'Unsubmitted server');
expect(connection.scroll.offset, 280);
expect(mounts.values, everyElement(1));
});
testWidgets('all topics reachable at narrow large text ($cupertino)', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final tabs = SettingsTopicTabs(
pages: {
for (final topic in SettingsTopic.values)
topic: (_) => Text('${topic.label} content'),
},
);
Widget scale(BuildContext context, Widget? child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: const TextScaler.linear(2)),
child: child!,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
builder: scale,
home: CupertinoPageScaffold(child: tabs),
)
: MaterialApp(
builder: scale,
home: Scaffold(body: tabs),
),
);
for (final topic in SettingsTopic.values) {
await selectSettingsTopic(tester, topic.label);
expect(find.text('${topic.label} content'), findsOneWidget);
expect(tester.takeException(), isNull);
}
});
}
testWidgets('all topics reachable at narrow large text', (tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final tabs = SettingsTopicTabs(
pages: {
for (final topic in SettingsTopic.values)
topic: (_) => Text('${topic.label} content'),
},
);
Widget scale(BuildContext context, Widget? child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: const TextScaler.linear(2)),
child: child!,
);
await tester.pumpWidget(
MaterialApp(
builder: scale,
home: Scaffold(body: tabs),
),
);
for (final topic in SettingsTopic.values) {
await selectSettingsTopic(tester, topic.label);
expect(find.text('${topic.label} content'), findsOneWidget);
expect(tester.takeException(), isNull);
}
});
}
@@ -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_scope.dart';
@@ -11,11 +10,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'settings_topic_test_helper.dart';
Widget host({
bool cupertino = false,
String? scope,
SettingsTopicStore? store,
}) {
Widget host({String? scope, SettingsTopicStore? store}) {
final tabs = SettingsTopicTabs(
navigationScope: scope,
selectionStore: store,
@@ -24,9 +19,7 @@ Widget host({
topic: (_) => Text('${topic.name} page'),
},
);
return cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: tabs))
: MaterialApp(home: Scaffold(body: tabs));
return MaterialApp(home: Scaffold(body: tabs));
}
class DelayedStore implements SettingsTopicStore {
@@ -67,26 +60,22 @@ class SharedQueuedTopicStore implements SettingsTopicStore {
}
void main() {
for (final cupertino in [false, true]) {
testWidgets('restores selected category after recreation ($cupertino)', (
tester,
) async {
SharedPreferences.setMockInitialValues({});
await tester.pumpWidget(host(cupertino: cupertino, scope: 'server-a'));
await tester.pumpAndSettle();
await selectSettingsTopic(tester, 'Connection');
expect(find.text('connection page'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pumpWidget(host(cupertino: cupertino, scope: 'server-a'));
await tester.pumpAndSettle();
expect(find.text('connection page'), findsOneWidget);
final preferences = await SharedPreferences.getInstance();
expect(
preferences.getString(scopedServerKey(settingsTopicKey, 'server-a')),
'connection',
);
});
}
testWidgets('restores selected category after recreation', (tester) async {
SharedPreferences.setMockInitialValues({});
await tester.pumpWidget(host(scope: 'server-a'));
await tester.pumpAndSettle();
await selectSettingsTopic(tester, 'Connection');
expect(find.text('connection page'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pumpWidget(host(scope: 'server-a'));
await tester.pumpAndSettle();
expect(find.text('connection page'), findsOneWidget);
final preferences = await SharedPreferences.getInstance();
expect(
preferences.getString(scopedServerKey(settingsTopicKey, 'server-a')),
'connection',
);
});
testWidgets('server scopes and malformed selections are independent', (
tester,