add
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
// 评论模型解析单测(《03-接口文档》6.3/6.4)
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:video_app/models/comment_item.dart';
|
||||
|
||||
void main() {
|
||||
group('CommentItem.fromJson', () {
|
||||
test('完整字段解析', () {
|
||||
final c = CommentItem.fromJson(const {
|
||||
'comment_id': 55001,
|
||||
'user': {
|
||||
'user_id': 100030,
|
||||
'nickname': '阿花',
|
||||
'avatar_url': 'https://cdn/a.jpg',
|
||||
},
|
||||
'content': '拍得真好',
|
||||
'like_count': 12,
|
||||
'reply_count': 3,
|
||||
'created_at': '2026-10-14 10:00:00',
|
||||
});
|
||||
expect(c.commentId, 55001);
|
||||
expect(c.userId, 100030);
|
||||
expect(c.nickname, '阿花');
|
||||
expect(c.avatarUrl, 'https://cdn/a.jpg');
|
||||
expect(c.content, '拍得真好');
|
||||
expect(c.likeCount, 12);
|
||||
expect(c.replyCount, 3);
|
||||
expect(c.createdAt, '2026-10-14 10:00:00');
|
||||
});
|
||||
|
||||
test('字段缺失按默认值兜底', () {
|
||||
final c = CommentItem.fromJson(const {});
|
||||
expect(c.commentId, 0);
|
||||
expect(c.nickname, '');
|
||||
expect(c.replyCount, 0);
|
||||
});
|
||||
|
||||
test('copyWith 更新回复数', () {
|
||||
final c = CommentItem(commentId: 1, userId: 2, replyCount: 3);
|
||||
final c2 = c.copyWith(replyCount: 4);
|
||||
expect(c2.replyCount, 4);
|
||||
expect(c2.commentId, 1);
|
||||
expect(c.replyCount, 3); // 原对象不变
|
||||
});
|
||||
});
|
||||
|
||||
group('CommentListPage.fromJson', () {
|
||||
test('total 与列表解析', () {
|
||||
final page = CommentListPage.fromJson(const {
|
||||
'total': 78,
|
||||
'list': [
|
||||
{
|
||||
'comment_id': 55001,
|
||||
'user': {'user_id': 100030, 'nickname': '阿花', 'avatar_url': ''},
|
||||
'content': '拍得真好',
|
||||
'like_count': 12,
|
||||
'reply_count': 3,
|
||||
'created_at': '2026-10-14 10:00:00',
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(page.total, 78);
|
||||
expect(page.items, hasLength(1));
|
||||
expect(page.items.first.commentId, 55001);
|
||||
});
|
||||
});
|
||||
|
||||
group('RewardProgress / CommentCreateResult', () {
|
||||
test('普通发表:未发奖', () {
|
||||
final r = CommentCreateResult.fromJson(const {
|
||||
'comment_id': 55010,
|
||||
'reward_progress': {
|
||||
'current': 5,
|
||||
'target': 10,
|
||||
'rewarded_this_time': false,
|
||||
},
|
||||
});
|
||||
expect(r.commentId, 55010);
|
||||
expect(r.rewardProgress.current, 5);
|
||||
expect(r.rewardProgress.target, 10);
|
||||
expect(r.rewardProgress.rewardedThisTime, isFalse);
|
||||
expect(r.rewardProgress.rewardPoints, 0);
|
||||
});
|
||||
|
||||
test('满刻度发奖:reward_points 解析', () {
|
||||
final r = CommentCreateResult.fromJson(const {
|
||||
'comment_id': 55011,
|
||||
'reward_progress': {
|
||||
'current': 0,
|
||||
'target': 10,
|
||||
'rewarded_this_time': true,
|
||||
'reward_points': 1,
|
||||
},
|
||||
});
|
||||
expect(r.rewardProgress.rewardedThisTime, isTrue);
|
||||
expect(r.rewardProgress.rewardPoints, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user