theme_test.dart 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. ]),
  43. );
  44. expect(theme.lightTheme, isA<FlowyColorScheme>());
  45. expect(theme.darkTheme, isA<FlowyColorScheme>());
  46. }
  47. });
  48. test('fromName returns existing theme', () async {
  49. final theme = await AppTheme.fromName(
  50. BuiltInTheme.defaultTheme,
  51. pluginService: MockPluginService(),
  52. );
  53. expect(theme, isNotNull);
  54. expect(theme.builtIn, true);
  55. expect(theme.themeName, BuiltInTheme.defaultTheme);
  56. expect(theme.lightTheme, isA<FlowyColorScheme>());
  57. expect(theme.darkTheme, isA<FlowyColorScheme>());
  58. });
  59. test('fromName throws error for non-existent theme', () async {
  60. expect(
  61. () async => await AppTheme.fromName(
  62. 'bogus',
  63. pluginService: MockPluginService(),
  64. ),
  65. throwsArgumentError,
  66. );
  67. });
  68. });
  69. }