53 lines
1.4 KiB
Dart
53 lines
1.4 KiB
Dart
// 用户主页相关模型解析单测
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:video_app/models/user_profile.dart';
|
|
|
|
void main() {
|
|
test('UserPublicProfile.fromJson 解析', () {
|
|
final p = UserPublicProfile.fromJson(const {
|
|
'user_id': 100023,
|
|
'nickname': '小明',
|
|
'avatar_url': 'https://cdn/a.jpg',
|
|
'bio': '记录生活',
|
|
'video_count': 12,
|
|
'total_likes': 3456,
|
|
});
|
|
expect(p.userId, 100023);
|
|
expect(p.nickname, '小明');
|
|
expect(p.videoCount, 12);
|
|
expect(p.totalLikes, 3456);
|
|
});
|
|
|
|
test('UserPublicProfile 缺省兜底', () {
|
|
final p = UserPublicProfile.fromJson(const {'user_id': 1});
|
|
expect(p.nickname, '');
|
|
expect(p.videoCount, 0);
|
|
});
|
|
|
|
test('HistoryItem.fromJson 解析与计费标签', () {
|
|
final h = HistoryItem.fromJson(const {
|
|
'video': {'video_id': 101, 'title': '示例视频'},
|
|
'watched_at': '2026-10-14 09:21:33',
|
|
'cost_type': 1,
|
|
});
|
|
expect(h.video.videoId, 101);
|
|
expect(h.costType, 1);
|
|
expect(h.costLabel, '积分');
|
|
|
|
final free = HistoryItem.fromJson(const {
|
|
'video': {'video_id': 102},
|
|
'watched_at': '',
|
|
'cost_type': 0,
|
|
});
|
|
expect(free.costLabel, '免费');
|
|
|
|
final member = HistoryItem.fromJson(const {
|
|
'video': {'video_id': 103},
|
|
'watched_at': '',
|
|
'cost_type': 2,
|
|
});
|
|
expect(member.costLabel, '会员');
|
|
});
|
|
}
|