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,66 @@
|
||||
// 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/library_api.dart';
|
||||
|
||||
import '../support/fake_http_adapter.dart';
|
||||
|
||||
void main() {
|
||||
test('should_request_favorites_with_page_and_parse_page_result', () async {
|
||||
final adapter = FakeHttpAdapter(
|
||||
(_) async => FakeHttpResponse(
|
||||
jsonEncode({
|
||||
'code': 0,
|
||||
'message': 'ok',
|
||||
'data': {
|
||||
'total': '21',
|
||||
'list': [
|
||||
{'id': '9', 'title': '收藏剧', 'cover': '/files/9.png'},
|
||||
],
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
final api = LibraryApi(
|
||||
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
||||
);
|
||||
|
||||
final page = await api.favorites(pageIndex: 2, pageSize: 10);
|
||||
|
||||
final request = adapter.requests.single;
|
||||
expect(request.uri.path, '/app/favorites');
|
||||
expect(request.queryParameters['pageIndex'], '2');
|
||||
expect(request.queryParameters['pageSize'], '10');
|
||||
expect(page.total, 21);
|
||||
expect(page.list.single.id, '9');
|
||||
expect(page.list.single.title, '收藏剧');
|
||||
});
|
||||
|
||||
test(
|
||||
'should_wrap_legacy_list_when_backend_has_not_deployed_paging',
|
||||
() async {
|
||||
final adapter = FakeHttpAdapter(
|
||||
(_) async => FakeHttpResponse(
|
||||
jsonEncode({
|
||||
'code': 0,
|
||||
'message': 'ok',
|
||||
'data': [
|
||||
{'id': '3', 'title': '旧收藏'},
|
||||
],
|
||||
}),
|
||||
),
|
||||
);
|
||||
final api = LibraryApi(
|
||||
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
||||
);
|
||||
|
||||
final page = await api.favorites();
|
||||
|
||||
expect(page.total, 1);
|
||||
expect(page.list.single.title, '旧收藏');
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user