75 lines
2.1 KiB
Dart
75 lines
2.1 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/models/home_feed.dart';
|
|
import 'package:fruitshorts/pages/discover/ranking_logic.dart';
|
|
|
|
void main() {
|
|
test('should_use_backend_hot_order_when_hot_board_is_selected', () {
|
|
final logic = RankingLogic(
|
|
sections: [
|
|
FeedSection(
|
|
code: 'hot',
|
|
title: 'Hot',
|
|
dramas: [_drama('first'), _drama('second')],
|
|
),
|
|
FeedSection(code: 'new', title: 'New', dramas: [_drama('fresh')]),
|
|
],
|
|
fallback: [_drama('fallback')],
|
|
);
|
|
|
|
expect(logic.board, RankingBoard.hot);
|
|
expect(logic.entries.map((entry) => entry.drama.id), ['first', 'second']);
|
|
expect(logic.entries.map((entry) => entry.rank), [1, 2]);
|
|
logic.dispose();
|
|
});
|
|
|
|
test('should_switch_to_new_releases_when_new_board_is_selected', () {
|
|
final logic = RankingLogic(
|
|
sections: [
|
|
FeedSection(code: 'hot', title: 'Hot', dramas: [_drama('hot')]),
|
|
FeedSection(code: 'new', title: 'New', dramas: [_drama('fresh')]),
|
|
],
|
|
fallback: const [],
|
|
);
|
|
|
|
logic.select(RankingBoard.newReleases);
|
|
|
|
expect(logic.board, RankingBoard.newReleases);
|
|
expect(logic.entries.single.drama.id, 'fresh');
|
|
logic.dispose();
|
|
});
|
|
|
|
test(
|
|
'should_deduplicate_and_fall_back_when_requested_section_is_missing',
|
|
() {
|
|
final logic = RankingLogic(
|
|
sections: [
|
|
FeedSection(
|
|
code: 'hot',
|
|
title: 'Hot',
|
|
dramas: [_drama('a'), _drama('a')],
|
|
),
|
|
],
|
|
fallback: [_drama('b'), _drama('a')],
|
|
);
|
|
|
|
expect(logic.entries.map((entry) => entry.drama.id), ['a']);
|
|
|
|
logic.select(RankingBoard.newReleases);
|
|
|
|
expect(logic.entries.map((entry) => entry.drama.id), ['b', 'a']);
|
|
expect(logic.entries.last.rank, 2);
|
|
logic.dispose();
|
|
},
|
|
);
|
|
}
|
|
|
|
Drama _drama(String id) => Drama(
|
|
id: id,
|
|
title: 'Drama $id',
|
|
synopsis: 'Synopsis $id',
|
|
posterUrl: '/files/$id.jpg',
|
|
);
|