Files
meshcore-open/test/helpers/message_image_helper_test.dart
T
2026-08-07 19:28:43 +02:00

68 lines
2.2 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/helpers/message_image_helper.dart';
void main() {
group('MessageImageHelper', () {
test('parses short pyx ids', () {
final attachment = MessageImageHelper.parse(
'my picture: https://pyx.li/?i=RzmdkTsE text',
);
expect(attachment, isNotNull);
expect(attachment, 'https://pyx.li/i/RzmdkTsE.jpg');
});
test('parses direct pyx image urls', () {
final attachment = MessageImageHelper.parse('https://pyx.li/?i=Cd1KFiwu');
expect(attachment, isNotNull);
expect(attachment, 'https://pyx.li/i/Cd1KFiwu.jpg');
});
test('parses provider-hosted ipfs links', () {
final attachment = MessageImageHelper.parse(
'my picture: https://uneven-plum-tarantula.myfilebase.com/ipfs/bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly text',
);
expect(attachment, isNotNull);
expect(
attachment,
'https://uneven-plum-tarantula.myfilebase.com/ipfs/bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly',
);
});
test('parses direct ipfs cid urls', () {
final attachment = MessageImageHelper.parse(
'my picture: ipfs://bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly text',
);
expect(attachment, isNotNull);
expect(
attachment,
'https://ipfs.io/ipfs/bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly',
);
});
test('parses http image urls', () {
final attachment = MessageImageHelper.parse(
'see this image https://example.com/picture.png?size=large additional text',
);
expect(attachment, isNotNull);
expect(attachment, 'https://example.com/picture.png?size=large');
});
test('returns null for plain text', () {
expect(MessageImageHelper.parse('hello world'), isNull);
});
test('returns null for non-image ipfs gateway url', () async {
final attachment = await MessageImageHelper.parseVerified(
'https://lime-famous-rat-748.mypinata.cloud/ipfs/bafybeih3jqv36rsxqx7yw3k3ixhganrevrk7xmcxgkr2zuzjegxdytb3nq',
);
expect(attachment, isNull);
});
});
}