diff --git a/README.md b/README.md index 32b9deb3..edcc143e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # paginate -[![version 1.0.0+2](https://img.shields.io/badge/pub-v1.0.0+2-brightgreen.svg)](https://pub.dartlang.org/packages/angel_paginate) +[![version 1.0.0+3](https://img.shields.io/badge/pub-v1.0.0+3-brightgreen.svg)](https://pub.dartlang.org/packages/angel_paginate) [![build status](https://travis-ci.org/angel-dart/paginate.svg)](https://travis-ci.org/angel-dart/paginate) ![coverage: 100%](https://img.shields.io/badge/coverage-100%25-green.svg) diff --git a/lib/angel_paginate.dart b/lib/angel_paginate.dart index c993c752..7d40937b 100644 --- a/lib/angel_paginate.dart +++ b/lib/angel_paginate.dart @@ -57,7 +57,8 @@ class Paginator { nextPage: _page >= last - 1 ? -1 : _page + 2, startIndex: it.isEmpty ? -1 : offset, endIndex: offset + it.length - 1, - itemsPerPage: itemsPerPage, + itemsPerPage: itemsPerPage < _items.length ? itemsPerPage : _items + .length, total: len); } diff --git a/pubspec.yaml b/pubspec.yaml index 2fcbe81c..ba8697e8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ 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. author: Tobe O homepage: https://github.com/angel-dart/paginate diff --git a/test/all_test.dart b/test/all_test.dart index 3669a2fc..c071834b 100644 --- a/test/all_test.dart +++ b/test/all_test.dart @@ -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; main() { - paginate_test.main(); - server.main(); + group('bounds', bounds.main); + group('paginate', paginate.main); + group('server', server.main); } \ No newline at end of file diff --git a/test/bounds_test.dart b/test/bounds_test.dart new file mode 100644 index 00000000..f5185fc0 --- /dev/null +++ b/test/bounds_test.dart @@ -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> 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>.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); + }); +}