import 'dart:convert'; import 'dart:io'; import 'dart:math' as math; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:sxchnge_theme/sxchnge_theme.dart'; double contrast(Color a, Color b) { final x = a.computeLuminance(); final y = b.computeLuminance(); return (math.max(x, y) + 0.05) / (math.min(x, y) + 0.05); } void main() { test('website core colors stay aligned with the package snapshot', () { final source = File('../../../website/design/tokens.json'); if (!source.existsSync()) return; // Also allow testing outside this monorepo. final colors = (jsonDecode(source.readAsStringSync()) as Map)['colors'] as Map; for (final entry in { 'ink': SxchngeBrand.ink, 'mint': SxchngeBrand.mint, 'lime': SxchngeBrand.lime, 'paper': SxchngeBrand.paper, 'forest': SxchngeBrand.forest, }.entries) { expect( entry.value.toARGB32(), int.parse('ff${(colors[entry.key] as String).substring(1)}', radix: 16), ); } }); for (final dark in [false, true]) { final theme = dark ? SxchngeTheme.dark() : SxchngeTheme.light(); test( '${dark ? "dark" : "light"} foreground pairs meet normal text contrast', () { final c = theme.colorScheme; for (final pair in [ (c.primary, c.onPrimary), (c.primaryContainer, c.onPrimaryContainer), (c.secondary, c.onSecondary), (c.secondaryContainer, c.onSecondaryContainer), (c.tertiary, c.onTertiary), (c.tertiaryContainer, c.onTertiaryContainer), (c.surface, c.onSurface), (c.surface, c.onSurfaceVariant), (c.error, c.onError), (c.errorContainer, c.onErrorContainer), ]) { expect(contrast(pair.$1, pair.$2), greaterThanOrEqualTo(4.5)); } expect( theme.textTheme.bodyMedium!.fontFamily, 'packages/sxchnge_theme/Onest', ); }, ); } }