add app test suite — unit, widget, golden, a11y (168 tests)
Four layers under app/test/:
* kernel/, extension/ — unit tests for every kernel service and
the extension contract. i18n fallback chain gets the full
matrix (exact/lang/default/placeholder, namespace isolation,
unknown namespace, interpolation). Theme resolver and
extension-manager topo sort covered.
* widgets/, builtin/ — widget tests for every primitive and each
Tier 0 built-in. Assertions reach into the Semantics node so
a missing label fails structurally, not visually.
* goldens/ — Alchemist + Ahem font for cross-platform pixel
stability; primitives only (button, tab bar, icon set). No
goldens for compositions — they'd churn through every tier.
* a11y/ — contract-level gate: semantic coverage walks the
built-in catalogue, contrast walks every token pair in every
bundled theme against WCAG-AA thresholds (catches real
regressions: the first run caught `tab.inactive_text` at 2.81
in summer-night), i18n coverage asserts every referenced key
exists in its catalog (exists-in-map, not "key == value" — too
ambiguous for keys that happen to equal their translation).
Helpers under helpers/: `KernelFixture.create()` boots a
KernelServices with in-memory stores + a FakeDaemonClient (no
socket, drivable connected-state), `widget_harness` wraps a
widget in the minimum tree that resolves theme + i18n.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:clide_app/kernel/kernel.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('SettingsStore', () {
|
||||
late Directory tmp;
|
||||
late SettingsStore store;
|
||||
|
||||
setUp(() async {
|
||||
tmp = await Directory.systemTemp.createTemp('clide_settings_');
|
||||
store = SettingsStore(appDir: tmp);
|
||||
await store.load();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
store.dispose();
|
||||
if (await tmp.exists()) {
|
||||
try {
|
||||
await tmp.delete(recursive: true);
|
||||
} catch (_) {}
|
||||
}
|
||||
});
|
||||
|
||||
test('scope key validation — rejects non-standard prefixes', () async {
|
||||
expect(
|
||||
() => store.get<String>('nothing.here'),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
);
|
||||
expect(
|
||||
() => store.set('notascope.key', 'v'),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('app.* scope round-trips via YAML on disk', () async {
|
||||
await store.set<String>('app.theme.current', 'summer-night');
|
||||
expect(store.get<String>('app.theme.current'), 'summer-night');
|
||||
final loaded = SettingsStore(appDir: tmp);
|
||||
await loaded.load();
|
||||
expect(loaded.get<String>('app.theme.current'), 'summer-night');
|
||||
loaded.dispose();
|
||||
});
|
||||
|
||||
test('app.* scope supports bool + int + list', () async {
|
||||
await store.set<bool>('app.extensions.git.enabled', false);
|
||||
await store.set<int>('app.layout.width', 240);
|
||||
await store.set<List<String>>('app.recent', const ['/a', '/b']);
|
||||
final loaded = SettingsStore(appDir: tmp);
|
||||
await loaded.load();
|
||||
expect(loaded.get<bool>('app.extensions.git.enabled'), false);
|
||||
expect(loaded.get<int>('app.layout.width'), 240);
|
||||
expect(loaded.get<List<dynamic>>('app.recent'), ['/a', '/b']);
|
||||
loaded.dispose();
|
||||
});
|
||||
|
||||
test('setting a project.* key without an open project throws', () async {
|
||||
expect(
|
||||
() => store.set('project.thing', 'x'),
|
||||
throwsA(isA<StateError>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('project scope is isolated from app scope', () async {
|
||||
final projectDir = await Directory.systemTemp.createTemp('clide_proj_');
|
||||
try {
|
||||
await store.setProjectDir(projectDir);
|
||||
await store.set<String>('app.global', 'A');
|
||||
await store.set<String>('project.scoped', 'P');
|
||||
expect(store.get<String>('app.global'), 'A');
|
||||
expect(store.get<String>('project.scoped'), 'P');
|
||||
// Reload project dir (simulate reopening) and confirm app values
|
||||
// don't leak into project store.
|
||||
await store.setProjectDir(null);
|
||||
expect(store.get<String>('app.global'), 'A');
|
||||
expect(store.get<String>('project.scoped'), isNull);
|
||||
await store.setProjectDir(projectDir);
|
||||
expect(store.get<String>('project.scoped'), 'P');
|
||||
} finally {
|
||||
try {
|
||||
await projectDir.delete(recursive: true);
|
||||
} catch (_) {}
|
||||
}
|
||||
});
|
||||
|
||||
test('notifyListeners fires on set and load', () async {
|
||||
var count = 0;
|
||||
store.addListener(() => count++);
|
||||
await store.set<String>('app.k', 'v');
|
||||
expect(count, greaterThanOrEqualTo(1));
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user