04ba81e0ea
Keep chat and folder-picker UI on the Material path by removing obsolete Cupertino imports, icon metadata, flags, and alternate control handling while preserving existing behavior and focused test coverage.
188 lines
6.3 KiB
Dart
188 lines
6.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/chat/conversation/chat_bar_control_style.dart';
|
|
import 'package:pipelines_app/features/chat/conversation/chat_bar_tint.dart';
|
|
import 'package:pipelines_app/features/chat/conversation/chat_thread_header.dart';
|
|
import 'package:pipelines_app/features/chat/ui/sessions/chat_adaptive.dart';
|
|
import 'package:pipelines_app/features/chat/ui/sessions/chat_color_palette.dart';
|
|
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
|
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({
|
|
String? color,
|
|
Brightness brightness = Brightness.light,
|
|
bool? inactive,
|
|
}) {
|
|
Widget header = ChatThreadHeader(
|
|
title: 'Colour chat',
|
|
folder: 'demo',
|
|
onInfo: () {},
|
|
showBack: true,
|
|
onBack: () {},
|
|
chatColor: color,
|
|
controls: [
|
|
Builder(
|
|
builder: (context) => TextButton(
|
|
style: chatBarTextButtonStyle(context),
|
|
onPressed: () {},
|
|
child: const Text('Model'),
|
|
),
|
|
),
|
|
],
|
|
actions: [
|
|
ChatBarAction(
|
|
label: 'Files',
|
|
onPressed: () {},
|
|
materialIcon: Icons.folder_outlined,
|
|
),
|
|
],
|
|
);
|
|
if (inactive != null) {
|
|
header = ChatPaneActivity(inactive: inactive, child: header);
|
|
}
|
|
final body = Align(
|
|
alignment: Alignment.topCenter,
|
|
child: SizedBox(width: 900, height: 120, child: header),
|
|
);
|
|
return MaterialApp(
|
|
theme: brightness == Brightness.dark ? appDarkTheme() : appLightTheme(),
|
|
home: Scaffold(body: body),
|
|
);
|
|
}
|
|
|
|
Future<BuildContext> _pump(
|
|
WidgetTester tester, {
|
|
String? color,
|
|
Brightness brightness = Brightness.light,
|
|
bool? inactive,
|
|
}) async {
|
|
tester.view.physicalSize = const Size(1000, 400);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
_header(color: color, brightness: brightness, inactive: inactive),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
return tester.element(find.byType(ChatThreadHeader));
|
|
}
|
|
|
|
Color? _titleFill(WidgetTester tester) => tester
|
|
.widget<GlassPill>(
|
|
find
|
|
.ancestor(
|
|
of: find.byKey(const Key('chat-info')),
|
|
matching: find.byType(GlassPill),
|
|
)
|
|
.first,
|
|
)
|
|
.fill;
|
|
|
|
Color? _textColor(WidgetTester tester, String text) =>
|
|
tester.renderObject<RenderParagraph>(find.text(text)).text.style?.color;
|
|
|
|
Color? _iconIn(WidgetTester tester, Finder control) => IconTheme.of(
|
|
tester.element(find.descendant(of: control, matching: find.byType(Icon))),
|
|
).color;
|
|
|
|
final _files = find.byType(ChatBarAction);
|
|
final _back = find.byKey(const Key('chat-back'));
|
|
|
|
void main() {
|
|
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));
|
|
});
|
|
|
|
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,
|
|
color: 'teal',
|
|
brightness: brightness,
|
|
);
|
|
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: 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('an inactive split pane fades its bar tint to half', (
|
|
tester,
|
|
) async {
|
|
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,
|
|
).onPrimaryContainer;
|
|
expect(_iconIn(tester, _back), foreground);
|
|
expect(_iconIn(tester, _files), foreground);
|
|
});
|
|
}
|