theme_test.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import 'package:flowy_infra/colorscheme/colorscheme.dart';
  2. import 'package:flowy_infra/plugins/service/location_service.dart';
  3. import 'package:flowy_infra/plugins/service/models/flowy_dynamic_plugin.dart';
  4. import 'package:flowy_infra/plugins/service/plugin_service.dart';
  5. import 'package:flowy_infra/theme.dart';
  6. import 'package:flutter/widgets.dart';
  7. import 'package:flutter_test/flutter_test.dart';
  8. class MockPluginService implements FlowyPluginService {
  9. @override
  10. Future<void> addPlugin(FlowyDynamicPlugin plugin) =>
  11. throw UnimplementedError();
  12. @override
  13. Future<FlowyDynamicPlugin?> lookup({required String name}) =>
  14. throw UnimplementedError();
  15. @override
  16. Future<DynamicPluginLibrary> get plugins async => const Iterable.empty();
  17. @override
  18. void setLocation(PluginLocationService locationService) =>
  19. throw UnimplementedError();
  20. }
  21. void main() {
  22. WidgetsFlutterBinding.ensureInitialized();
  23. group('AppTheme', () {
  24. test('fallback theme', () {
  25. const theme = AppTheme.fallback;
  26. expect(theme.builtIn, true);
  27. expect(theme.themeName, BuiltInTheme.defaultTheme);
  28. expect(theme.lightTheme, isA<FlowyColorScheme>());
  29. expect(theme.darkTheme, isA<FlowyColorScheme>());
  30. });
  31. test('built-in themes', () {
  32. final themes = AppTheme.builtins;
  33. expect(themes, isNotEmpty);
  34. for (final theme in themes) {
  35. expect(theme.builtIn, true);
  36. expect(
  37. theme.themeName,
  38. anyOf([
  39. BuiltInTheme.defaultTheme,
  40. BuiltInTheme.dandelion,
  41. BuiltInTheme.lavender,
  42. BuiltInTheme.lemonade,
  43. ]),
  44. );
  45. expect(theme.lightTheme, isA<FlowyColorScheme>());
  46. expect(theme.darkTheme, isA<FlowyColorScheme>());
  47. }
  48. });
  49. test('fromName returns existing theme', () async {
  50. final theme = await AppTheme.fromName(
  51. BuiltInTheme.defaultTheme,
  52. pluginService: MockPluginService(),
  53. );
  54. expect(theme, isNotNull);
  55. expect(theme.builtIn, true);
  56. expect(theme.themeName, BuiltInTheme.defaultTheme);
  57. expect(theme.lightTheme, isA<FlowyColorScheme>());
  58. expect(theme.darkTheme, isA<FlowyColorScheme>());
  59. });
  60. test('fromName throws error for non-existent theme', () async {
  61. expect(
  62. () async => await AppTheme.fromName(
  63. 'bogus',
  64. pluginService: MockPluginService(),
  65. ),
  66. throwsArgumentError,
  67. );
  68. });
  69. });
  70. }