8ca3d3e467
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
182 lines
7.7 KiB
Dart
182 lines
7.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/ui/text/monospace.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/app_theme.dart';
|
|
import 'package:pipelines_app/ui/theme/paper_fonts.dart';
|
|
|
|
ThemeData _theme(AppDesign design, Brightness brightness, {String? font}) =>
|
|
brightness == Brightness.dark
|
|
? design.dark(fontFamily: font)
|
|
: design.light(fontFamily: font);
|
|
|
|
void main() {
|
|
test('Paper is listed with a stable id, a label and one line', () {
|
|
expect(AppDesign.values, contains(AppDesign.paper));
|
|
expect(AppDesign.fromId('paper'), AppDesign.paper);
|
|
expect(AppDesign.paper.label, 'Paper');
|
|
expect(AppDesign.paper.description, isNot(contains('\n')));
|
|
expect(AppDesign.paper.usesInterfaceFont, isTrue);
|
|
expect(AppDesign.terminal.usesInterfaceFont, isFalse);
|
|
});
|
|
|
|
test('Paper tokens: manuscript transcript, underline composer, washed '
|
|
'row, serif reading at ~70ch, soft corners, hairlines', () {
|
|
for (final brightness in Brightness.values) {
|
|
final theme = _theme(AppDesign.paper, brightness);
|
|
final tokens = theme.extension<AppDesignTokens>()!;
|
|
expect(tokens.design, AppDesign.paper);
|
|
expect(tokens.transcript, TranscriptStyle.manuscript);
|
|
expect(tokens.terminal, isFalse);
|
|
expect(tokens.composer, ComposerStyle.underline);
|
|
expect(tokens.selectedRow, SelectedRowStyle.washed);
|
|
expect(tokens.reading.family, paperSerifFamily);
|
|
expect(tokens.reading.height, closeTo(1.5, 0.1));
|
|
expect(tokens.reading.measure, 70);
|
|
expect(tokens.radius, inInclusiveRange(8, 10));
|
|
expect(tokens.flat, isTrue);
|
|
expect(tokens.frame, theme.colorScheme.outlineVariant);
|
|
expect(tokens.panel, theme.colorScheme.surface);
|
|
expect(tokens.chatColorSaturation, lessThan(1));
|
|
expect(tokens.ansi, isNotNull);
|
|
}
|
|
});
|
|
|
|
test('Paper pages: warm off-white by day, sepia charcoal by night', () {
|
|
final light = _theme(AppDesign.paper, Brightness.light);
|
|
final page = light.scaffoldBackgroundColor;
|
|
expect(page.computeLuminance(), greaterThan(0.8));
|
|
expect(page, isNot(const Color(0xFFFFFFFF)));
|
|
expect(page.r, greaterThan(page.b), reason: 'a warm page');
|
|
final dark = _theme(AppDesign.paper, Brightness.dark);
|
|
final night = dark.scaffoldBackgroundColor;
|
|
expect(night.computeLuminance(), inExclusiveRange(0.008, 0.05));
|
|
expect(night.r, greaterThan(night.b), reason: 'sepia, not neutral');
|
|
for (final theme in [light, dark]) {
|
|
// Ink, a muted secondary ink and one accent.
|
|
final scheme = theme.colorScheme;
|
|
expect(scheme.onSurface, isNot(scheme.onSurfaceVariant));
|
|
expect(scheme.primary.b, greaterThan(scheme.primary.r));
|
|
}
|
|
});
|
|
|
|
test('Paper sets titles in the serif and keeps chrome in the interface '
|
|
'font', () {
|
|
for (final brightness in Brightness.values) {
|
|
final text = _theme(AppDesign.paper, brightness, font: 'Inter').textTheme;
|
|
for (final title in [
|
|
text.headlineSmall,
|
|
text.titleLarge,
|
|
text.displaySmall,
|
|
]) {
|
|
expect(title?.fontFamily, paperSerifFamily);
|
|
}
|
|
for (final chrome in [
|
|
text.labelLarge,
|
|
text.labelSmall,
|
|
text.titleMedium,
|
|
text.bodyMedium,
|
|
text.bodySmall,
|
|
]) {
|
|
expect(chrome?.fontFamily, 'Inter');
|
|
}
|
|
}
|
|
// The reading style sets the serif over the body role and keeps the
|
|
// interface face as its fallback.
|
|
final paper = _theme(AppDesign.paper, Brightness.light, font: 'Inter');
|
|
final tokens = paper.extension<AppDesignTokens>()!;
|
|
const body = TextStyle(fontFamily: 'Inter', fontSize: 16);
|
|
final reading = tokens.reading.apply(body)!;
|
|
expect(reading.fontFamily, paperSerifFamily);
|
|
expect(reading.fontFamilyFallback, contains('Inter'));
|
|
expect(reading.height, tokens.reading.height);
|
|
expect(reading.fontSize, greaterThan(16));
|
|
});
|
|
|
|
test('Paper floats only menus and dialogs, by a whisper, in its corners', () {
|
|
final theme = _theme(AppDesign.paper, Brightness.light);
|
|
final radius = theme.extension<AppDesignTokens>()!.radius!;
|
|
expect(theme.cardTheme.elevation, 0);
|
|
expect(theme.appBarTheme.scrolledUnderElevation, 0);
|
|
expect(theme.floatingActionButtonTheme.elevation, 0);
|
|
expect(theme.dialogTheme.elevation, inInclusiveRange(1, 4));
|
|
expect(theme.popupMenuTheme.elevation, inInclusiveRange(1, 4));
|
|
expect(theme.dialogTheme.shadowColor!.a, lessThan(0.5));
|
|
for (final shape in [
|
|
theme.cardTheme.shape,
|
|
theme.dialogTheme.shape,
|
|
theme.popupMenuTheme.shape,
|
|
theme.chipTheme.shape,
|
|
theme.snackBarTheme.shape,
|
|
]) {
|
|
expect(
|
|
(shape! as RoundedRectangleBorder).borderRadius,
|
|
BorderRadius.circular(radius),
|
|
);
|
|
}
|
|
// Controls the Default leaves to Material are Paper's own.
|
|
expect(theme.sliderTheme.trackHeight, 2);
|
|
expect(theme.sliderTheme.thumbShape, isA<RoundSliderThumbShape>());
|
|
expect(theme.badgeTheme.backgroundColor, theme.colorScheme.primary);
|
|
expect(theme.checkboxTheme.shape, isA<RoundedRectangleBorder>());
|
|
expect(theme.switchTheme.trackOutlineWidth, isNotNull);
|
|
expect(theme.tabBarTheme.indicator, isA<UnderlineTabIndicator>());
|
|
expect(theme.inputDecorationTheme.border, isA<UnderlineInputBorder>());
|
|
expect(theme.searchBarTheme.elevation?.resolve({}), 0);
|
|
});
|
|
|
|
test('the Default design is unchanged: no tokens, every style defaulted', () {
|
|
expect(AppDesign.standard.light(), appLightTheme());
|
|
expect(AppDesign.standard.dark(), appDarkTheme());
|
|
const tokens = AppDesignTokens.standard;
|
|
expect(tokens.transcript, TranscriptStyle.bubbles);
|
|
expect(tokens.composer, ComposerStyle.pill);
|
|
expect(tokens.selectedRow, SelectedRowStyle.tonal);
|
|
expect(tokens.reading.family, isNull);
|
|
expect(tokens.reading.measure, isNull);
|
|
expect(tokens.chatColorSaturation, 1);
|
|
expect(tokens.panel, isNull);
|
|
final style = const TextStyle(fontSize: 16, fontFamily: 'Inter');
|
|
expect(tokens.reading.apply(style), same(style));
|
|
});
|
|
|
|
test('Terminal is unchanged: prompt transcript, framed row, pill, its own '
|
|
'monospace and no reading type', () {
|
|
for (final brightness in Brightness.values) {
|
|
final theme = _theme(AppDesign.terminal, brightness, font: 'Inter');
|
|
final tokens = theme.extension<AppDesignTokens>()!;
|
|
expect(tokens.transcript, TranscriptStyle.prompt);
|
|
expect(tokens.terminal, isTrue);
|
|
expect(tokens.selectedRow, SelectedRowStyle.framed);
|
|
expect(tokens.composer, ComposerStyle.pill);
|
|
expect(tokens.reading.family, isNull);
|
|
expect(tokens.panel, isNull);
|
|
expect(tokens.chatColorSaturation, 1);
|
|
expect(tokens.radius, 3);
|
|
expect(theme.textTheme.bodyLarge?.fontFamily, appMonospaceFamily);
|
|
// A flat panel keeps Terminal's own low surface.
|
|
expect(
|
|
tokens.panelFill(theme.colorScheme, Colors.red),
|
|
theme.colorScheme.surfaceContainerLow,
|
|
);
|
|
}
|
|
});
|
|
|
|
test('each design swatch matches its theme', () {
|
|
for (final design in AppDesign.values) {
|
|
for (final brightness in Brightness.values) {
|
|
final theme = _theme(design, brightness);
|
|
final swatch = design.swatch(brightness);
|
|
// A glass design's scaffold is clear: its page is its backdrop.
|
|
final page =
|
|
theme.extension<AppDesignTokens>()?.glass?.backdrop.base ??
|
|
theme.scaffoldBackgroundColor;
|
|
expect(swatch.page, page, reason: '$design');
|
|
expect(swatch.ink, theme.colorScheme.onSurface, reason: '$design');
|
|
expect(swatch.accent, theme.colorScheme.primary, reason: '$design');
|
|
}
|
|
}
|
|
});
|
|
}
|