import 'package:flutter_test/flutter_test.dart'; import 'package:tatlock_ui/core/auth/user_preferences.dart'; void main() { group('UserPreferences', () { group('default constructor', () { test('creates with default values', () { const prefs = UserPreferences(); expect(prefs.theme, equals('system')); expect(prefs.defaultRoom, equals('front-hall')); expect(prefs.preferencesJson, isEmpty); }); }); group('custom constructor', () { test('creates with custom values', () { const prefs = UserPreferences( theme: 'dark', defaultRoom: 'kitchen', preferencesJson: {'sidebar_collapsed': true, 'font_size': 14}, ); expect(prefs.theme, equals('dark')); expect(prefs.defaultRoom, equals('kitchen')); expect(prefs.preferencesJson['sidebar_collapsed'], isTrue); expect(prefs.preferencesJson['font_size'], equals(14)); }); }); group('fromJson', () { test('deserializes from JSON', () { final json = { 'theme': 'light', 'defaultRoom': 'living-room', 'preferencesJson': {'key': 'value'}, }; final prefs = UserPreferences.fromJson(json); expect(prefs.theme, equals('light')); expect(prefs.defaultRoom, equals('living-room')); expect(prefs.preferencesJson['key'], equals('value')); }); test('uses defaults for missing fields', () { final json = {}; final prefs = UserPreferences.fromJson(json); expect(prefs.theme, equals('system')); expect(prefs.defaultRoom, equals('front-hall')); expect(prefs.preferencesJson, isEmpty); }); test('handles partial JSON', () { final json = {'theme': 'dark'}; final prefs = UserPreferences.fromJson(json); expect(prefs.theme, equals('dark')); expect(prefs.defaultRoom, equals('front-hall')); }); }); group('toJson', () { test('serializes to JSON', () { const prefs = UserPreferences( theme: 'dark', defaultRoom: 'office', preferencesJson: {'notifications': true}, ); final json = prefs.toJson(); expect(json['theme'], equals('dark')); expect(json['defaultRoom'], equals('office')); expect(json['preferencesJson']['notifications'], isTrue); }); test('round-trip serialization preserves data', () { const original = UserPreferences( theme: 'light', defaultRoom: 'bedroom', preferencesJson: {'compact_mode': false}, ); final json = original.toJson(); final restored = UserPreferences.fromJson(json); expect(restored.theme, equals(original.theme)); expect(restored.defaultRoom, equals(original.defaultRoom)); expect( restored.preferencesJson['compact_mode'], equals(original.preferencesJson['compact_mode']), ); }); }); group('copyWith', () { test('creates a copy with modified values', () { const original = UserPreferences( theme: 'system', defaultRoom: 'front-hall', ); final updated = original.copyWith(theme: 'dark'); // Original unchanged expect(original.theme, equals('system')); // Updated has new value expect(updated.theme, equals('dark')); // Preserved unchanged values expect(updated.defaultRoom, equals(original.defaultRoom)); }); }); group('equality', () { test('two identical preferences are equal', () { const prefs1 = UserPreferences(theme: 'dark', defaultRoom: 'office'); const prefs2 = UserPreferences(theme: 'dark', defaultRoom: 'office'); expect(prefs1, equals(prefs2)); }); test('different preferences are not equal', () { const prefs1 = UserPreferences(theme: 'dark'); const prefs2 = UserPreferences(theme: 'light'); expect(prefs1, isNot(equals(prefs2))); }); }); group('theme validation', () { test('accepts valid theme values', () { const themes = ['system', 'light', 'dark']; for (final theme in themes) { final prefs = UserPreferences(theme: theme); expect(prefs.theme, equals(theme)); } }); }); }); }