8ed3998dd5
An unset (or unknown) design id resolves to Terminal, in the controller's initial value, AppDesign.fromId and the boot spinner. A stored choice, including Classic's stable 'default' id, is respected. The picker calls the original Material look Classic so no row reads 'Default'. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
115 lines
4.6 KiB
Dart
115 lines
4.6 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 a missing or unknown id is Terminal', () {
|
|
for (final design in AppDesign.values) {
|
|
expect(AppDesign.fromId(design.id), design);
|
|
}
|
|
expect(AppDesign.defaultDesign, AppDesign.terminal);
|
|
expect(AppDesign.fromId(null), AppDesign.terminal);
|
|
expect(AppDesign.fromId('neon'), AppDesign.terminal);
|
|
// Classic keeps the id it was stored under when it was the default.
|
|
expect(AppDesign.standard.id, 'default');
|
|
expect(AppDesign.standard.label, 'Classic');
|
|
});
|
|
|
|
test('the Classic 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');
|
|
},
|
|
),
|
|
},
|
|
),
|
|
);
|
|
// Terminal until the device chooses.
|
|
expect(tokens.terminal, isTrue);
|
|
expect(family, appMonospaceFamily);
|
|
await designs.select(AppDesign.standard);
|
|
await tester.pumpAndSettle();
|
|
expect(tokens.terminal, isFalse);
|
|
expect(family, isNot(appMonospaceFamily));
|
|
await designs.select(AppDesign.terminal);
|
|
await tester.pumpAndSettle();
|
|
expect(tokens.terminal, isTrue);
|
|
});
|
|
}
|