Skip to content

Commit

Permalink
Further fixes and tests for grouping ordering on timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Beverley committed Aug 13, 2020
1 parent c3b8d75 commit e298c64
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
8 changes: 6 additions & 2 deletions lib/GADS/Timeline.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ sub _build_colors
}

has groups => (
is => 'ro',
default => sub { +{} },
is => 'lazy',
clearer => 1,
);

sub _build_groups { +{} }

has _group_count => (
is => 'rw',
isa => Int,
Expand Down Expand Up @@ -107,6 +109,8 @@ sub clear
$self->clear_items;
$self->_set_display_from(undef);
$self->_set_display_to(undef);
$self->clear_groups;
$self->_group_count(0);
}

has _all_items_index => (
Expand Down
12 changes: 6 additions & 6 deletions t/013_datatime.t
Original file line number Diff line number Diff line change
Expand Up @@ -706,13 +706,13 @@ is( @{$records->data_timeline->{items}}, 1, "Filter, single column and limited r
{
push @$data, {
string1 => 'foo2',
enum1 => [2],
enum1 => [3],
date1 => $date->add(days => 1)->ymd,
};
}
push @$data,{
string1 => 'foo1',
enum1 => [1,3],
enum1 => [1,4],
date1 => '2010-07-01',
};
$date = DateTime->new(year => 2010, month => 8, day => 1);
Expand All @@ -725,7 +725,7 @@ is( @{$records->data_timeline->{items}}, 1, "Filter, single column and limited r
};
}

my $sheet = Test::GADS::DataSheet->new(data => $data, multivalue => 1);
my $sheet = Test::GADS::DataSheet->new(data => $data, multivalue => 1, enumvals_count => 4);

$sheet->create_records;
my $schema = $sheet->schema;
Expand All @@ -747,20 +747,20 @@ is( @{$records->data_timeline->{items}}, 1, "Filter, single column and limited r
view => $view,
user => undef,
layout => $layout,
from => DateTime->new(year => 2010, month => 3, day => 1),
from => DateTime->new(year => 2010, month => 6, day => 1),
schema => $schema,
);

my $return = $records->data_timeline(group => $enum1->id);

# 149 normal results as per other tests plus 1 extra result for multivalue
# 148 normal results as per other tests plus 1 extra result for multivalue
is( @{$return->{items}}, 149, "Correct number of items for group ordering" );

# Check that the groups are in the right order. Because we are ordering by
# the enumvals (foo1, foo2, foo3) then number in the value should match the
# grouping order
my @groups = @{$return->{groups}};
is( @groups, 3, "Correct number of groups" );
is( @groups, 4, "Correct number of groups" );

ok( $_->{content} eq "foo$_->{order}", "Ordering matches content" )
foreach @groups;
Expand Down
24 changes: 13 additions & 11 deletions t/lib/Test/GADS/DataSheet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ has column_count => (
},
);

has enumvals_count => (
is => 'ro',
default => 3,
);

has curval => (
is => 'ro',
);
Expand Down Expand Up @@ -598,17 +603,14 @@ sub __build_columns
$enum->name("enum$count");
$enum->name_short("L${instance_id}enum$count");
$enum->multivalue(1) if $self->multivalue && $self->multivalue_columns->{enum};
$enum->enumvals([
{
value => 'foo1',
},
{
value => 'foo2',
},
{
value => 'foo3',
},
]);
my @enumvals;
foreach my $i (1..$self->enumvals_count)
{
push @enumvals, {
value => "foo$i",
};
}
$enum->enumvals(\@enumvals);
$enum->set_permissions({$self->group->id => $permissions})
unless $self->no_groups;
try { $enum->write };
Expand Down

0 comments on commit e298c64

Please sign in to comment.