More tests
This commit is contained in:
parent
b16472fcd8
commit
c2ba916f00
5 changed files with 59 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
||||||
# paginate
|
# paginate
|
||||||
[](https://pub.dartlang.org/packages/angel_paginate)
|
[](https://pub.dartlang.org/packages/angel_paginate)
|
||||||
[](https://travis-ci.org/angel-dart/paginate)
|
[](https://travis-ci.org/angel-dart/paginate)
|
||||||

|

|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,8 @@ class Paginator<T> {
|
||||||
nextPage: _page >= last - 1 ? -1 : _page + 2,
|
nextPage: _page >= last - 1 ? -1 : _page + 2,
|
||||||
startIndex: it.isEmpty ? -1 : offset,
|
startIndex: it.isEmpty ? -1 : offset,
|
||||||
endIndex: offset + it.length - 1,
|
endIndex: offset + it.length - 1,
|
||||||
itemsPerPage: itemsPerPage,
|
itemsPerPage: itemsPerPage < _items.length ? itemsPerPage : _items
|
||||||
|
.length,
|
||||||
total: len);
|
total: len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_paginate
|
name: angel_paginate
|
||||||
version: 1.0.0+2
|
version: 1.0.0+3
|
||||||
description: Platform-agnostic pagination library, with custom support for the Angel framework.
|
description: Platform-agnostic pagination library, with custom support for the Angel framework.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/paginate
|
homepage: https://github.com/angel-dart/paginate
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import 'paginate_test.dart' as paginate_test;
|
import 'package:test/test.dart';
|
||||||
|
import 'bounds_test.dart' as bounds;
|
||||||
|
import 'paginate_test.dart' as paginate;
|
||||||
import 'server_test.dart' as server;
|
import 'server_test.dart' as server;
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
paginate_test.main();
|
group('bounds', bounds.main);
|
||||||
server.main();
|
group('paginate', paginate.main);
|
||||||
|
group('server', server.main);
|
||||||
}
|
}
|
49
test/bounds_test.dart
Normal file
49
test/bounds_test.dart
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
import 'package:angel_client/angel_client.dart' as c;
|
||||||
|
import 'package:angel_diagnostics/angel_diagnostics.dart';
|
||||||
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
|
import 'package:angel_paginate/server.dart';
|
||||||
|
import 'package:angel_test/angel_test.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
final List<Map<String, String>> DATA = [
|
||||||
|
{'billie': 'jean'},
|
||||||
|
{'off': 'the_wall'},
|
||||||
|
{'michael': 'jackson'}
|
||||||
|
];
|
||||||
|
|
||||||
|
main() {
|
||||||
|
TestClient client;
|
||||||
|
c.Service songService;
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
var app = new Angel()
|
||||||
|
..use('/api/songs', new AnonymousService(index: ([p]) async => DATA));
|
||||||
|
var service = app.service('api/songs') as HookedService;
|
||||||
|
service.afterIndexed.listen(paginate(itemsPerPage: 2));
|
||||||
|
await app.configure(logRequests());
|
||||||
|
client = await connectTo(app);
|
||||||
|
songService = client.service('api/songs');
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() => client.close());
|
||||||
|
|
||||||
|
test('limit exceeds size of collection', () async {
|
||||||
|
var response = await songService.index({
|
||||||
|
'query': {
|
||||||
|
r'$limit': DATA.length + 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var page = new PaginationResult<Map<String, String>>.fromMap(response);
|
||||||
|
print('page: ${page.toJson()}');
|
||||||
|
|
||||||
|
expect(page.total, DATA.length);
|
||||||
|
expect(page.itemsPerPage, DATA.length);
|
||||||
|
expect(page.previousPage, -1);
|
||||||
|
expect(page.currentPage, 1);
|
||||||
|
expect(page.nextPage, -1);
|
||||||
|
expect(page.startIndex, 0);
|
||||||
|
expect(page.endIndex, DATA.length - 1);
|
||||||
|
expect(page.data, DATA);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue