mirror of
https://github.com/block/buzz.git
synced 2026-10-27 20:41:57 +00:00
Aligns mobile with desktop's neutral palette and six chat colors. Appearance now offers Light, Dark, and System instead of themes, while preserving community preferences and the single Home and Chat preview pair. Chat colors survive local preference reloads without historical-index remapping, and the Chat preview shows the draft outgoing bubble color. Channel and section icons are removed, section chevrons sit beside names, and section dividers use 7% opacity. DM avatars remain. Validation: `just mobile-check`, 35 focused tests, and the full mobile suite passed (3,351 tests; 4 skipped). Updated light/dark previews were rendered and visually checked. The earlier release was verified on iPhone; this follow-up has not been reinstalled. The earlier repository-wide lint passed, but full `just ci` was stopped for low disk space. Hosted CI is running for the new head. **Intentional design parity:** Section labels and chevrons retain desktop’s `--text-unavailable` colors: light `#959595`, dark `#595959`. Verified against `block/buzz-app` main at `0201b54c496120a44e020834663dc534cae9a79f`. These colors do not meet 4.5:1 text contrast on the mobile section surfaces; the product decision for this PR is to preserve desktop parity and leave them unchanged. Kenneth explicitly accepts this known contrast tradeoff for this PR/release and requests that reviewers treat it as a scoped product exception rather than a blocker. This does not claim WCAG compliance or change the repository-wide accessibility target. Any future contrast adjustment should be coordinated across desktop and mobile. ### Snapshots Channel list: physical iPhone. Appearance and chat colors: Flutter-rendered previews. | Channels | Light | Dark | Chat colors | | --- | --- | --- | --- | |  |  |  |  | --------- Signed-off-by: kenny lopez <klopez4212@gmail.com>
164 lines
5.2 KiB
Dart
164 lines
5.2 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:buzz/shared/theme/theme.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
void main() {
|
|
test('desktop v1 payload round-trips exactly', () {
|
|
final preference = CommunityThemePreference.fromJson({
|
|
'version': 1,
|
|
'theme': 'github-dark',
|
|
'accent': '#c0a2f1',
|
|
'followSystem': false,
|
|
});
|
|
|
|
expect(preference.mode, ThemeMode.dark);
|
|
expect(
|
|
jsonEncode(preference.toJson()),
|
|
'{"version":1,"theme":"github-dark","accent":"#c0a2f1","followSystem":false}',
|
|
);
|
|
});
|
|
|
|
test('rejects unknown themes, accents, and future versions', () {
|
|
for (final payload in [
|
|
{
|
|
'version': 2,
|
|
'theme': 'buzz',
|
|
'accent': '#3b82f6',
|
|
'followSystem': true,
|
|
},
|
|
{
|
|
'version': 1,
|
|
'theme': 'unknown',
|
|
'accent': '#3b82f6',
|
|
'followSystem': true,
|
|
},
|
|
{
|
|
'version': 1,
|
|
'theme': 'buzz',
|
|
'accent': '#000000',
|
|
'followSystem': true,
|
|
},
|
|
]) {
|
|
expect(
|
|
() => CommunityThemePreference.fromJson(payload),
|
|
throwsFormatException,
|
|
);
|
|
}
|
|
});
|
|
|
|
test('storage is scoped by pubkey and normalized relay URL', () async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final storage = CommunityThemeStorage(prefs);
|
|
const a = CommunityThemePreference(
|
|
theme: 'buzz',
|
|
accent: '#3b82f6',
|
|
followSystem: true,
|
|
);
|
|
const b = CommunityThemePreference(
|
|
theme: 'dracula',
|
|
accent: '#ef4444',
|
|
followSystem: false,
|
|
);
|
|
|
|
await storage.write('pk', 'WSS://Relay.Example///', a);
|
|
await storage.write('pk', 'wss://other.example', b);
|
|
|
|
expect(storage.read('pk', 'wss://relay.example'), a);
|
|
expect(storage.read('pk', 'wss://other.example/'), b);
|
|
expect(storage.read('other-pk', 'wss://relay.example'), isNull);
|
|
});
|
|
|
|
test('dirty outbox survives restart and clears only exact ack', () async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final storage = CommunityThemeStorage(prefs);
|
|
const pending = CommunityThemePreference(
|
|
theme: 'dracula',
|
|
accent: '#ef4444',
|
|
followSystem: false,
|
|
);
|
|
const newer = CommunityThemePreference(
|
|
theme: 'houston',
|
|
accent: '#a855f7',
|
|
followSystem: false,
|
|
);
|
|
|
|
await storage.writeOutbox('pk', 'wss://relay.example', pending);
|
|
expect(
|
|
CommunityThemeStorage(prefs).readOutbox('pk', 'wss://relay.example'),
|
|
pending,
|
|
);
|
|
await storage.writeOutbox('pk', 'wss://relay.example', newer);
|
|
await storage.clearOutbox('pk', 'wss://relay.example', pending);
|
|
expect(storage.readOutbox('pk', 'wss://relay.example'), newer);
|
|
await storage.clearOutbox('pk', 'wss://relay.example', newer);
|
|
expect(storage.readOutbox('pk', 'wss://relay.example'), isNull);
|
|
});
|
|
|
|
for (final color in chatColorChoices) {
|
|
for (final mode in ThemeMode.values) {
|
|
test(
|
|
'local ${color.name} ${mode.name} survives a storage restart',
|
|
() async {
|
|
SharedPreferences.setMockInitialValues({
|
|
'buzz_accent_color': 0,
|
|
'buzz_theme_mode': 'light',
|
|
});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final preference = CommunityThemePreference(
|
|
theme: mode == ThemeMode.dark ? buzzDarkThemeName : buzzThemeName,
|
|
accent: color.wireValue,
|
|
followSystem: mode == ThemeMode.system,
|
|
);
|
|
await CommunityThemeStorage(prefs).writeLegacy(preference);
|
|
// Recreate preferences and storage from only the persisted snapshot.
|
|
final disk = {
|
|
for (final key in prefs.getKeys()) key: prefs.get(key)!,
|
|
};
|
|
SharedPreferences.setMockInitialValues(disk);
|
|
final restarted = CommunityThemeStorage(
|
|
await SharedPreferences.getInstance(),
|
|
);
|
|
expect(restarted.legacyPreference(), preference);
|
|
expect(restarted.legacyPreference().mode, mode);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
test('invalid local snapshot falls back to historical migration', () async {
|
|
SharedPreferences.setMockInitialValues({
|
|
'buzz-local-theme.v1': '{"version":99}',
|
|
'buzz_accent_color': 8,
|
|
});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
expect(CommunityThemeStorage(prefs).legacyPreference().accent, 'neutral');
|
|
});
|
|
|
|
test('legacy accent indexes migrate without inventing wire values', () async {
|
|
SharedPreferences.setMockInitialValues({
|
|
'buzz_theme_mode': 'dark',
|
|
'buzz_color_scheme': 'dracula',
|
|
'buzz_accent_color': 8,
|
|
});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final preference = CommunityThemeStorage(prefs).legacyPreference();
|
|
|
|
expect(
|
|
preference,
|
|
const CommunityThemePreference(
|
|
theme: 'dracula',
|
|
accent: 'neutral',
|
|
followSystem: false,
|
|
),
|
|
);
|
|
expect(preference.mode, ThemeMode.dark);
|
|
expect(legacyAccentWireValue(6), '#a855f7');
|
|
expect(legacyAccentWireValue(7), '#6366f1');
|
|
});
|
|
}
|