253 lines
8.4 KiB
Dart
253 lines
8.4 KiB
Dart
import 'package:flutter/cupertino.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({
|
|
required bool cupertino,
|
|
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) => cupertino
|
|
? CupertinoButton(
|
|
onPressed: () {},
|
|
child: chatBarCupertinoContent(context, const Text('Model')),
|
|
)
|
|
: TextButton(
|
|
style: chatBarTextButtonStyle(context),
|
|
onPressed: () {},
|
|
child: const Text('Model'),
|
|
),
|
|
),
|
|
],
|
|
actions: [
|
|
ChatBarAction(
|
|
label: 'Files',
|
|
onPressed: () {},
|
|
materialIcon: Icons.folder_outlined,
|
|
cupertinoIcon: CupertinoIcons.folder,
|
|
),
|
|
],
|
|
);
|
|
if (inactive != null) {
|
|
header = ChatPaneActivity(inactive: inactive, child: header);
|
|
}
|
|
final body = Align(
|
|
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),
|
|
);
|
|
}
|
|
|
|
Future<BuildContext> _pump(
|
|
WidgetTester tester, {
|
|
required bool cupertino,
|
|
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(
|
|
cupertino: cupertino,
|
|
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() {
|
|
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('$host: an inactive split pane fades its bar tint to half', (
|
|
tester,
|
|
) async {
|
|
final context = await _pump(
|
|
tester,
|
|
cupertino: cupertino,
|
|
color: 'orange',
|
|
inactive: true,
|
|
);
|
|
final shade = chatColorShade(context, 'orange')!;
|
|
final raised = cupertino
|
|
? CupertinoColors.systemGrey5.resolveFrom(context)
|
|
: 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(cupertino: cupertino, 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('Material: bar icons take the seeded onPrimaryContainer', (
|
|
tester,
|
|
) async {
|
|
final context = await _pump(tester, cupertino: false, color: 'purple');
|
|
final shade = chatColorShade(context, 'purple')!;
|
|
final foreground = ColorScheme.fromSeed(
|
|
seedColor: shade,
|
|
).onPrimaryContainer;
|
|
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),
|
|
);
|
|
});
|
|
}
|