|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:querya_desktop/core/theme/theme_definition.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + group('ThemeDefinition', () { |
| 6 | + test('isFileBacked is true for file-backed sources', () { |
| 7 | + expect( |
| 8 | + _definition(source: ThemeSource.filesystem).isFileBacked, |
| 9 | + isTrue, |
| 10 | + ); |
| 11 | + expect( |
| 12 | + _definition(source: ThemeSource.imported).isFileBacked, |
| 13 | + isTrue, |
| 14 | + ); |
| 15 | + expect( |
| 16 | + _definition(source: ThemeSource.legacyImported).isFileBacked, |
| 17 | + isTrue, |
| 18 | + ); |
| 19 | + }); |
| 20 | + |
| 21 | + test('isFileBacked is false for built-in themes', () { |
| 22 | + expect( |
| 23 | + _definition(source: ThemeSource.builtin).isFileBacked, |
| 24 | + isFalse, |
| 25 | + ); |
| 26 | + }); |
| 27 | + |
| 28 | + test('stableCacheKey includes source, id, and content hash', () { |
| 29 | + final definition = _definition( |
| 30 | + id: 'cyberpunk-neon', |
| 31 | + source: ThemeSource.filesystem, |
| 32 | + contentHash: 'hash-v1', |
| 33 | + ); |
| 34 | + |
| 35 | + expect( |
| 36 | + definition.stableCacheKey, |
| 37 | + 'filesystem:cyberpunk-neon:hash-v1', |
| 38 | + ); |
| 39 | + }); |
| 40 | + |
| 41 | + test('stableCacheKey changes when contentHash changes', () { |
| 42 | + final base = _definition(contentHash: 'hash-v1'); |
| 43 | + final updated = _definition(contentHash: 'hash-v2'); |
| 44 | + |
| 45 | + expect(base.stableCacheKey, isNot(updated.stableCacheKey)); |
| 46 | + }); |
| 47 | + |
| 48 | + test('stableCacheKey falls back to path then name without hash', () { |
| 49 | + final withPath = _definition( |
| 50 | + contentHash: null, |
| 51 | + path: '/data/themes/custom.json', |
| 52 | + ); |
| 53 | + final withNameOnly = _definition( |
| 54 | + contentHash: null, |
| 55 | + path: null, |
| 56 | + name: 'Querya Dark', |
| 57 | + ); |
| 58 | + |
| 59 | + expect(withPath.stableCacheKey, contains('/data/themes/custom.json')); |
| 60 | + expect(withNameOnly.stableCacheKey, endsWith('Querya Dark')); |
| 61 | + }); |
| 62 | + |
| 63 | + test('value equality compares metadata fields', () { |
| 64 | + final a = _definition(contentHash: 'hash-v1'); |
| 65 | + final b = _definition(contentHash: 'hash-v1'); |
| 66 | + final c = _definition(contentHash: 'hash-v2'); |
| 67 | + |
| 68 | + expect(a, equals(b)); |
| 69 | + expect(a, isNot(equals(c))); |
| 70 | + }); |
| 71 | + }); |
| 72 | +} |
| 73 | + |
| 74 | +ThemeDefinition _definition({ |
| 75 | + String id = 'fixture-custom-dark', |
| 76 | + String name = 'Fixture Custom Dark', |
| 77 | + ThemeSource source = ThemeSource.filesystem, |
| 78 | + ThemeFormat format = ThemeFormat.queryaCustom, |
| 79 | + bool isDark = true, |
| 80 | + String? path = '/tmp/fixture-custom-dark.json', |
| 81 | + DateTime? lastModified, |
| 82 | + String? contentHash = 'abc123', |
| 83 | +}) { |
| 84 | + return ThemeDefinition( |
| 85 | + id: id, |
| 86 | + name: name, |
| 87 | + source: source, |
| 88 | + format: format, |
| 89 | + isDark: isDark, |
| 90 | + path: path, |
| 91 | + lastModified: lastModified, |
| 92 | + contentHash: contentHash, |
| 93 | + ); |
| 94 | +} |
0 commit comments