mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-29 04:42:02 +02:00
98 lines
3.4 KiB
Dart
98 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:spotiflac_android/l10n/l10n.dart';
|
|
import 'package:spotiflac_android/models/theme_settings.dart';
|
|
import 'package:spotiflac_android/providers/theme_provider.dart';
|
|
import 'package:spotiflac_android/screens/settings/appearance_settings_page.dart';
|
|
import 'package:spotiflac_android/theme/dynamic_color_wrapper.dart';
|
|
import 'package:spotiflac_android/theme/mornye_theme.dart';
|
|
|
|
void main() {
|
|
Future<void> openSettings(
|
|
WidgetTester tester,
|
|
SharedPreferences prefs,
|
|
) async {
|
|
tester.view.physicalSize = const Size(390, 1000);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
initialThemeSettingsProvider.overrideWithValue(
|
|
loadBootstrapThemeSettings(prefs),
|
|
),
|
|
],
|
|
child: DynamicColorWrapper(
|
|
builder: (light, dark, mode) => MaterialApp(
|
|
theme: light,
|
|
darkTheme: dark,
|
|
themeMode: mode,
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
home: const MornyeSettingsTheme(child: AppearanceSettingsPage()),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
for (final mode in [ThemeMode.light, ThemeMode.dark]) {
|
|
testWidgets('Mornye accent updates live and survives restart ($mode)', (
|
|
tester,
|
|
) async {
|
|
SharedPreferences.setMockInitialValues({
|
|
kThemeStyleKey: 'mornye',
|
|
kThemeModeKey: mode.name,
|
|
kSeedColorKey: 0xff123456,
|
|
});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await openSettings(tester, prefs);
|
|
final page = find.byType(AppearanceSettingsPage);
|
|
final initial = Theme.of(tester.element(page));
|
|
expect(
|
|
initial.colorScheme.primary,
|
|
MornyeTheme.accentColor(MornyeAccent.red, initial.brightness),
|
|
);
|
|
|
|
final blue = find.byTooltip('Blue');
|
|
await tester.ensureVisible(blue);
|
|
await tester.tap(blue);
|
|
await tester.pumpAndSettle();
|
|
final theme = Theme.of(tester.element(page));
|
|
expect(
|
|
theme.colorScheme.primary,
|
|
MornyeTheme.accentColor(MornyeAccent.blue, theme.brightness),
|
|
);
|
|
expect(prefs.getString(kMornyeAccentKey), 'blue');
|
|
expect(prefs.getInt(kSeedColorKey), 0xff123456);
|
|
final overlay = MornyeTheme.fromContext(
|
|
tester.element(page),
|
|
brightness: Brightness.dark,
|
|
);
|
|
expect(overlay.extension<MornyeTheme>()!.accent, MornyeAccent.blue);
|
|
expect(
|
|
overlay.colorScheme.primary,
|
|
MornyeTheme.accentColor(MornyeAccent.blue, Brightness.dark),
|
|
);
|
|
|
|
await tester.pumpWidget(const SizedBox());
|
|
await openSettings(tester, prefs);
|
|
expect(
|
|
Theme.of(tester.element(page)).colorScheme.primary,
|
|
theme.colorScheme.primary,
|
|
);
|
|
await tester.ensureVisible(find.byTooltip('Red (default)'));
|
|
await tester.tap(find.byTooltip('Red (default)'));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
Theme.of(tester.element(page)).colorScheme.primary,
|
|
initial.colorScheme.primary,
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|
|
}
|