107 lines
2.9 KiB
Dart
107 lines
2.9 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fruitshorts/core/data/models/drama.dart';
|
|
import 'package:fruitshorts/core/data/services/playback_queue.dart';
|
|
|
|
void main() {
|
|
test('should_advance_between_dramas_on_home_and_between_episodes_in_series_when_queue_is_built', () {
|
|
final dramas = [_drama('a', 3), _drama('b', 2), _drama('c', 4)];
|
|
|
|
final home = PlaybackQueue.home(dramas);
|
|
expect(home.length, 3);
|
|
expect(home.entryAt(0).drama.id, 'a');
|
|
expect(home.entryAt(1).drama.id, 'b');
|
|
expect(home.entryAt(1).episode.number, 1);
|
|
expect(home.nextIndex(0), 1);
|
|
expect(home.nextIndex(2), isNull);
|
|
|
|
final series = PlaybackQueue.series(dramas[0]);
|
|
expect(series.length, 3);
|
|
expect(series.entryAt(0).drama.id, series.entryAt(1).drama.id);
|
|
expect(series.entryAt(1).episode.number, 2);
|
|
expect(series.nextIndex(0), 1);
|
|
expect(series.nextIndex(2), isNull);
|
|
});
|
|
|
|
test('should_leave_dramas_out_when_they_have_no_episodes', () {
|
|
final home = PlaybackQueue.home([
|
|
_drama('a', 2),
|
|
Drama(
|
|
id: 'empty',
|
|
title: '没有剧集',
|
|
synopsis: '',
|
|
posterUrl: '/files/empty.jpg',
|
|
),
|
|
]);
|
|
expect(home.length, 1);
|
|
expect(home.entryAt(0).drama.id, 'a');
|
|
});
|
|
|
|
test('should_play_preview_episode_when_list_card_has_one', () {
|
|
final home = PlaybackQueue.home([
|
|
Drama.fromCardJson(const {
|
|
'id': 5,
|
|
'title': '闪婚后',
|
|
'cover': '/files/cover.jpg',
|
|
'totalEpisodes': 77,
|
|
'preview': {
|
|
'id': 9,
|
|
'number': 1,
|
|
'title': '第 1 集',
|
|
'isFree': true,
|
|
'playUrl': '/files/episode/9.mp4',
|
|
'posterUrl': '/files/transcoded/9/poster.jpg',
|
|
'thumbnailsUrl': '/files/transcoded/9/thumbnails/thumbnails.vtt',
|
|
},
|
|
}),
|
|
]);
|
|
|
|
expect(home.length, 1);
|
|
expect(home.entryAt(0).episode.videoUrl, '/files/episode/9.mp4');
|
|
expect(
|
|
home.entryAt(0).episode.posterUrl,
|
|
'/files/transcoded/9/poster.jpg',
|
|
);
|
|
});
|
|
|
|
test('should_parse_poster_url_for_drama_detail_episode_list', () {
|
|
final drama = Drama.fromDetailJson(const {
|
|
'id': 5,
|
|
'title': '闪婚后',
|
|
'cover': '/files/cover.jpg',
|
|
'episodes': [
|
|
{
|
|
'id': 9,
|
|
'number': 1,
|
|
'title': '第 1 集',
|
|
'isFree': true,
|
|
'posterUrl': '/files/transcoded/9/poster.jpg',
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(
|
|
drama.episodes.single.posterUrl,
|
|
'/files/transcoded/9/poster.jpg',
|
|
);
|
|
});
|
|
}
|
|
|
|
Drama _drama(String id, int episodeCount) => Drama(
|
|
id: id,
|
|
title: 'Drama $id',
|
|
synopsis: '简介 $id',
|
|
posterUrl: '/files/$id.jpg',
|
|
episodes: [
|
|
for (var index = 1; index <= episodeCount; index++)
|
|
Episode(
|
|
id: '$id-$index',
|
|
number: index,
|
|
title: '第 $index 集',
|
|
isFree: true,
|
|
videoUrl: 'https://example.test/$id-$index.mp4',
|
|
),
|
|
],
|
|
);
|