feat(category): 分类频道接入榜单快照
This commit is contained in:
1 parent
8c1662475a
commit
59fbd33059
8 files changed
+234
-11
No files matched your search
@@ -4,6 +4,7 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/content_category.dart';
|
||||
import 'package:fruitshorts/core/data/models/category_ranking.dart';
|
||||
import 'package:fruitshorts/core/data/models/drama.dart';
|
||||
import 'package:fruitshorts/core/data/models/home_feed.dart';
|
||||
import 'package:fruitshorts/core/data/remote/api_client.dart';
|
||||
@@ -31,7 +32,13 @@ void main() {
|
||||
'code': 0,
|
||||
'message': 'ok',
|
||||
'data': [
|
||||
{'id': id, 'name': 'Romance'},
|
||||
{
|
||||
'id': id,
|
||||
'name': '推荐榜',
|
||||
'code': 'RECOMMEND_RANKING',
|
||||
'layoutType': 'RANKING',
|
||||
'revision': '6',
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
@@ -44,11 +51,82 @@ void main() {
|
||||
final categories = await CategoryApi(client).list();
|
||||
|
||||
expect(categories.single.id, id);
|
||||
expect(categories.single.name, 'Romance');
|
||||
expect(categories.single.name, '推荐榜');
|
||||
expect(categories.single.code, 'RECOMMEND_RANKING');
|
||||
expect(categories.single.isRanking, isTrue);
|
||||
expect(categories.single.revision, '6');
|
||||
expect(adapter.requests.single.uri.path, '/app/categories');
|
||||
},
|
||||
);
|
||||
|
||||
test('should_parse_ranking_snapshot_without_reordering_entries', () async {
|
||||
final adapter = FakeHttpAdapter(
|
||||
(_) async => FakeHttpResponse(
|
||||
jsonEncode({
|
||||
'code': 0,
|
||||
'message': 'ok',
|
||||
'data': {
|
||||
'id': '7',
|
||||
'code': 'RECOMMEND_RANKING',
|
||||
'revision': '9',
|
||||
'list': [
|
||||
{
|
||||
'rank': 1,
|
||||
'drama': {
|
||||
'id': '22',
|
||||
'titleLocales': {'zh': '第二十二部'},
|
||||
},
|
||||
},
|
||||
{
|
||||
'rank': 2,
|
||||
'drama': {
|
||||
'id': '11',
|
||||
'titleLocales': {'zh': '第十一部'},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
final api = CategoryApi(
|
||||
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
||||
);
|
||||
|
||||
final ranking = await api.ranking('7');
|
||||
|
||||
expect(ranking.revision, '9');
|
||||
expect(ranking.entries.map((item) => item.rank), [1, 2]);
|
||||
expect(ranking.entries.map((item) => item.drama.id), ['22', '11']);
|
||||
expect(adapter.requests.single.uri.path, '/app/categories/7/ranking');
|
||||
});
|
||||
|
||||
test('should_load_ranking_when_first_category_uses_ranking_layout', () async {
|
||||
final repository = ScriptedCategoryRepository(
|
||||
categories: const [
|
||||
ContentCategory(
|
||||
id: '7',
|
||||
name: '推荐榜',
|
||||
layoutType: ContentCategory.rankingLayout,
|
||||
),
|
||||
],
|
||||
);
|
||||
final controller = CategoryController(repository);
|
||||
controller.dramaPageLoader = (_, {pageIndex = 1, pageSize = 20}) async =>
|
||||
throw StateError('grid loader should not run');
|
||||
controller.rankingLoader = (_) async => CategoryRanking(
|
||||
id: '7',
|
||||
code: 'RECOMMEND_RANKING',
|
||||
revision: '3',
|
||||
entries: [CategoryRankingEntry(rank: 1, drama: _drama('rank-1'))],
|
||||
);
|
||||
|
||||
await controller.load();
|
||||
|
||||
expect(controller.rankingSlotOf('7').ranking?.revision, '3');
|
||||
expect(controller.slotOf('7').pageIndex, 0);
|
||||
});
|
||||
|
||||
test('should_return_category_dramas_when_category_id_exists', () async {
|
||||
final repository = ScriptedCategoryRepository(
|
||||
categories: const [
|
||||
|
||||
Reference in new issue
Block a user