import 'package:flutter/foundation.dart'; 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_controller.dart'; import 'package:pipelines_app/ui/theme/app_design_tokens.dart'; import 'package:pipelines_app/ui/theme/app_theme.dart'; ThemeData _theme(AppDesign design, Brightness brightness, {String? font}) => brightness == Brightness.dark ? design.dark(fontFamily: font) : design.light(fontFamily: font); BorderRadius? _radiusOf(ShapeBorder? shape) => (shape as RoundedRectangleBorder?)?.borderRadius as BorderRadius?; void main() { const six = BorderRadius.all(Radius.circular(6)); test('Compact is listed with a stable id, a label and one line', () { expect(AppDesign.fromId('compact'), AppDesign.compact); expect(AppDesign.compact.label, 'Compact'); expect(AppDesign.compact.description, isNot(contains('\n'))); expect(AppDesign.compact.usesInterfaceFont, isTrue); expect(AppDesign.compact.swatchLines, greaterThan(2)); for (final design in AppDesign.values) { if (design != AppDesign.compact) expect(design.swatchLines, 2); } }); test('Compact tokens: Default chat and composer, tonal rows, 6px corners, ' 'the compact density and tighter paragraphs', () { for (final brightness in Brightness.values) { final tokens = _theme( AppDesign.compact, brightness, ).extension()!; expect(tokens.design, AppDesign.compact); expect(tokens.radius, 6); expect(tokens.flat, isFalse); expect(tokens.frame, isNull); expect(tokens.transcript, TranscriptStyle.bubbles); expect(tokens.composer, ComposerStyle.pill); expect(tokens.selectedRow, SelectedRowStyle.tonal); expect(tokens.density, DesignDensity.compact); expect(tokens.density.dense, isTrue); expect(tokens.density.iconSize, 18); expect(tokens.density.railLabels, isFalse); expect(tokens.density.railWidth, lessThan(96)); expect(tokens.reading.family, isNull); expect(tokens.reading.paragraphGap, lessThan(0.9)); expect(tokens.denseCorners(BorderRadius.circular(12)), six); } }); test('the comfortable designs keep the comfortable density', () { for (final design in [AppDesign.terminal, AppDesign.paper]) { final tokens = design.light().extension()!; expect(tokens.density, DesignDensity.comfortable); expect(tokens.reading.paragraphGap, 0.9); final twelve = BorderRadius.circular(12); expect(tokens.denseCorners(twelve), twelve); } expect(AppDesignTokens.standard.density, DesignDensity.comfortable); // Default still builds its exact themes, with no tokens at all. expect(AppDesign.standard.light(), appLightTheme()); expect(AppDesign.standard.dark(), appDarkTheme()); }); test('density spacing: unchanged when comfortable, 4px grid when dense', () { const comfortable = DesignDensity.comfortable; for (final value in [2.0, 4.0, 6.0, 10.0, 13.0, 16.0, 24.0]) { expect(comfortable.space(value), value); expect(comfortable.inset(value), value); } expect(comfortable.minTouchRow, 0); const compact = DesignDensity.compact; expect(compact.space(16), 8); expect(compact.space(13), 8); expect(compact.space(12), 8); expect(compact.space(8), 4); expect(compact.space(6), 4); expect(compact.space(4), 2); expect(compact.space(24), 16); expect(compact.inset(16), 12); expect(compact.inset(12), 8); for (final value in [8.0, 12.0, 16.0, 24.0, 32.0]) { expect(compact.space(value) % 4, 0, reason: 'on the 4px grid'); expect(compact.space(value), lessThan(value)); } }); test('Compact keeps Default colours and packs type, icons and density', () { for (final brightness in Brightness.values) { final theme = _theme(AppDesign.compact, brightness, font: 'Inter'); final standard = _theme(AppDesign.standard, brightness, font: 'Inter'); expect(theme.colorScheme, standard.colorScheme); expect(theme.scaffoldBackgroundColor, standard.scaffoldBackgroundColor); final text = theme.textTheme; expect(text.bodyMedium?.fontSize, 13); expect(text.bodyLarge?.fontSize, 14); expect(text.labelMedium?.fontSize, 12); expect(text.labelSmall?.fontSize, 11); expect(text.titleMedium?.fontSize, 14); for (final style in [text.bodyMedium, text.titleLarge, text.labelLarge]) { // The device's interface font still applies. expect(style?.fontFamily, 'Inter'); expect(style?.fontSize, lessThan(20)); // Line heights on a 2px step. expect((style!.fontSize! * style.height!) % 2, closeTo(0, 0.01)); } expect(theme.visualDensity, VisualDensity.compact); expect(theme.iconTheme.size, 18); expect( theme.iconButtonTheme.style?.visualDensity, VisualDensity.compact, reason: 'Material 3 icon buttons ignore the theme density otherwise', ); } }); test('every floating and framed surface takes the same 6px corners', () { final theme = AppDesign.compact.light(); expect(_radiusOf(theme.dialogTheme.shape), six); expect(_radiusOf(theme.popupMenuTheme.shape), six); expect(_radiusOf(theme.snackBarTheme.shape), six); expect(_radiusOf(theme.cardTheme.shape), six); expect(_radiusOf(theme.chipTheme.shape), six); expect(_radiusOf(theme.floatingActionButtonTheme.shape), six); expect(_radiusOf(theme.listTileTheme.shape), six); expect(_radiusOf(theme.navigationRailTheme.indicatorShape), six); expect(_radiusOf(theme.menuTheme.style?.shape?.resolve(const {})), six); expect( _radiusOf(theme.filledButtonTheme.style?.shape?.resolve(const {})), six, ); expect( _radiusOf(theme.iconButtonTheme.style?.shape?.resolve(const {})), six, ); expect( (theme.tooltipTheme.decoration as BoxDecoration?)?.borderRadius, six, ); final sheet = _radiusOf(theme.bottomSheetTheme.shape)!; expect(sheet.topLeft, const Radius.circular(6)); expect(sheet.bottomLeft, Radius.zero); // A card keeps its outline under the theme's shape (outlined graph // nodes would otherwise lose it). final card = theme.cardTheme.shape! as RoundedRectangleBorder; expect(card.side.color, theme.colorScheme.outlineVariant); }); test('pointer devices shrink targets; touch devices keep 40px', () { for (final (platform, pointer) in [ (TargetPlatform.linux, true), (TargetPlatform.macOS, true), (TargetPlatform.windows, true), (TargetPlatform.android, false), (TargetPlatform.iOS, false), ]) { debugDefaultTargetPlatformOverride = platform; // Built afresh: the cached theme is the device's, built once. final theme = AppDesign.compact.build(Brightness.light); expect( theme.materialTapTargetSize, pointer ? MaterialTapTargetSize.shrinkWrap : MaterialTapTargetSize.padded, ); expect(DesignDensity.compact.minTouchRow, pointer ? 0 : 40); } debugDefaultTargetPlatformOverride = null; }); test( 'a switch into or out of Compact snaps; others keep the blend', () async { final designs = AppDesignController(store: MemoryAppDesignStore()); expect(AppDesign.compact.dense, isTrue); for (final design in [ AppDesign.standard, AppDesign.terminal, AppDesign.paper, ]) { expect(design.dense, isFalse); } expect(designs.themeAnimationDuration, kThemeAnimationDuration); await designs.select(AppDesign.terminal); expect(designs.themeAnimationDuration, kThemeAnimationDuration); await designs.select(AppDesign.compact); expect(designs.themeAnimationDuration, Duration.zero); await designs.select(AppDesign.paper); expect(designs.themeAnimationDuration, Duration.zero); await designs.select(AppDesign.standard); expect(designs.themeAnimationDuration, kThemeAnimationDuration); }, ); }