48 lines
1.3 KiB
Dart
48 lines
1.3 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/chat/domain/chat_clipboard_paste.dart';
|
|
|
|
void main() {
|
|
test('a nameless clipboard file takes the web client name for its type', () {
|
|
expect(chatPastedAttachmentName('image/png', 1), 'pasted-1.png');
|
|
expect(chatPastedAttachmentName('image/jpeg', 2), 'pasted-2.jpg');
|
|
expect(
|
|
chatPastedAttachmentName('application/octet-stream', 3),
|
|
'pasted-3.octetstream',
|
|
);
|
|
expect(chatPastedAttachmentName('', 4), 'pasted-4.bin');
|
|
});
|
|
|
|
test('the unsupported host keeps text paste and reports the gap', () {
|
|
const paste = ChatClipboardPaste.unsupported('no files here');
|
|
|
|
expect(paste.isSupported, isFalse);
|
|
expect(
|
|
() =>
|
|
paste.listen(onFiles: (_) {}, canAccept: () => true, onError: (_) {}),
|
|
throwsUnsupportedError,
|
|
);
|
|
});
|
|
|
|
test('a supported host subscribes once and returns its unsubscribe', () {
|
|
var listens = 0;
|
|
var stops = 0;
|
|
final paste = ChatClipboardPaste(
|
|
subscribe: (onFiles, canAccept, onError) {
|
|
listens += 1;
|
|
return () => stops += 1;
|
|
},
|
|
);
|
|
|
|
final stop = paste.listen(
|
|
onFiles: (_) {},
|
|
canAccept: () => true,
|
|
onError: (_) {},
|
|
);
|
|
|
|
expect(paste.isSupported, isTrue);
|
|
expect(listens, 1);
|
|
stop();
|
|
expect(stops, 1);
|
|
});
|
|
}
|