Skip to content

Commit 2c77d05

Browse files
test: add tests to message reply box
1 parent 99108d4 commit 2c77d05

File tree

3 files changed

+309
-81
lines changed

3 files changed

+309
-81
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_riverpod/flutter_riverpod.dart';
3+
import 'package:flutter_screenutil/flutter_screenutil.dart';
4+
import 'package:gap/gap.dart';
5+
import 'package:whitenoise/config/providers/localization_provider.dart';
6+
import 'package:whitenoise/domain/models/message_model.dart';
7+
import 'package:whitenoise/ui/chat/widgets/message_media_tile.dart';
8+
import 'package:whitenoise/ui/core/themes/src/extensions.dart';
9+
import 'package:whitenoise/utils/message_utils.dart';
10+
11+
class MessageReplyBox extends ConsumerWidget {
12+
const MessageReplyBox({super.key, this.replyingTo, this.onTap});
13+
final MessageModel? replyingTo;
14+
final VoidCallback? onTap;
15+
16+
@override
17+
Widget build(BuildContext context, WidgetRef ref) {
18+
// Watch localization changes
19+
ref.watch(currentLocaleProvider);
20+
if (replyingTo == null) {
21+
return const SizedBox.shrink();
22+
}
23+
return Container(
24+
margin: EdgeInsets.only(bottom: 8.h),
25+
child: Material(
26+
color: context.colors.secondary,
27+
child: InkWell(
28+
onTap: onTap,
29+
child: Container(
30+
padding: EdgeInsets.all(8.w),
31+
decoration: BoxDecoration(
32+
border: Border(
33+
left: BorderSide(
34+
color: context.colors.mutedForeground,
35+
width: 3.0,
36+
),
37+
),
38+
),
39+
child: Row(
40+
children: [
41+
if (replyingTo?.mediaAttachments.isNotEmpty ?? false) ...[
42+
Padding(
43+
padding: EdgeInsets.only(right: 8.w),
44+
child: MessageMediaTile(
45+
mediaFile: replyingTo!.mediaAttachments.first,
46+
size: 32.w,
47+
),
48+
),
49+
],
50+
Expanded(
51+
child: Column(
52+
crossAxisAlignment: CrossAxisAlignment.stretch,
53+
children: [
54+
Text(
55+
MessageUtils.getDisplayName(replyingTo, null),
56+
style: TextStyle(
57+
color: context.colors.mutedForeground,
58+
fontSize: 12.sp,
59+
fontWeight: FontWeight.w600,
60+
),
61+
maxLines: 1,
62+
overflow: TextOverflow.ellipsis,
63+
),
64+
Gap(4.h),
65+
Text(
66+
replyingTo?.content ?? '',
67+
style: TextStyle(
68+
color: context.colors.primary,
69+
fontSize: 12.sp,
70+
fontWeight: FontWeight.w600,
71+
),
72+
maxLines: 1,
73+
overflow: TextOverflow.ellipsis,
74+
),
75+
],
76+
),
77+
),
78+
],
79+
),
80+
),
81+
),
82+
),
83+
);
84+
}
85+
}

lib/ui/chat/widgets/message_widget.dart

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
import 'dart:io';
22

33
import 'package:flutter/material.dart';
4-
import 'package:flutter_riverpod/flutter_riverpod.dart';
54
import 'package:flutter_screenutil/flutter_screenutil.dart';
65
import 'package:gap/gap.dart';
76

8-
import 'package:whitenoise/config/providers/localization_provider.dart';
97
import 'package:whitenoise/config/states/chat_search_state.dart';
108
import 'package:whitenoise/domain/models/message_model.dart';
119
import 'package:whitenoise/ui/chat/widgets/chat_bubble/bubble.dart';
1210
import 'package:whitenoise/ui/chat/widgets/media_modal.dart';
1311
import 'package:whitenoise/ui/chat/widgets/message_media_grid.dart';
14-
import 'package:whitenoise/ui/chat/widgets/message_media_tile.dart';
12+
import 'package:whitenoise/ui/chat/widgets/message_reply_box.dart';
1513
import 'package:whitenoise/ui/core/themes/src/extensions.dart';
1614
import 'package:whitenoise/ui/core/ui/wn_avatar.dart';
1715
import 'package:whitenoise/ui/core/ui/wn_image.dart';
18-
import 'package:whitenoise/utils/message_utils.dart';
1916

2017
class MessageWidget extends StatelessWidget {
2118
final MessageModel message;
@@ -132,7 +129,7 @@ class MessageWidget extends StatelessWidget {
132129
),
133130
Gap(4.h),
134131
],
135-
ReplyBox(
132+
MessageReplyBox(
136133
replyingTo: message.replyTo,
137134
onTap:
138135
message.replyTo != null ? () => onReplyTap?.call(message.replyTo!.id) : null,
@@ -481,79 +478,3 @@ class TimeAndStatus extends StatelessWidget {
481478
);
482479
}
483480
}
484-
485-
class ReplyBox extends ConsumerWidget {
486-
const ReplyBox({super.key, this.replyingTo, this.onTap});
487-
final MessageModel? replyingTo;
488-
final VoidCallback? onTap;
489-
490-
@override
491-
Widget build(BuildContext context, WidgetRef ref) {
492-
// Watch localization changes
493-
ref.watch(currentLocaleProvider);
494-
if (replyingTo == null) {
495-
return const SizedBox.shrink();
496-
}
497-
return Container(
498-
margin: EdgeInsets.only(bottom: 8.h),
499-
child: Material(
500-
color: context.colors.secondary,
501-
child: InkWell(
502-
onTap: onTap,
503-
child: Container(
504-
padding: EdgeInsets.all(8.w),
505-
decoration: BoxDecoration(
506-
border: Border(
507-
left: BorderSide(
508-
color: context.colors.mutedForeground,
509-
width: 3.0,
510-
),
511-
),
512-
),
513-
child: Row(
514-
children: [
515-
if (replyingTo?.mediaAttachments.isNotEmpty ?? false) ...[
516-
Padding(
517-
padding: EdgeInsets.only(right: 8.w),
518-
child: MessageMediaTile(
519-
mediaFile: replyingTo!.mediaAttachments.first,
520-
size: 32.w,
521-
),
522-
),
523-
],
524-
Expanded(
525-
child: Column(
526-
crossAxisAlignment: CrossAxisAlignment.stretch,
527-
children: [
528-
Text(
529-
MessageUtils.getDisplayName(replyingTo, null),
530-
style: TextStyle(
531-
color: context.colors.mutedForeground,
532-
fontSize: 12.sp,
533-
fontWeight: FontWeight.w600,
534-
),
535-
maxLines: 1,
536-
overflow: TextOverflow.ellipsis,
537-
),
538-
Gap(4.h),
539-
Text(
540-
replyingTo?.content ?? '',
541-
style: TextStyle(
542-
color: context.colors.primary,
543-
fontSize: 12.sp,
544-
fontWeight: FontWeight.w600,
545-
),
546-
maxLines: 1,
547-
overflow: TextOverflow.ellipsis,
548-
),
549-
],
550-
),
551-
),
552-
],
553-
),
554-
),
555-
),
556-
),
557-
);
558-
}
559-
}

0 commit comments

Comments
 (0)