merge(app): land chat-attach-model micro-slice
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_attachment_draft.dart';
|
||||
|
||||
ChatAttachment attachment(
|
||||
String name,
|
||||
int sizeBytes, {
|
||||
String mime = 'text/plain',
|
||||
}) => ChatAttachment(name: name, mime: mime, sizeBytes: sizeBytes);
|
||||
|
||||
void main() {
|
||||
test('adds attachments in order and records their metadata', () {
|
||||
final draft = ChatAttachmentDraft();
|
||||
const screenshot = ChatAttachment(
|
||||
name: 'screen.png',
|
||||
mime: 'image/png',
|
||||
sizeBytes: 2048,
|
||||
);
|
||||
|
||||
expect(draft.add(screenshot), isNull);
|
||||
expect(draft.add(attachment('notes.txt', 512)), isNull);
|
||||
|
||||
expect(draft.attachments, [screenshot, attachment('notes.txt', 512)]);
|
||||
expect(draft.totalBytes, 2560);
|
||||
expect(draft.isEmpty, isFalse);
|
||||
expect(
|
||||
() => draft.attachments.add(attachment('other.txt', 1)),
|
||||
throwsUnsupportedError,
|
||||
);
|
||||
});
|
||||
|
||||
test('removes only the requested attachment', () {
|
||||
final draft = ChatAttachmentDraft();
|
||||
final first = attachment('first.txt', 100);
|
||||
final second = attachment('second.txt', 200);
|
||||
draft.add(first);
|
||||
draft.add(second);
|
||||
|
||||
expect(draft.remove(first), isTrue);
|
||||
expect(draft.attachments, [second]);
|
||||
expect(draft.totalBytes, 200);
|
||||
expect(draft.remove(first), isFalse);
|
||||
expect(draft.attachments, [second]);
|
||||
});
|
||||
|
||||
test('accepts exactly 1 MiB in total', () {
|
||||
final draft = ChatAttachmentDraft();
|
||||
|
||||
expect(draft.add(attachment('large.bin', 700000)), isNull);
|
||||
expect(draft.add(attachment('rest.bin', 348576)), isNull);
|
||||
expect(draft.totalBytes, ChatAttachmentDraft.maxTotalBytes);
|
||||
expect(draft.attachments, hasLength(2));
|
||||
});
|
||||
|
||||
test('refuses one byte over the limit and keeps the existing list', () {
|
||||
final draft = ChatAttachmentDraft();
|
||||
final kept = attachment('kept.bin', ChatAttachmentDraft.maxTotalBytes);
|
||||
draft.add(kept);
|
||||
|
||||
final refusal = draft.add(attachment('extra.bin', 1));
|
||||
|
||||
expect(refusal, ChatAttachmentRefusal.totalTooLarge);
|
||||
expect(
|
||||
refusal!.message,
|
||||
'Attachments are too large for web chat (1 MiB total).',
|
||||
);
|
||||
expect(draft.attachments, [kept]);
|
||||
expect(draft.totalBytes, ChatAttachmentDraft.maxTotalBytes);
|
||||
});
|
||||
|
||||
test('refuses a blank name without adding anything', () {
|
||||
final draft = ChatAttachmentDraft();
|
||||
|
||||
expect(draft.add(attachment('', 10)), ChatAttachmentRefusal.blankName);
|
||||
expect(draft.add(attachment(' ', 10)), ChatAttachmentRefusal.blankName);
|
||||
expect(
|
||||
ChatAttachmentRefusal.blankName.message,
|
||||
'An attachment needs a file name.',
|
||||
);
|
||||
expect(draft.attachments, isEmpty);
|
||||
expect(draft.totalBytes, 0);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user