Files
pipelines/app/test/ui/theme/app_design_test.dart
T
alan ca2f7eee32 App: add a selectable app design with a Terminal look
AppDesign builds each design's light and dark ThemeData with an
AppDesignTokens extension (corner radius, flat surfaces, frame colour,
ANSI accents, prompt glyph). Settings gains a Design picker stored per
device; the theme hosts rebuild live. Terminal is monospace (bundled
RobotoMono), near-black or paper, flat 1px frames with 3px corners, and
draws the chat transcript as prompt lines, tool dot/result lines and
bracketed follow-up lines. Default keeps its exact themes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:43:59 +00:00

111 lines
4.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/app.dart';
import 'package:pipelines_app/shell/destination.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_controller.dart';
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
import 'package:pipelines_app/ui/theme/app_font_controller.dart';
import 'package:pipelines_app/ui/theme/app_font_store.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
void main() {
test('ids round-trip and an unknown id is the Default design', () {
for (final design in AppDesign.values) {
expect(AppDesign.fromId(design.id), design);
}
expect(AppDesign.fromId(null), AppDesign.standard);
expect(AppDesign.fromId('neon'), AppDesign.standard);
expect(AppDesign.standard.id, 'default');
});
test('the Default design builds exactly the existing themes', () {
expect(AppDesign.standard.light(), appLightTheme());
expect(AppDesign.standard.dark(), appDarkTheme());
expect(
AppDesign.standard.light(fontFamily: 'Inter'),
appLightTheme(fontFamily: 'Inter'),
);
expect(AppDesign.standard.dark().extension<AppDesignTokens>(), isNull);
});
test('Terminal is monospace, flat and near-black in dark', () {
for (final brightness in Brightness.values) {
final theme = brightness == Brightness.dark
? AppDesign.terminal.dark(fontFamily: 'Inter')
: AppDesign.terminal.light(fontFamily: 'Inter');
final tokens = theme.extension<AppDesignTokens>()!;
expect(tokens.terminal, isTrue);
expect(tokens.flat, isTrue);
expect(tokens.radius, lessThanOrEqualTo(4));
expect(tokens.ansi, isNotNull);
expect(theme.colorScheme.brightness, brightness);
// The interface font choice does not apply: monospace everywhere.
for (final style in [
theme.textTheme.bodyLarge,
theme.textTheme.titleMedium,
theme.textTheme.labelLarge,
]) {
expect(style?.fontFamily, appMonospaceFamily);
expect(style?.letterSpacing, 0);
}
expect(theme.cardTheme.elevation, 0);
expect(theme.dialogTheme.elevation, 0);
expect(theme.appBarTheme.scrolledUnderElevation, 0);
final dialog = theme.dialogTheme.shape! as RoundedRectangleBorder;
expect(dialog.borderRadius, BorderRadius.circular(tokens.radius!));
expect(dialog.side.width, 1);
}
final dark = AppDesign.terminal.dark();
expect(dark.scaffoldBackgroundColor.computeLuminance(), lessThan(0.01));
final light = AppDesign.terminal.light();
expect(light.scaffoldBackgroundColor.computeLuminance(), greaterThan(0.85));
});
test('tokens reshape only under a design that sets a radius', () {
const stadium = StadiumBorder();
expect(AppDesignTokens.standard.shape(stadium), same(stadium));
final terminal = AppDesign.terminal.dark().extension<AppDesignTokens>()!;
final shaped = terminal.shape(stadium) as RoundedRectangleBorder;
expect(shaped.borderRadius, BorderRadius.circular(terminal.radius!));
});
testWidgets('the Material host switches design live, without a restart', (
tester,
) async {
final designs = AppDesignController(store: MemoryAppDesignStore());
final fonts = AppFontController(
store: MemoryAppFontStore(),
loader: (family, assets) async {},
);
late AppDesignTokens tokens;
String? family;
await tester.pumpWidget(
MyApp(
fonts: fonts,
designs: designs,
destination: AppDestination.settings,
destinationBodies: <AppDestination, WidgetBuilder>{
AppDestination.settings: (context) => Builder(
builder: (context) {
tokens = AppDesignTokens.of(context);
family = DefaultTextStyle.of(context).style.fontFamily;
return const Text('body');
},
),
},
),
);
expect(tokens.terminal, isFalse);
expect(family, isNot(appMonospaceFamily));
await designs.select(AppDesign.terminal);
await tester.pumpAndSettle();
expect(tokens.terminal, isTrue);
expect(family, appMonospaceFamily);
await designs.select(AppDesign.standard);
await tester.pumpAndSettle();
expect(tokens.terminal, isFalse);
});
}