115 lines
3.7 KiB
Dart
115 lines
3.7 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/attention/domain/attention_models.dart';
|
|
|
|
Map<String, dynamic> run([Map<String, dynamic> overrides = const {}]) => {
|
|
'id': 1,
|
|
'name': 'Plan and land',
|
|
'title': null,
|
|
'status': 'failed',
|
|
'created_at': '2026-10-19T10:00:00Z',
|
|
'finished_at': '2026-10-19T10:05:00Z',
|
|
'diagnostic': '',
|
|
...overrides,
|
|
};
|
|
|
|
void main() {
|
|
group('dismissal and clear-all snapshot', () {
|
|
test('a dismissed identity is filtered out and never returns', () {
|
|
final rows = [
|
|
run({'id': 7, 'status': 'waiting', 'title': 'Wait'}),
|
|
];
|
|
final dismissed = attentionDismiss(const {}, '7:Decision');
|
|
expect(attentionEntries(rows, dismissed: dismissed), isEmpty);
|
|
expect(attentionEntries(rows, dismissed: dismissed), isEmpty);
|
|
});
|
|
|
|
test('a different kind for the same run is a different identity', () {
|
|
final dismissed = attentionDismiss(const {}, '7:Decision');
|
|
final failed = run({'id': 7, 'status': 'failed', 'diagnostic': 'later'});
|
|
final entries = attentionEntries([failed], dismissed: dismissed);
|
|
expect(entries.single.key, '7:Failed');
|
|
expect(entries.single.detail, 'later');
|
|
});
|
|
|
|
test('dismiss ignores a blank key and adds once', () {
|
|
final one = attentionDismiss(const {}, '1:Failed');
|
|
expect(one, {'1:Failed'});
|
|
expect(attentionDismiss(one, '1:Failed'), {'1:Failed'});
|
|
expect(attentionDismiss(one, ' '), {'1:Failed'});
|
|
expect(one, {'1:Failed'}, reason: 'input set is not mutated');
|
|
});
|
|
|
|
test('clear all applies only the identities in the open snapshot', () {
|
|
final a = attentionEntryFor(run({'id': 1}))!;
|
|
final snapshot = attentionDismissalSnapshot([a]);
|
|
final b = attentionEntryFor(run({'id': 2}))!;
|
|
final after = attentionDismissAll(const {}, snapshot);
|
|
expect(after, {'1:Failed'});
|
|
expect(after.contains(b.key), isFalse);
|
|
expect(
|
|
attentionEntries([
|
|
run({'id': 1}),
|
|
run({'id': 2}),
|
|
], dismissed: after).map((entry) => entry.runId),
|
|
[2],
|
|
);
|
|
});
|
|
|
|
test('the snapshot is a defensive copy', () {
|
|
final a = attentionEntryFor(run({'id': 1}))!;
|
|
final b = attentionEntryFor(run({'id': 2}))!;
|
|
final live = [a, b];
|
|
final snapshot = attentionDismissalSnapshot(live);
|
|
live.add(attentionEntryFor(run({'id': 3}))!);
|
|
expect(snapshot.map((entry) => entry.runId), [1, 2]);
|
|
expect(snapshot, isNot(same(live)));
|
|
});
|
|
});
|
|
|
|
group('persistence', () {
|
|
test('the key is the documented one', () {
|
|
expect(attentionStorageKey, 'pipelines.next.attention.v1');
|
|
expect(attentionStorageKey, isNot('pipelines.web.attention.v1'));
|
|
});
|
|
|
|
test('encoding is one sorted JSON array and round-trips', () {
|
|
final encoded = encodeAttentionDismissals({
|
|
'9:Failed',
|
|
'1:Decision',
|
|
'4:Failed',
|
|
});
|
|
expect(encoded, '["1:Decision","4:Failed","9:Failed"]');
|
|
expect(decodeAttentionDismissals(encoded), {
|
|
'1:Decision',
|
|
'4:Failed',
|
|
'9:Failed',
|
|
});
|
|
expect(encodeAttentionDismissals(const {}), '[]');
|
|
});
|
|
|
|
test('blank or unreadable storage decodes to empty and never throws', () {
|
|
for (final stored in [
|
|
null,
|
|
'',
|
|
' ',
|
|
'not json',
|
|
'{',
|
|
'"a string"',
|
|
'{}',
|
|
'42',
|
|
]) {
|
|
expect(decodeAttentionDismissals(stored), isEmpty);
|
|
}
|
|
});
|
|
|
|
test('a JSON array keeps only non-empty strings', () {
|
|
expect(
|
|
decodeAttentionDismissals(
|
|
'["1:Failed", 2, null, {"a":1}, "3:Decision", ""]',
|
|
),
|
|
{'1:Failed', '3:Decision'},
|
|
);
|
|
});
|
|
});
|
|
}
|