Add custom themes, holiday themes, chat backgrounds and holiday animations
- Themes: name + background + accent, derived surfaces/text/bubbles; editor with live preview; share codes and .jsonl import/export - Theme icons: swap tab, send, settings, node avatar and map marker icons for named icons or pictures (lossless JPEG XL) - Chat backgrounds per channel/DM (color or JPEG XL picture with fade); themes can set one, optionally for every chat - Map follows custom themes (panels, accent, tile tint, markers) - Holiday themes (Halloween, Thanksgiving, Christmas, New Year's) with generated backgrounds, icons and map markers; automatic switching from 17 days before each holiday - Holiday greeting animations (bats, turkeys, Santa, fireworks) matched across all app languages via translation strings
This commit is contained in:
1 parent
780183b586
commit
4a574185e8
124 files changed
+12686
-292
No files matched your search
@@ -0,0 +1,260 @@
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:koni_jxl_flutter/koni_jxl_flutter.dart';
|
||||
import 'package:meshcore_open/models/chat_background.dart';
|
||||
import 'package:meshcore_open/models/custom_theme.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/services/chat_background_image_store.dart';
|
||||
import 'package:meshcore_open/services/chat_background_service.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:meshcore_open/widgets/chat_background.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
const _green = Color(0xFF166534);
|
||||
const _navy = Color(0xFF1E3A8A);
|
||||
|
||||
CustomTheme _theme({ChatBackground? background, bool everywhere = false}) =>
|
||||
CustomTheme(
|
||||
id: 'custom:bg',
|
||||
name: 'Bg',
|
||||
background: const Color(0xFF000000),
|
||||
accent: const Color(0xFFFACC15),
|
||||
chatBackground: background,
|
||||
chatBackgroundEverywhere: everywhere,
|
||||
);
|
||||
|
||||
Future<Uint8List> _pngBytes(int width, int height) async {
|
||||
final recorder = ui.PictureRecorder();
|
||||
ui.Canvas(recorder).drawRect(
|
||||
ui.Rect.fromLTWH(0, 0, width.toDouble(), height.toDouble()),
|
||||
ui.Paint()..color = const Color(0xFF3366CC),
|
||||
);
|
||||
final image = await recorder.endRecording().toImage(width, height);
|
||||
final data = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||
image.dispose();
|
||||
return data!.buffer.asUint8List();
|
||||
}
|
||||
|
||||
void main() {
|
||||
late AppSettingsService settings;
|
||||
late InMemoryChatBackgroundImageStore images;
|
||||
late ChatBackgroundService service;
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
await PrefsManager.initialize();
|
||||
// A date with no holiday nearby, so no automatic holiday theme (and its
|
||||
// chat background) gets in the way.
|
||||
settings = AppSettingsService(clock: () => DateTime(2026, 7, 1));
|
||||
images = InMemoryChatBackgroundImageStore();
|
||||
service = ChatBackgroundService(settings, imageStore: images);
|
||||
});
|
||||
|
||||
group('ChatBackground', () {
|
||||
test('storage JSON round-trips and fade is clamped', () {
|
||||
const color = ChatBackground.color(_green, fade: 0.5);
|
||||
expect(ChatBackground.fromJson(color.toJson()), color);
|
||||
const image = ChatBackground.image('abc', fade: 0.3);
|
||||
expect(ChatBackground.fromJson(image.toJson()), image);
|
||||
expect(
|
||||
ChatBackground.fromJson({'color': '#000000', 'fade': 5})!.fade,
|
||||
ChatBackground.maxFade,
|
||||
);
|
||||
expect(ChatBackground.fromJson({'fade': 0.5}), isNull);
|
||||
});
|
||||
|
||||
test('share JSON carries colors and attached pictures only', () {
|
||||
expect(const ChatBackground.image('abc').toShareJson(), isNull);
|
||||
final withBytes = const ChatBackground.image(
|
||||
'abc',
|
||||
).withInlineImage(Uint8List.fromList([1, 2, 3]));
|
||||
final shared = ChatBackground.fromJson(withBytes.toShareJson())!;
|
||||
expect(shared.inlineImage, [1, 2, 3]);
|
||||
expect(shared.imageId, isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('themes', () {
|
||||
test('chat background persists with the theme', () {
|
||||
final theme = _theme(
|
||||
background: const ChatBackground.image('pic'),
|
||||
everywhere: true,
|
||||
);
|
||||
expect(CustomTheme.fromJson(theme.toJson()), theme);
|
||||
});
|
||||
|
||||
test('share codes keep colors but never a local image ID', () {
|
||||
final colored = _theme(
|
||||
background: const ChatBackground.color(_navy),
|
||||
everywhere: true,
|
||||
);
|
||||
final shared = CustomTheme.fromShareCode(
|
||||
colored.toShareCode(),
|
||||
newId: 'x',
|
||||
)!;
|
||||
expect(shared.chatBackground, colored.chatBackground);
|
||||
expect(shared.chatBackgroundEverywhere, isTrue);
|
||||
|
||||
final pictured = _theme(background: const ChatBackground.image('pic'));
|
||||
final noBytes = CustomTheme.fromShareCode(
|
||||
pictured.toShareCode(),
|
||||
newId: 'x',
|
||||
)!;
|
||||
expect(noBytes.chatBackground, isNull);
|
||||
|
||||
// A hand-written code pointing at a local ID is ignored too.
|
||||
final forged = CustomTheme.fromShareCode(
|
||||
'{"name":"F","background":"#000","accent":"#fff",'
|
||||
'"chatBackground":{"image":"pic"}}',
|
||||
newId: 'x',
|
||||
)!;
|
||||
expect(forged.chatBackground, isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('resolve', () {
|
||||
const key = 'channel:abc';
|
||||
|
||||
test('chat background beats the theme by default', () async {
|
||||
expect(service.resolve(key), isNull);
|
||||
|
||||
await settings.saveCustomTheme(
|
||||
_theme(background: const ChatBackground.color(_navy)),
|
||||
apply: true,
|
||||
);
|
||||
expect(service.resolve(key)?.color, _navy);
|
||||
expect(service.overridingTheme, isNull);
|
||||
|
||||
await service.setChatBackground(key, const ChatBackground.color(_green));
|
||||
expect(service.resolve(key)?.color, _green);
|
||||
expect(service.resolve('channel:other')?.color, _navy);
|
||||
});
|
||||
|
||||
test('"use in every chat" lets the theme win', () async {
|
||||
await service.setChatBackground(key, const ChatBackground.color(_green));
|
||||
await settings.saveCustomTheme(
|
||||
_theme(background: const ChatBackground.color(_navy), everywhere: true),
|
||||
apply: true,
|
||||
);
|
||||
expect(service.resolve(key)?.color, _navy);
|
||||
expect(service.overridingTheme?.name, 'Bg');
|
||||
// The chat keeps its own choice for when the theme changes.
|
||||
expect(service.chatBackground(key)?.color, _green);
|
||||
|
||||
await settings.setActiveTheme(null);
|
||||
expect(service.resolve(key)?.color, _green);
|
||||
});
|
||||
|
||||
test('per-chat backgrounds survive a restart', () async {
|
||||
await service.setChatBackground(
|
||||
key,
|
||||
const ChatBackground.color(_green, fade: 0.7),
|
||||
);
|
||||
final reloaded = ChatBackgroundService(settings, imageStore: images);
|
||||
expect(reloaded.chatBackground(key), service.chatBackground(key));
|
||||
await service.setChatBackground(key, null);
|
||||
expect(
|
||||
ChatBackgroundService(settings, imageStore: images).chatBackground(key),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('pictures', () {
|
||||
testWidgets('are shrunk and stored as JPEG XL', (tester) async {
|
||||
final id = await tester.runAsync(() async {
|
||||
return service.addImage(await _pngBytes(1600, 800));
|
||||
});
|
||||
expect(id, isNotNull);
|
||||
final stored = images.images[id]!;
|
||||
expect(looksLikeJxl(stored), isTrue);
|
||||
final size = await tester.runAsync(() async {
|
||||
final image = await decodeJxlToUiImage(stored);
|
||||
final s = Size(image.width.toDouble(), image.height.toDouble());
|
||||
image.dispose();
|
||||
return s;
|
||||
});
|
||||
expect(size, const Size(1080, 540));
|
||||
|
||||
expect(
|
||||
await tester.runAsync(
|
||||
() => service.addImage(Uint8List.fromList([1, 2, 3])),
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('travel with themes and come back as stored pictures', (
|
||||
tester,
|
||||
) async {
|
||||
final id = (await tester.runAsync(
|
||||
() async => service.addImage(await _pngBytes(40, 30)),
|
||||
))!;
|
||||
final theme = _theme(background: ChatBackground.image(id, fade: 0.5));
|
||||
|
||||
final embedded = (await tester.runAsync(
|
||||
() => service.embedThemeImages(theme),
|
||||
))!;
|
||||
final code = embedded.toShareCode();
|
||||
final received = CustomTheme.fromShareCode(code, newId: 'new')!;
|
||||
expect(received.chatBackground!.inlineImage, isNotNull);
|
||||
|
||||
final stored = (await tester.runAsync(
|
||||
() => service.storeThemeImages(received),
|
||||
))!;
|
||||
final storedId = stored.chatBackground!.imageId!;
|
||||
expect(images.images[storedId], isNotNull);
|
||||
expect(stored.chatBackground!.inlineImage, isNull);
|
||||
expect(stored.chatBackground!.fade, 0.5);
|
||||
});
|
||||
|
||||
testWidgets('unused pictures are cleaned up', (tester) async {
|
||||
await tester.runAsync(() async {
|
||||
final kept = (await service.addImage(await _pngBytes(20, 20)))!;
|
||||
final themed = (await service.addImage(await _pngBytes(21, 20)))!;
|
||||
final orphan = (await service.addImage(await _pngBytes(22, 20)))!;
|
||||
await service.setChatBackground(
|
||||
'contact:a',
|
||||
ChatBackground.image(kept),
|
||||
);
|
||||
await settings.saveCustomTheme(
|
||||
_theme(background: ChatBackground.image(themed)),
|
||||
);
|
||||
await service.collectGarbage();
|
||||
expect(images.images.keys, unorderedEquals([kept, themed]));
|
||||
expect(images.images.containsKey(orphan), isFalse);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('ChatBackdrop paints the resolved background', (tester) async {
|
||||
await service.setChatBackground(
|
||||
'contact:a',
|
||||
const ChatBackground.color(_green),
|
||||
);
|
||||
Widget host(String key) => ChangeNotifierProvider.value(
|
||||
value: service,
|
||||
child: MaterialApp(
|
||||
home: ChatBackdrop(chatKey: key, child: const Text('hi')),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(host('contact:a'));
|
||||
expect(find.byType(ChatBackgroundLayer), findsOneWidget);
|
||||
expect(find.text('hi'), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(host('contact:b'));
|
||||
expect(find.byType(ChatBackgroundLayer), findsNothing);
|
||||
|
||||
// Works (and draws nothing) without the service, e.g. in older tests.
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: ChatBackdrop(chatKey: 'x', child: Text('hi')),
|
||||
),
|
||||
);
|
||||
expect(find.text('hi'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/models/app_settings.dart';
|
||||
import 'package:meshcore_open/models/custom_theme.dart';
|
||||
import 'package:meshcore_open/models/holiday_schedule.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
const halloween = 'preset:halloween';
|
||||
const thanksgiving = 'preset:thanksgiving';
|
||||
const christmas = 'preset:christmas';
|
||||
const newYear = 'preset:new_year';
|
||||
|
||||
String? holidayOn(int year, int month, int day) =>
|
||||
activeHolidayFor(DateTime(year, month, day, 13, 30))?.themeId;
|
||||
|
||||
void main() {
|
||||
group('holiday dates', () {
|
||||
test('Thanksgiving is the fourth Thursday of November', () {
|
||||
expect(ThemeHoliday.thanksgiving.dateIn(2024), DateTime(2024, 11, 28));
|
||||
expect(ThemeHoliday.thanksgiving.dateIn(2025), DateTime(2025, 11, 27));
|
||||
expect(ThemeHoliday.thanksgiving.dateIn(2026), DateTime(2026, 11, 26));
|
||||
expect(ThemeHoliday.thanksgiving.dateIn(2029), DateTime(2029, 11, 22));
|
||||
expect(ThemeHoliday.thanksgiving.dateIn(2018), DateTime(2018, 11, 22));
|
||||
});
|
||||
|
||||
test('preset ids exist', () {
|
||||
for (final holiday in ThemeHoliday.values) {
|
||||
expect(CustomTheme.presetById(holiday.themeId), isNotNull);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
group('activeHolidayFor', () {
|
||||
test('Halloween window', () {
|
||||
expect(holidayOn(2026, 10, 13), isNull);
|
||||
expect(holidayOn(2026, 10, 14), halloween);
|
||||
expect(holidayOn(2026, 10, 31), halloween);
|
||||
});
|
||||
|
||||
test('Thanksgiving 2026 (Nov 26) window', () {
|
||||
expect(holidayOn(2026, 11, 1), isNull);
|
||||
expect(holidayOn(2026, 11, 8), isNull);
|
||||
expect(holidayOn(2026, 11, 9), thanksgiving);
|
||||
expect(holidayOn(2026, 11, 26), thanksgiving);
|
||||
});
|
||||
|
||||
test('Nov 1 is Thanksgiving when it falls within 17 days', () {
|
||||
// Thanksgiving 2029 is Nov 22, 21 days after Nov 1: none.
|
||||
expect(holidayOn(2029, 11, 1), isNull);
|
||||
// Thanksgiving 2018 was Nov 22 too; Nov 5 is exactly 17 days out.
|
||||
expect(holidayOn(2018, 11, 5), thanksgiving);
|
||||
expect(holidayOn(2018, 11, 4), isNull);
|
||||
});
|
||||
|
||||
test('Thanksgiving holds until its day, then Christmas waits its turn', () {
|
||||
// Thanksgiving is at the latest Nov 28 and Christmas' window opens
|
||||
// Dec 8, so those two never compete; the days between have no theme.
|
||||
expect(holidayOn(2024, 11, 28), thanksgiving);
|
||||
expect(holidayOn(2024, 11, 29), isNull);
|
||||
expect(holidayOn(2024, 12, 7), isNull);
|
||||
expect(holidayOn(2024, 12, 8), christmas);
|
||||
});
|
||||
|
||||
test('Christmas and New Year windows', () {
|
||||
expect(holidayOn(2026, 12, 7), isNull);
|
||||
expect(holidayOn(2026, 12, 8), christmas);
|
||||
// Dec 15 is within 17 days of New Year's too; Christmas is nearer.
|
||||
expect(holidayOn(2026, 12, 15), christmas);
|
||||
expect(holidayOn(2026, 12, 25), christmas);
|
||||
expect(holidayOn(2026, 12, 26), newYear);
|
||||
expect(holidayOn(2026, 12, 31), newYear);
|
||||
expect(holidayOn(2027, 1, 1), newYear);
|
||||
expect(holidayOn(2027, 1, 2), isNull);
|
||||
});
|
||||
|
||||
test('year wrap gives the coming New Year occurrence', () {
|
||||
final active = activeHolidayFor(DateTime(2026, 12, 26))!;
|
||||
expect(active.date, DateTime(2027, 1, 1));
|
||||
expect(active.daysAway, 6);
|
||||
expect(active.occurrenceKey, 'preset:new_year@2027-01-01');
|
||||
});
|
||||
|
||||
test('no holiday in spring or summer', () {
|
||||
expect(holidayOn(2026, 3, 15), isNull);
|
||||
expect(holidayOn(2026, 7, 4), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('settings JSON', () {
|
||||
test('auto switch defaults to true', () {
|
||||
expect(AppSettings().holidayAutoSwitch, isTrue);
|
||||
expect(AppSettings.fromJson({}).holidayAutoSwitch, isTrue);
|
||||
expect(AppSettings().holidayThemeDismissed, isNull);
|
||||
});
|
||||
|
||||
test('round-trips', () {
|
||||
final settings = AppSettings(
|
||||
holidayAutoSwitch: false,
|
||||
holidayThemeDismissed: 'preset:christmas@2026-12-25',
|
||||
);
|
||||
final decoded = AppSettings.fromJson(
|
||||
jsonDecode(jsonEncode(settings.toJson())) as Map<String, dynamic>,
|
||||
);
|
||||
expect(decoded.holidayAutoSwitch, isFalse);
|
||||
expect(decoded.holidayThemeDismissed, 'preset:christmas@2026-12-25');
|
||||
expect(settings.toJson()['holiday_auto_switch'], isFalse);
|
||||
});
|
||||
|
||||
test('copyWith can clear the dismissal', () {
|
||||
final settings = AppSettings(holidayThemeDismissed: 'x');
|
||||
expect(settings.copyWith().holidayThemeDismissed, 'x');
|
||||
expect(
|
||||
settings.copyWith(holidayThemeDismissed: null).holidayThemeDismissed,
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('AppSettingsService', () {
|
||||
late DateTime now;
|
||||
late AppSettingsService service;
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
now = DateTime(2026, 7, 1, 12);
|
||||
service = AppSettingsService(clock: () => now);
|
||||
await service.loadSettings();
|
||||
});
|
||||
|
||||
tearDown(() => service.dispose());
|
||||
|
||||
test('holiday theme overrides without touching activeThemeId', () async {
|
||||
await service.setActiveTheme('preset:forest');
|
||||
final ownId = service.settings.activeThemeId;
|
||||
expect(service.activeCustomTheme?.id, ownId);
|
||||
|
||||
now = DateTime(2026, 12, 10, 9);
|
||||
expect(service.activeCustomTheme?.id, christmas);
|
||||
expect(service.autoHolidayTheme?.id, christmas);
|
||||
expect(service.settings.activeThemeId, ownId);
|
||||
expect(service.chosenCustomTheme?.id, ownId);
|
||||
|
||||
now = DateTime(2027, 1, 2, 9);
|
||||
expect(service.activeCustomTheme?.id, ownId);
|
||||
expect(service.autoHolidayTheme, isNull);
|
||||
});
|
||||
|
||||
test('stock theme users get the holiday theme too', () {
|
||||
now = DateTime(2026, 10, 31, 20);
|
||||
expect(service.settings.activeThemeId, isNull);
|
||||
expect(service.activeCustomTheme?.id, halloween);
|
||||
});
|
||||
|
||||
test('manual pick dismisses only the current occurrence', () async {
|
||||
now = DateTime(2026, 10, 20);
|
||||
expect(service.activeCustomTheme?.id, halloween);
|
||||
|
||||
await service.setActiveTheme(null);
|
||||
expect(service.activeCustomTheme, isNull);
|
||||
expect(
|
||||
service.settings.holidayThemeDismissed,
|
||||
'preset:halloween@2026-10-31',
|
||||
);
|
||||
|
||||
now = DateTime(2026, 10, 31, 23);
|
||||
expect(service.activeCustomTheme, isNull);
|
||||
|
||||
// Next holiday switches again.
|
||||
now = DateTime(2026, 11, 20);
|
||||
expect(service.activeCustomTheme?.id, thanksgiving);
|
||||
|
||||
// Next year's Halloween too.
|
||||
now = DateTime(2027, 10, 20);
|
||||
expect(service.activeCustomTheme?.id, halloween);
|
||||
});
|
||||
|
||||
test('picking a stock mode dismisses too', () async {
|
||||
now = DateTime(2026, 12, 20);
|
||||
expect(service.activeCustomTheme?.id, christmas);
|
||||
await service.setThemeMode('dark');
|
||||
expect(service.activeCustomTheme, isNull);
|
||||
expect(service.settings.themeMode, 'dark');
|
||||
|
||||
now = DateTime(2026, 12, 26);
|
||||
expect(service.activeCustomTheme?.id, newYear);
|
||||
});
|
||||
|
||||
test(
|
||||
'picking the auto-applied holiday preset is not a dismissal',
|
||||
() async {
|
||||
await service.setActiveTheme('preset:forest');
|
||||
final ownId = service.settings.activeThemeId;
|
||||
now = DateTime(2026, 12, 20);
|
||||
|
||||
await service.setActiveTheme(christmas);
|
||||
expect(service.settings.holidayThemeDismissed, isNull);
|
||||
expect(service.settings.activeThemeId, ownId);
|
||||
expect(service.activeCustomTheme?.id, christmas);
|
||||
|
||||
now = DateTime(2027, 1, 5);
|
||||
expect(service.activeCustomTheme?.id, ownId);
|
||||
},
|
||||
);
|
||||
|
||||
test('a user who picked the holiday preset keeps it', () async {
|
||||
await service.setActiveTheme(halloween);
|
||||
now = DateTime(2026, 10, 20);
|
||||
expect(service.autoHolidayTheme, isNull);
|
||||
expect(service.activeCustomTheme?.id, halloween);
|
||||
now = DateTime(2026, 11, 1);
|
||||
expect(service.activeCustomTheme?.id, halloween);
|
||||
});
|
||||
|
||||
test('auto switch off keeps the user theme', () async {
|
||||
await service.setHolidayAutoSwitch(false);
|
||||
now = DateTime(2026, 12, 25);
|
||||
expect(service.activeCustomTheme, isNull);
|
||||
expect(service.autoHolidayTheme, isNull);
|
||||
|
||||
await service.setHolidayAutoSwitch(true);
|
||||
expect(service.activeCustomTheme?.id, christmas);
|
||||
});
|
||||
|
||||
test('turning auto switch back on forgets the dismissal', () async {
|
||||
now = DateTime(2026, 12, 20);
|
||||
await service.setThemeMode('light');
|
||||
expect(service.activeCustomTheme, isNull);
|
||||
await service.setHolidayAutoSwitch(false);
|
||||
await service.setHolidayAutoSwitch(true);
|
||||
expect(service.settings.holidayThemeDismissed, isNull);
|
||||
expect(service.activeCustomTheme?.id, christmas);
|
||||
});
|
||||
|
||||
test('date timer runs only once started and while enabled', () async {
|
||||
expect(service.hasDateTimer, isFalse);
|
||||
service.startDateWatch();
|
||||
expect(service.hasDateTimer, isTrue);
|
||||
await service.setHolidayAutoSwitch(false);
|
||||
expect(service.hasDateTimer, isFalse);
|
||||
await service.setHolidayAutoSwitch(true);
|
||||
expect(service.hasDateTimer, isTrue);
|
||||
service.dispose();
|
||||
expect(service.hasDateTimer, isFalse);
|
||||
// tearDown disposes again; use a fresh service there.
|
||||
service = AppSettingsService(clock: () => now);
|
||||
});
|
||||
|
||||
test('date change notifies only when the holiday theme changes', () {
|
||||
now = DateTime(2026, 12, 6, 23);
|
||||
service.startDateWatch();
|
||||
var notified = 0;
|
||||
service.addListener(() => notified++);
|
||||
|
||||
now = DateTime(2026, 12, 7, 0, 0, 1);
|
||||
service.checkDateChange();
|
||||
expect(notified, 0);
|
||||
|
||||
now = DateTime(2026, 12, 8, 0, 0, 1);
|
||||
service.checkDateChange();
|
||||
expect(notified, 1);
|
||||
expect(service.activeCustomTheme?.id, christmas);
|
||||
|
||||
now = DateTime(2026, 12, 9, 0, 0, 1);
|
||||
service.checkDateChange();
|
||||
expect(notified, 1);
|
||||
|
||||
now = DateTime(2026, 12, 26, 0, 0, 1);
|
||||
service.checkDateChange();
|
||||
expect(notified, 2);
|
||||
expect(service.activeCustomTheme?.id, newYear);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user