Skip to content

Commit 13485a4

Browse files
author
Andy Beverley
committed
Further fixes and tests for grouping ordering on timeline
1 parent c3b8d75 commit 13485a4

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

lib/GADS/Timeline.pm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ sub _build_colors
6767
}
6868

6969
has groups => (
70-
is => 'ro',
71-
default => sub { +{} },
70+
is => 'lazy',
71+
clearer => 1,
7272
);
7373

74+
sub _build_groups { +{} }
75+
7476
has _group_count => (
7577
is => 'rw',
7678
isa => Int,
@@ -107,6 +109,7 @@ sub clear
107109
$self->clear_items;
108110
$self->_set_display_from(undef);
109111
$self->_set_display_to(undef);
112+
$self->clear_groups;
110113
}
111114

112115
has _all_items_index => (

t/013_datatime.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -706,13 +706,13 @@ is( @{$records->data_timeline->{items}}, 1, "Filter, single column and limited r
706706
{
707707
push @$data, {
708708
string1 => 'foo2',
709-
enum1 => [2],
709+
enum1 => [3],
710710
date1 => $date->add(days => 1)->ymd,
711711
};
712712
}
713713
push @$data,{
714714
string1 => 'foo1',
715-
enum1 => [1,3],
715+
enum1 => [1,4],
716716
date1 => '2010-07-01',
717717
};
718718
$date = DateTime->new(year => 2010, month => 8, day => 1);
@@ -725,7 +725,7 @@ is( @{$records->data_timeline->{items}}, 1, "Filter, single column and limited r
725725
};
726726
}
727727

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

730730
$sheet->create_records;
731731
my $schema = $sheet->schema;
@@ -747,20 +747,20 @@ is( @{$records->data_timeline->{items}}, 1, "Filter, single column and limited r
747747
view => $view,
748748
user => undef,
749749
layout => $layout,
750-
from => DateTime->new(year => 2010, month => 3, day => 1),
750+
from => DateTime->new(year => 2010, month => 6, day => 1),
751751
schema => $schema,
752752
);
753753

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

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

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

765765
ok( $_->{content} eq "foo$_->{order}", "Ordering matches content" )
766766
foreach @groups;

t/lib/Test/GADS/DataSheet.pm

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ has column_count => (
354354
},
355355
);
356356

357+
has enumvals_count => (
358+
is => 'ro',
359+
default => 3,
360+
);
361+
357362
has curval => (
358363
is => 'ro',
359364
);
@@ -598,17 +603,14 @@ sub __build_columns
598603
$enum->name("enum$count");
599604
$enum->name_short("L${instance_id}enum$count");
600605
$enum->multivalue(1) if $self->multivalue && $self->multivalue_columns->{enum};
601-
$enum->enumvals([
602-
{
603-
value => 'foo1',
604-
},
605-
{
606-
value => 'foo2',
607-
},
608-
{
609-
value => 'foo3',
610-
},
611-
]);
606+
my @enumvals;
607+
foreach my $i (1..$self->enumvals_count)
608+
{
609+
push @enumvals, {
610+
value => "foo$i",
611+
};
612+
}
613+
$enum->enumvals(\@enumvals);
612614
$enum->set_permissions({$self->group->id => $permissions})
613615
unless $self->no_groups;
614616
try { $enum->write };

0 commit comments

Comments
 (0)