Share the IPFS link attach flow between the chat screens
Move the pick/read/upload/insert flow that was copied into both chat screens into helpers/ipfs_link_attach_flow.dart; each screen passes only its byte limit and outbound encoder.
This commit is contained in:
1 parent
0620e8f27a
commit
cc33595f13
4 files changed
+221
-208
No files matched your search
@@ -0,0 +1,76 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/helpers/ipfs_link_attach_flow.dart';
|
||||
|
||||
void main() {
|
||||
const url = 'ipfs://cid';
|
||||
String identity(String text) => text;
|
||||
|
||||
test('puts the link before an empty draft with a trailing space', () {
|
||||
expect(
|
||||
composeIpfsLinkDraft(
|
||||
messageUrl: url,
|
||||
existingText: '',
|
||||
maxBytes: 100,
|
||||
encodeOutbound: identity,
|
||||
),
|
||||
'$url ',
|
||||
);
|
||||
});
|
||||
|
||||
test('keeps a draft that fits after the link', () {
|
||||
expect(
|
||||
composeIpfsLinkDraft(
|
||||
messageUrl: url,
|
||||
existingText: 'hello',
|
||||
maxBytes: 100,
|
||||
encodeOutbound: identity,
|
||||
),
|
||||
'$url\nhello',
|
||||
);
|
||||
});
|
||||
|
||||
test('trims the draft until the encoded text fits', () {
|
||||
expect(
|
||||
composeIpfsLinkDraft(
|
||||
messageUrl: url,
|
||||
existingText: 'hello',
|
||||
maxBytes: url.length + 3,
|
||||
encodeOutbound: identity,
|
||||
),
|
||||
'$url\nhe',
|
||||
);
|
||||
});
|
||||
|
||||
test('measures the encoded form', () {
|
||||
expect(
|
||||
composeIpfsLinkDraft(
|
||||
messageUrl: url,
|
||||
existingText: 'hello',
|
||||
maxBytes: url.length + 3,
|
||||
encodeOutbound: (text) => 'x$text',
|
||||
),
|
||||
'$url\nh',
|
||||
);
|
||||
});
|
||||
|
||||
test('returns null when the link alone does not fit', () {
|
||||
expect(
|
||||
composeIpfsLinkDraft(
|
||||
messageUrl: url,
|
||||
existingText: 'hello',
|
||||
maxBytes: 4,
|
||||
encodeOutbound: identity,
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
composeIpfsLinkDraft(
|
||||
messageUrl: url,
|
||||
existingText: '',
|
||||
maxBytes: 4,
|
||||
encodeOutbound: identity,
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user