6a051a16e8
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
194 lines
7.8 KiB
Dart
194 lines
7.8 KiB
Dart
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/ui/theme/app_design.dart';
|
|
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
|
|
import 'package:pipelines_app/ui/theme/glass_backdrop.dart';
|
|
import 'package:pipelines_app/ui/theme/glass_palette.dart';
|
|
|
|
ThemeData _theme(AppDesign design, Brightness brightness) =>
|
|
brightness == Brightness.dark ? design.dark() : design.light();
|
|
|
|
AppDesignTokens _tokens(AppDesign design, Brightness brightness) =>
|
|
_theme(design, brightness).extension<AppDesignTokens>() ??
|
|
AppDesignTokens.standard;
|
|
|
|
double _contrast(Color a, Color b) {
|
|
final la = a.computeLuminance(), lb = b.computeLuminance();
|
|
return (math.max(la, lb) + 0.05) / (math.min(la, lb) + 0.05);
|
|
}
|
|
|
|
/// Every colour the backdrop can show at a point: its base and each glow at
|
|
/// full strength (the worst cases), composited under [tints] in order.
|
|
List<Color> _grounds(GlassStyle style, List<Color> tints) => [
|
|
for (final under in [
|
|
style.backdrop.base,
|
|
for (final glow in style.backdrop.glows)
|
|
Color.alphaBlend(glow.color, style.backdrop.base),
|
|
])
|
|
tints.fold(under, (ground, tint) => Color.alphaBlend(tint, ground)),
|
|
];
|
|
|
|
void main() {
|
|
test('Glass is listed with a stable id, a label and one line', () {
|
|
expect(AppDesign.values, contains(AppDesign.glass));
|
|
expect(AppDesign.fromId('glass'), AppDesign.glass);
|
|
expect(AppDesign.glass.label, 'Glass');
|
|
expect(AppDesign.glass.description, isNot(contains('\n')));
|
|
expect(AppDesign.glass.usesInterfaceFont, isTrue);
|
|
});
|
|
|
|
test('Glass tokens: bubbles and a pill composer on glass, a glowing open '
|
|
'row, no flat frames, corners grown with the hierarchy kept', () {
|
|
for (final brightness in Brightness.values) {
|
|
final theme = _theme(AppDesign.glass, brightness);
|
|
final tokens = theme.extension<AppDesignTokens>()!;
|
|
expect(tokens.design, AppDesign.glass);
|
|
expect(tokens.transcript, TranscriptStyle.bubbles);
|
|
expect(tokens.composer, ComposerStyle.pill);
|
|
expect(tokens.selectedRow, SelectedRowStyle.glow);
|
|
expect(tokens.flat, isFalse);
|
|
expect(tokens.radius, isNull);
|
|
expect(tokens.frame, isNull);
|
|
expect(tokens.snapSwitch, isTrue);
|
|
expect(tokens.ansi, isNotNull);
|
|
expect(tokens.reading.family, isNull, reason: 'the interface sans');
|
|
expect(tokens.reading.height, greaterThan(1.4));
|
|
final glass = tokens.glass!;
|
|
expect(glass, brightness == Brightness.dark ? glassDarkStyle : glassLightStyle);
|
|
// Outer > inner: each widget's own radius grows by the same factor up
|
|
// to the cap, so nesting order is kept.
|
|
expect(tokens.corners(BorderRadius.circular(4)), BorderRadius.circular(6));
|
|
expect(tokens.corners(BorderRadius.circular(8)), BorderRadius.circular(12));
|
|
expect(tokens.corners(BorderRadius.circular(16)), BorderRadius.circular(20));
|
|
expect(tokens.corners(BorderRadius.circular(28)), BorderRadius.circular(28));
|
|
expect(tokens.shape(const StadiumBorder()), const StadiumBorder());
|
|
expect(tokens.shape(const CircleBorder()), const CircleBorder());
|
|
expect(
|
|
tokens.shape(
|
|
const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(12)),
|
|
),
|
|
),
|
|
const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(18)),
|
|
),
|
|
);
|
|
// Pages are clear over the backdrop; floating pieces nearly opaque.
|
|
expect(theme.scaffoldBackgroundColor.a, 0);
|
|
expect(theme.dialogTheme.backgroundColor!.a, greaterThan(0.9));
|
|
expect(theme.popupMenuTheme.color!.a, greaterThan(0.9));
|
|
expect(theme.dialogTheme.shape, isA<GlassBorder>());
|
|
expect(theme.popupMenuTheme.shape, isA<GlassBorder>());
|
|
expect(theme.cardTheme.shape, isA<GlassBorder>());
|
|
// Containers are glass tints; the page roles stay opaque for blends.
|
|
expect(theme.colorScheme.surfaceContainerHigh.a, lessThan(1));
|
|
expect(theme.colorScheme.surface.a, 1);
|
|
expect(glass.solid.a, 1);
|
|
}
|
|
});
|
|
|
|
test('other designs keep their tokens and corners (no glass)', () {
|
|
for (final design in AppDesign.values.where((d) => d != AppDesign.glass)) {
|
|
for (final brightness in Brightness.values) {
|
|
final tokens = _tokens(design, brightness);
|
|
expect(tokens.glass, isNull, reason: design.label);
|
|
expect(tokens.selectedRow, isNot(SelectedRowStyle.glow));
|
|
final designed = BorderRadius.circular(8);
|
|
expect(
|
|
tokens.corners(designed),
|
|
tokens.radius == null ? designed : BorderRadius.circular(tokens.radius!),
|
|
);
|
|
expect(tokens.solidFill(const Color(0x80FFFFFF)), const Color(0x80FFFFFF));
|
|
expect(_theme(design, brightness).scaffoldBackgroundColor.a, 1);
|
|
}
|
|
}
|
|
expect(_tokens(AppDesign.standard, Brightness.light), AppDesignTokens.standard);
|
|
});
|
|
|
|
test('Glass body text keeps WCAG AA over every part of the backdrop', () {
|
|
for (final brightness in Brightness.values) {
|
|
final theme = _theme(AppDesign.glass, brightness);
|
|
final scheme = theme.colorScheme;
|
|
final glass = theme.extension<AppDesignTokens>()!.glass!;
|
|
final surfaces = <String, List<Color>>{
|
|
'rail': _grounds(glass, [glass.rail]),
|
|
'list pane': _grounds(glass, [glass.pane]),
|
|
'reading pane': _grounds(glass, [glass.detail]),
|
|
'card in the reading pane': _grounds(glass, [glass.detail, glass.card]),
|
|
'bubble': _grounds(glass, [
|
|
glass.detail,
|
|
scheme.surfaceContainerHighest,
|
|
]),
|
|
'bar': _grounds(glass, [glass.bar]),
|
|
'open row': _grounds(glass, [glass.pane, glass.slab]),
|
|
};
|
|
for (final MapEntry(key: name, value: grounds) in surfaces.entries) {
|
|
for (final ground in grounds) {
|
|
expect(
|
|
_contrast(scheme.onSurface, ground),
|
|
greaterThanOrEqualTo(7),
|
|
reason: '$brightness body text on the $name',
|
|
);
|
|
expect(
|
|
_contrast(scheme.onSurfaceVariant, ground),
|
|
greaterThanOrEqualTo(4.5),
|
|
reason: '$brightness muted text on the $name',
|
|
);
|
|
expect(
|
|
_contrast(scheme.primary, ground),
|
|
greaterThanOrEqualTo(4.5),
|
|
reason: '$brightness accent text on the $name',
|
|
);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
testWidgets('the backdrop paints only under Glass and keeps one tree '
|
|
'shape for every design', (tester) async {
|
|
for (final design in AppDesign.values) {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: design.light(),
|
|
home: const GlassBackdrop(child: SizedBox.expand()),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final paint = tester.widget<CustomPaint>(
|
|
find.byKey(const ValueKey('glass-backdrop')),
|
|
);
|
|
if (design == AppDesign.glass) {
|
|
expect(paint.painter, isA<GlassMeshPainter>());
|
|
expect(
|
|
(paint.painter! as GlassMeshPainter).mesh,
|
|
glassLightStyle.backdrop,
|
|
);
|
|
} else {
|
|
expect(paint.painter, isNull, reason: design.label);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('GlassBorder is value-equal, keeps a side it is given, and lerps', () {
|
|
const a = GlassBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(16)),
|
|
highlight: Color(0xFFFFFFFF),
|
|
edge: Color(0x22000000),
|
|
);
|
|
const b = GlassBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(16)),
|
|
highlight: Color(0xFFFFFFFF),
|
|
edge: Color(0x22000000),
|
|
);
|
|
expect(a, b);
|
|
expect(a.hashCode, b.hashCode);
|
|
final ring = a.copyWith(side: const BorderSide(width: 2));
|
|
expect(ring.side.width, 2);
|
|
expect(ring.borderRadius, a.borderRadius);
|
|
expect(ring.dimensions, const EdgeInsets.all(2));
|
|
expect(ShapeBorder.lerp(a, ring, 0.5), isA<GlassBorder>());
|
|
});
|
|
}
|