import 'dart:math' as math; import 'package:cutdex/app/editor_theme.dart'; import 'package:cutdex_ui/theme.dart'; import 'package:cutdex_sdk/timeline_ui.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { for (final palette in AppPalette.values) { for (final brightness in Brightness.values) { test( '${palette.name} ${brightness.name} shares semantic colors and readable text', () { final theme = EditorTheme.forPalette(palette, brightness); final colors = theme.colorScheme; final tokens = AppColors.of(theme); expect(theme.brightness, brightness); expect(tokens.family, palette); final settings = AppTheme.settingsContentTheme(theme); final dialog = AppTheme.dialogContentTheme(theme); final inspector = AppTheme.propertiesPanelTheme(theme); final actions = AppTheme.dialogActionTheme(theme); final timeline = theme.extension()!; expect( settings.switchTheme.trackColor!.resolve({WidgetState.selected}), colors.primary, ); expect( (dialog.inputDecorationTheme.focusedBorder as OutlineInputBorder) .borderSide .color, colors.primary, ); expect(timeline.selectionOutlineColor, colors.primary); expect( (inspector.inputDecorationTheme.focusedBorder as OutlineInputBorder) .borderSide .color, colors.primary, ); for (final style in [ theme.filledButtonTheme.style!, settings.filledButtonTheme.style!, actions.filledButtonTheme.style!, ]) { final background = style.backgroundColor!.resolve({})!; final foreground = style.foregroundColor!.resolve({})!; expect(background, colors.primary); expect( _contrast(foreground, background), greaterThanOrEqualTo(4.5), ); } expect(timeline.backgroundColor, colors.surface); expect(settings.colorScheme.surfaceContainer, tokens.card); expect(settings.inputDecorationTheme.fillColor, tokens.card); expect(inspector.inputDecorationTheme.fillColor, tokens.card); expect(AppColors.of(settings), tokens); expect( theme.extension()!.previewBackground, Colors.black, ); for (final surface in [ colors.surface, colors.surfaceContainerLow, colors.surfaceContainer, timeline.visualClipColor, timeline.audioClipColor, ]) { expect( _contrast(colors.onSurface, surface), greaterThanOrEqualTo(4.5), ); } for (final surface in [ colors.surface, colors.surfaceContainerLow, colors.surfaceContainer, ]) { expect( _contrast(colors.onSurfaceVariant, surface), greaterThanOrEqualTo(4.5), ); } expect( _contrast(colors.onPrimary, colors.primary), greaterThanOrEqualTo(4.5), ); }, ); } } test('six theme combinations have distinct workspace colors', () { final signatures = { for (final palette in AppPalette.values) for (final brightness in Brightness.values) ( EditorTheme.forPalette(palette, brightness).colorScheme.surface, EditorTheme.forPalette(palette, brightness).colorScheme.primary, ), }; expect(signatures.length, 6); }); } double _contrast(Color a, Color b) { final first = a.computeLuminance(); final second = b.computeLuminance(); return (math.max(first, second) + .05) / (math.min(first, second) + .05); }