Skip to content

Commit 52385fa

Browse files
Merge pull request #136 from QueryaHub/issue/105-theme-definition-tests
test(theme): ThemeDefinition tests and equality (#105)
2 parents 30db7f5 + 529f9aa commit 52385fa

2 files changed

Lines changed: 119 additions & 0 deletions

File tree

‎lib/core/theme/theme_definition.dart‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,29 @@ class ThemeDefinition {
3939

4040
String get stableCacheKey =>
4141
'${source.name}:$id:${contentHash ?? path ?? name}';
42+
43+
@override
44+
bool operator ==(Object other) =>
45+
identical(this, other) ||
46+
other is ThemeDefinition &&
47+
id == other.id &&
48+
name == other.name &&
49+
source == other.source &&
50+
format == other.format &&
51+
isDark == other.isDark &&
52+
path == other.path &&
53+
lastModified == other.lastModified &&
54+
contentHash == other.contentHash;
55+
56+
@override
57+
int get hashCode => Object.hash(
58+
id,
59+
name,
60+
source,
61+
format,
62+
isDark,
63+
path,
64+
lastModified,
65+
contentHash,
66+
);
4267
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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

Comments
 (0)