mirror of
https://github.com/block/buzz.git
synced 2026-11-25 10:42:26 +00:00
fix(theme): preserve legacy appearance migration
Signed-off-by: kenny lopez <klopez4212@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:buzz/shared/theme/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -24,7 +25,7 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('older v1 payloads gain capability-independent defaults', () {
|
||||
test('older v1 payloads retain missing desktop-only fields', () {
|
||||
final preference = CommunityThemePreference.fromJson({
|
||||
'version': 1,
|
||||
'theme': 'buzz',
|
||||
@@ -35,7 +36,56 @@ void main() {
|
||||
expect(preference.glassBackground, isFalse);
|
||||
expect(preference.glassOpacity, 65);
|
||||
expect(preference.prominentActiveTab, isFalse);
|
||||
expect(preference.toJson(), containsPair('glassOpacity', 65));
|
||||
expect(preference.toJson(), isNot(contains('glassBackground')));
|
||||
expect(preference.toJson(), isNot(contains('glassOpacity')));
|
||||
expect(preference.toJson(), isNot(contains('prominentActiveTab')));
|
||||
});
|
||||
|
||||
test('mobile edits do not widen legacy appearance fields with defaults', () {
|
||||
final legacy = CommunityThemePreference.fromJson({
|
||||
'version': 1,
|
||||
'theme': 'buzz',
|
||||
'accent': '#3b82f6',
|
||||
'followSystem': true,
|
||||
});
|
||||
|
||||
final edited = legacy.copyWith(accent: '#ef4444');
|
||||
|
||||
expect(edited.toJson(), {
|
||||
'version': 1,
|
||||
'theme': 'buzz',
|
||||
'accent': '#ef4444',
|
||||
'followSystem': true,
|
||||
});
|
||||
|
||||
expect(legacy.copyWith(glassOpacity: 70).toJson(), {
|
||||
'version': 1,
|
||||
'theme': 'buzz',
|
||||
'accent': '#3b82f6',
|
||||
'followSystem': true,
|
||||
'glassOpacity': 70,
|
||||
});
|
||||
});
|
||||
|
||||
test('mobile appearance limits match the shared wire contract', () {
|
||||
final contract =
|
||||
jsonDecode(File('../schema/community-theme-v1.json').readAsStringSync())
|
||||
as Map<String, dynamic>;
|
||||
final properties = contract['properties'] as Map<String, dynamic>;
|
||||
final glassBackground =
|
||||
properties['glassBackground'] as Map<String, dynamic>;
|
||||
final glassOpacity = properties['glassOpacity'] as Map<String, dynamic>;
|
||||
final prominentActiveTab =
|
||||
properties['prominentActiveTab'] as Map<String, dynamic>;
|
||||
|
||||
expect(defaultCommunityGlassBackground, glassBackground['default'] as bool);
|
||||
expect(defaultCommunityGlassOpacity, glassOpacity['default'] as int);
|
||||
expect(minCommunityGlassOpacity, glassOpacity['minimum'] as int);
|
||||
expect(maxCommunityGlassOpacity, glassOpacity['maximum'] as int);
|
||||
expect(
|
||||
defaultCommunityProminentActiveTab,
|
||||
prominentActiveTab['default'] as bool,
|
||||
);
|
||||
});
|
||||
|
||||
test('rejects invalid theme and appearance values', () {
|
||||
|
||||
@@ -11,6 +11,65 @@ import 'package:nostr/nostr.dart' as nostr;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'mobile edit preserves omitted desktop-only fields from a legacy cache',
|
||||
() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final keys = nostr.Keys.generate();
|
||||
final storage = CommunityThemeStorage(prefs);
|
||||
await prefs.setString(
|
||||
storage.key(keys.public, 'https://relay.example'),
|
||||
jsonEncode({
|
||||
'version': 1,
|
||||
'theme': 'buzz',
|
||||
'accent': '#3b82f6',
|
||||
'followSystem': true,
|
||||
}),
|
||||
);
|
||||
final session = _ThemeRelaySession(
|
||||
keys.nsec,
|
||||
keys.public,
|
||||
initialStatus: SessionStatus.reconnecting,
|
||||
);
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
communityThemeStorageProvider.overrideWithValue(storage),
|
||||
relayConfigProvider.overrideWith(() => _RelayConfig(keys.nsec)),
|
||||
relaySessionProvider.overrideWith(() => session),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
container.listen(
|
||||
communityThemeProvider,
|
||||
(_, _) {},
|
||||
fireImmediately: true,
|
||||
);
|
||||
|
||||
container
|
||||
.read(communityThemeProvider.notifier)
|
||||
.setAccent(accentIndexForWireValue('#ef4444')!);
|
||||
|
||||
await _waitUntil(() {
|
||||
final raw = prefs.getString(
|
||||
storage.key(keys.public, 'https://relay.example'),
|
||||
);
|
||||
if (raw == null) return false;
|
||||
return (jsonDecode(raw) as Map<String, dynamic>)['accent'] == '#ef4444';
|
||||
});
|
||||
final persisted =
|
||||
jsonDecode(
|
||||
prefs.getString(
|
||||
storage.key(keys.public, 'https://relay.example'),
|
||||
)!,
|
||||
)
|
||||
as Map<String, dynamic>;
|
||||
expect(persisted, isNot(contains('glassBackground')));
|
||||
expect(persisted, isNot(contains('glassOpacity')));
|
||||
expect(persisted, isNot(contains('prominentActiveTab')));
|
||||
},
|
||||
);
|
||||
|
||||
test('mobile edits retain desktop-only appearance preferences', () async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
Reference in New Issue
Block a user