56 lines
1.9 KiB
Dart
56 lines
1.9 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:yumi/shared/business_logic/models/res/login_res.dart';
|
|
import 'package:yumi/shared/tools/sc_chat_bubble_message_data.dart';
|
|
|
|
void main() {
|
|
group('chat bubble message snapshot', () {
|
|
test('keeps the bubble URL used when the message is sent', () {
|
|
final cloudData = scEncodeChatBubbleMessageSnapshot(
|
|
PropsResources(
|
|
imSendCoverUrl: 'https://example.com/bubble.png',
|
|
sourceUrl: 'https://example.com/bubble.svga?version=1',
|
|
),
|
|
);
|
|
|
|
final snapshot = scDecodeChatBubbleMessageSnapshot(cloudData);
|
|
|
|
expect(snapshot.hasSnapshot, isTrue);
|
|
expect(snapshot.imageUrl, 'https://example.com/bubble.svga?version=1');
|
|
});
|
|
|
|
test('records an explicit disabled state', () {
|
|
final cloudData = scEncodeChatBubbleMessageSnapshot(null);
|
|
|
|
final snapshot = scDecodeChatBubbleMessageSnapshot(cloudData);
|
|
|
|
expect(snapshot.hasSnapshot, isTrue);
|
|
expect(snapshot.imageUrl, isEmpty);
|
|
});
|
|
|
|
test('a later disabled message does not change an earlier snapshot', () {
|
|
final enabledMessage = scEncodeChatBubbleMessageSnapshot(
|
|
PropsResources(imSendCoverUrl: 'https://example.com/enabled.png'),
|
|
);
|
|
final disabledMessage = scEncodeChatBubbleMessageSnapshot(null);
|
|
|
|
expect(
|
|
scDecodeChatBubbleMessageSnapshot(enabledMessage).imageUrl,
|
|
'https://example.com/enabled.png',
|
|
);
|
|
expect(
|
|
scDecodeChatBubbleMessageSnapshot(disabledMessage).imageUrl,
|
|
isEmpty,
|
|
);
|
|
});
|
|
|
|
test('leaves legacy and malformed cloud data without a snapshot', () {
|
|
for (final cloudData in [null, '', '{bad json', '{"other":true}']) {
|
|
final snapshot = scDecodeChatBubbleMessageSnapshot(cloudData);
|
|
|
|
expect(snapshot.hasSnapshot, isFalse);
|
|
expect(snapshot.imageUrl, isEmpty);
|
|
}
|
|
});
|
|
});
|
|
}
|