Data-Paging
view release on metacpan or search on metacpan
t/lib/Data/Paging/Collection.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Test::More::Hooks;
use Test::Fatal;
BEGIN {
use_ok 'Data::Paging::Collection';
}
subtest 'instantiate with total_count params' => sub {
my ($collection, $total_count);
before {
$total_count = 10;
};
subtest 'when current_page is the first page' => sub {
before {
$collection = Data::Paging::Collection->new(
entries => [qw/a b c d e f/],
total_count => $total_count,
per_page => 5,
current_page => 1,
);
};
subtest 'calc valid entries' => sub {
is_deeply $collection->entries, [qw/a b c d e f/];
is_deeply $collection->sliced_entries, [qw/a b c d e/];
};
subtest 'calc valid paging values' => sub {
is $collection->current_visit_count, 5;
is $collection->already_visited_count, 0;
is $collection->visited_count, 5;
};
subtest 'calc valid position values' => sub {
is $collection->begin_count, 1;
is $collection->end_count, 5;
is $collection->begin_position, 1;
is $collection->end_position, 5;
};
subtest 'calc valid page number values' => sub {
is $collection->first_page, 1;
is $collection->last_page, 2;
ok not $collection->has_prev;
ok $collection->has_next;
ok not $collection->prev_page;
is $collection->next_page, 2;
};
};
subtest 'when current_page is the last page' => sub {
before {
$collection = Data::Paging::Collection->new(
entries => [qw/a b c d e/],
total_count => $total_count,
per_page => 5,
current_page => 2,
);
};
subtest 'calc valid entries' => sub {
( run in 1.492 second using v1.01-cache-2.11-cpan-54e63673c56 )