Files
pipelines/app/test/features/chat/domain/chat_cycle_test.dart
T

67 lines
2.2 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/domain/chat_cycle.dart';
List<String> _ids(List<JsonMap> rows) => [
for (final row in rows) '${row['id']}',
];
String? _after(List<JsonMap> rows, String id) =>
chatSessionAfter(rows, id)?['id'] as String?;
bool _closedFolded(String title) => title != 'Closed';
void main() {
// Server recency order; the list regroups it.
final sessions = <JsonMap>[
{'id': 'r', 'title': 'Recent', 'directory': '/w'},
{'id': 'd', 'title': 'Other', 'directory': '/v'},
{'id': 'c', 'title': 'Done', 'directory': '/w', 'closed_at': 1},
{'id': 's', 'title': 'Second', 'directory': '/w'},
{'id': 'z', 'title': 'Zed', 'directory': '/w', 'starred': true},
{'id': 'a', 'title': 'apple', 'directory': '/v', 'starred': true},
];
test('shown rows: Starred by name, Chats by directory, folded skipped', () {
final folded = chatSessionsShown(
sessions,
query: '',
isOpen: _closedFolded,
);
expect(_ids(folded), ['a', 'z', 'r', 's', 'd']);
final open = chatSessionsShown(sessions, query: '', isOpen: (_) => true);
expect(_ids(open), ['a', 'z', 'r', 's', 'd', 'c']);
final searched = chatSessionsShown(
sessions,
query: 'o',
isOpen: (_) => true,
);
expect(_ids(searched), ['d', 's', 'c']);
});
test('next wraps from the last row to the first', () {
final rows = chatSessionsShown(sessions, query: '', isOpen: _closedFolded);
var id = 'a';
final visited = <String>[];
for (var i = 0; i < rows.length; i++) {
id = _after(rows, id)!;
visited.add(id);
}
expect(visited, ['z', 'r', 's', 'd', 'a']);
});
test('a chat in a folded section moves to the first shown row', () {
final rows = chatSessionsShown(sessions, query: '', isOpen: _closedFolded);
expect(_after(rows, 'c'), 'a');
});
test('nothing to move to without another shown row', () {
final one = <JsonMap>[
{'id': 'only'},
];
expect(_after(one, 'only'), isNull);
expect(_after(const [], 'only'), isNull);
expect(_after(one, 'elsewhere'), 'only');
});
}