95 lines
3.2 KiB
Dart
95 lines
3.2 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:relationship_saver/features/local/local_models.dart';
|
|
import 'package:relationship_saver/features/share_intake/share_payload_parser.dart';
|
|
|
|
void main() {
|
|
test('parses url-only payload', () {
|
|
final SharedPayload payload = SharePayloadParser.parse(
|
|
rawText: 'https://example.com/date-night',
|
|
sourceApp: 'share_sheet',
|
|
platform: 'android',
|
|
);
|
|
|
|
expect(payload.payloadType, SharedPayloadType.url);
|
|
expect(payload.url, 'https://example.com/date-night');
|
|
expect(payload.rawText, isEmpty);
|
|
});
|
|
|
|
test('parses text plus url payload', () {
|
|
final SharedPayload payload = SharePayloadParser.parse(
|
|
rawText: 'Could be a good anniversary place https://example.com',
|
|
sourceApp: 'share_sheet',
|
|
platform: 'android',
|
|
);
|
|
|
|
expect(payload.payloadType, SharedPayloadType.textWithUrl);
|
|
expect(payload.url, 'https://example.com');
|
|
expect(payload.rawText, 'Could be a good anniversary place');
|
|
});
|
|
|
|
test('preserves WhatsApp sender extraction when pattern matches', () {
|
|
final SharedPayload payload = SharePayloadParser.parse(
|
|
rawText: 'Ava Hart: loves cozy Italian restaurants',
|
|
sourceApp: 'whatsapp',
|
|
platform: 'ios',
|
|
);
|
|
|
|
expect(payload.sourceDisplayName, 'Ava Hart');
|
|
expect(payload.sourceUserId, 'wa:ava hart');
|
|
expect(payload.rawText, 'loves cozy Italian restaurants');
|
|
});
|
|
|
|
test('stores source message datetime when WhatsApp text includes one', () {
|
|
final SharedPayload payload = SharePayloadParser.parse(
|
|
rawText: '[19/05/2026, 14:30] Ava Hart: ginger tea helped',
|
|
sourceApp: 'whatsapp',
|
|
platform: 'ios',
|
|
);
|
|
|
|
expect(payload.sourceDisplayName, 'Ava Hart');
|
|
expect(payload.rawText, 'ginger tea helped');
|
|
expect(payload.sharedMessageDateTime, DateTime(2026, 5, 19, 14, 30));
|
|
expect(payload.parsingHints, contains('shared_message_datetime_detected'));
|
|
expect(payload.metadata, contains('shared_message_datetime'));
|
|
});
|
|
|
|
test(
|
|
'does not store source message datetime for arbitrary content dates',
|
|
() {
|
|
final SharedPayload payload = SharePayloadParser.parse(
|
|
rawText: 'Ava birthday is on May 20 and she likes ginger tea.',
|
|
sourceApp: 'share_sheet',
|
|
platform: 'ios',
|
|
);
|
|
|
|
expect(payload.sharedMessageDateTime, isNull);
|
|
},
|
|
);
|
|
|
|
test('uses explicit signal source app hint and extracts sender', () {
|
|
final SharedPayload payload = SharePayloadParser.parse(
|
|
rawText: 'Marek: this concert looks promising',
|
|
sourceApp: 'signal',
|
|
platform: 'android',
|
|
);
|
|
|
|
expect(payload.sourceApp, 'signal');
|
|
expect(payload.sourceDisplayName, 'Marek');
|
|
expect(payload.sourceUserId, 'signal:marek');
|
|
expect(payload.rawText, 'this concert looks promising');
|
|
});
|
|
|
|
test('normalizes notes hint without trying to invent sender metadata', () {
|
|
final SharedPayload payload = SharePayloadParser.parse(
|
|
rawText: 'Dinner idea from Notes https://example.com',
|
|
sourceApp: 'notes',
|
|
platform: 'ios',
|
|
);
|
|
|
|
expect(payload.sourceApp, 'notes');
|
|
expect(payload.sourceDisplayName, isNull);
|
|
expect(payload.payloadType, SharedPayloadType.textWithUrl);
|
|
expect(payload.rawText, 'Dinner idea from Notes');
|
|
});
|
|
}
|