feat(library): 收藏与观看历史支持分页
This commit is contained in:
1 parent
63d3b0f7ca
commit
235b50598a
24 files changed
+1015
-105
No files matched your search
@@ -0,0 +1,83 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/remote/api_client.dart';
|
||||
import 'package:fruitshorts/core/data/remote/watch_api.dart';
|
||||
|
||||
import '../support/fake_http_adapter.dart';
|
||||
|
||||
void main() {
|
||||
test('should_request_recent_with_page_and_parse_display_fields', () async {
|
||||
final adapter = FakeHttpAdapter(
|
||||
(_) async => FakeHttpResponse(
|
||||
jsonEncode({
|
||||
'code': 0,
|
||||
'message': 'ok',
|
||||
'data': {
|
||||
'total': '18',
|
||||
'list': [
|
||||
{
|
||||
'dramaId': '12',
|
||||
'episodeId': '88',
|
||||
'dramaTitle': '剧名',
|
||||
'dramaCover': '/files/12.png',
|
||||
'episodeNumber': 6,
|
||||
'totalEpisodes': 68,
|
||||
'positionMs': '80000',
|
||||
'durationMs': '120000',
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
final api = WatchApi(
|
||||
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
||||
);
|
||||
|
||||
final page = await api.recent(pageIndex: 2, pageSize: 10);
|
||||
|
||||
final request = adapter.requests.single;
|
||||
expect(request.uri.path, '/app/watch/recent');
|
||||
expect(request.queryParameters['pageIndex'], '2');
|
||||
expect(request.queryParameters['pageSize'], '10');
|
||||
expect(request.queryParameters.containsKey('limit'), isFalse);
|
||||
expect(page.total, 18);
|
||||
expect(page.list.single.dramaTitle, '剧名');
|
||||
expect(page.list.single.dramaCover, '/files/12.png');
|
||||
expect(page.list.single.episodeNumber, 6);
|
||||
expect(page.list.single.totalEpisodes, 68);
|
||||
});
|
||||
|
||||
test(
|
||||
'should_wrap_legacy_list_when_backend_has_not_deployed_paging',
|
||||
() async {
|
||||
final adapter = FakeHttpAdapter(
|
||||
(_) async => FakeHttpResponse(
|
||||
jsonEncode({
|
||||
'code': 0,
|
||||
'message': 'ok',
|
||||
'data': [
|
||||
{
|
||||
'dramaId': '5',
|
||||
'episodeId': '7',
|
||||
'positionMs': '1000',
|
||||
'durationMs': '2000',
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
);
|
||||
final api = WatchApi(
|
||||
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
||||
);
|
||||
|
||||
final page = await api.recent();
|
||||
|
||||
expect(page.total, 1);
|
||||
expect(page.list.single.dramaId, '5');
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user