Files
pipelines/app/test/features/chat/conversation/chat_shown_controller_test.dart

89 lines
2.5 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_controller.dart';
import 'chat_thread_fixtures.dart';
void main() {
late FakeChatGateway gateway;
late ChatThreadController controller;
setUp(() {
gateway = FakeChatGateway();
gateway.history = (_) async => chatPage([]);
controller = ChatThreadController(gateway, 's');
});
tearDown(() {
controller.dispose();
gateway.close();
});
test('takes the retained list from the subscribe reply', () async {
gateway.subscribe = () async => {
'chat_shown': {
'session_id': 's',
'items': [
{'id': 'a', 'kind': 'file', 'created_at': 1, 'path': '/h/a.png'},
{'id': 'b', 'kind': 'notify', 'created_at': 2, 'title': 'Done'},
],
},
};
await controller.load();
expect(controller.shown.map((item) => item['id']), ['a', 'b']);
});
test('a pushed frame adds or replaces one item of this chat only', () async {
gateway.subscribe = () async => {
'chat_shown': {
'session_id': 's',
'items': [
{'id': 'a', 'kind': 'notify', 'created_at': 1, 'delivered': false},
],
},
};
await controller.load();
var notified = 0;
controller.transcriptChanges.addListener(() => notified++);
gateway.emitRaw({
'type': 'chat_shown',
'chat_shown': {
'session_id': 'other',
'items': [
{'id': 'x', 'kind': 'notify', 'created_at': 3},
],
},
});
gateway.emitRaw({
'type': 'chat_shown',
'chat_shown': {
'session_id': 's',
'items': [
{'id': 'a', 'kind': 'notify', 'created_at': 1, 'delivered': true},
{'id': 'c', 'kind': 'html', 'created_at': 4, 'html': '<p>x</p>'},
],
},
});
await pumpEventQueue();
expect(controller.shown.map((item) => item['id']), ['a', 'c']);
expect(controller.shown.first['delivered'], isTrue);
expect(notified, 1);
});
test('a resync re-subscribes and adopts the server list', () async {
var round = 0;
gateway.subscribe = () async => {
'chat_shown': {
'session_id': 's',
'items': [
{'id': 'r$round', 'kind': 'notify', 'created_at': 1},
],
},
};
gateway.onSubscribe = () => round++;
await controller.load();
expect(controller.shown.single['id'], 'r1');
await controller.resync();
expect(controller.shown.single['id'], 'r2');
});
}