diff --git a/t/charts/basics.t b/t/charts/basics.t index 0f93e5a2433..1527a5e1dda 100644 --- a/t/charts/basics.t +++ b/t/charts/basics.t @@ -12,7 +12,7 @@ my @tickets = add_tix_from_data( { Subject => 'n', Status => 'new' }, { Subject => 'o', Status => 'open' }, { Subject => 'o', Status => 'open' }, - { Subject => 'r', Status => 'resolved' }, + { Subject => 'o', Status => 'open' }, { Subject => 'r', Status => 'resolved' }, { Subject => 'r', Status => 'resolved' }, ); @@ -28,6 +28,19 @@ use_ok 'RT::Report::Tickets'; ); $report->SortEntries; + my $new_cell = [ + { 'value' => 'new', 'type' => 'label' }, + { 'query' => '(Status = \'new\')', 'value' => '1', 'type' => 'value' }, + ]; + my $open_cell = [ + { 'value' => 'open', 'type' => 'label' }, + { 'query' => '(Status = \'open\')', 'value' => '3', 'type' => 'value' } + ]; + my $resolved_cell = [ + { 'value' => 'resolved', 'type' => 'label' }, + { 'query' => '(Status = \'resolved\')', 'value' => '2', 'type' => 'value' } + ]; + my @colors = RT->Config->Get("ChartColors"); my $expected = { 'thead' => [ { @@ -45,24 +58,15 @@ use_ok 'RT::Report::Tickets'; } ], 'tbody' => [ { - 'cells' => [ - { 'value' => 'new', 'type' => 'label' }, - { 'query' => '(Status = \'new\')', 'value' => '1', 'type' => 'value' }, - ], + 'cells' => $new_cell, 'even' => 1 }, { - 'cells' => [ - { 'value' => 'open', 'type' => 'label' }, - { 'query' => '(Status = \'open\')', 'value' => '2', 'type' => 'value' } - ], + 'cells' => $open_cell, 'even' => 0 }, { - 'cells' => [ - { 'value' => 'resolved', 'type' => 'label' }, - { 'query' => '(Status = \'resolved\')', 'value' => '3', 'type' => 'value' } - ], + 'cells' => $resolved_cell, 'even' => 1 }, ] @@ -70,6 +74,38 @@ use_ok 'RT::Report::Tickets'; my %table = $report->FormatTable( %columns ); is_deeply( \%table, $expected, "basic table" ); + + $report->SortEntries( ChartOrderBy => 'label', ChartOrder => 'ASC' ); + %table = $report->FormatTable( %columns ); + is_deeply( \%table, $expected, "basic table sorted by label ASC" ); + + $report->SortEntries( ChartOrderBy => 'label', ChartOrder => 'DESC' ); + %table = $report->FormatTable( %columns ); + @{$expected->{'tbody'}} = reverse @{$expected->{'tbody'}}; + is_deeply( \%table, $expected, "basic table sorted by label DESC" ); + + $report->SortEntries( ChartOrderBy => 'value', ChartOrder => 'ASC' ); + %table = $report->FormatTable( %columns ); + $expected->{'tbody'} = [ + { + 'cells' => $new_cell, + 'even' => 1 + }, + { + 'cells' => $resolved_cell, + 'even' => 0, + }, + { + 'cells' => $open_cell, + 'even' => 1 + }, + ]; + is_deeply( \%table, $expected, "basic table sorted by value ASC" ); + + $report->SortEntries( ChartOrderBy => 'value', ChartOrder => 'DESC' ); + %table = $report->FormatTable( %columns ); + @{$expected->{'tbody'}} = reverse @{$expected->{'tbody'}}; + is_deeply( \%table, $expected, "basic table sorted by value DESC" ); } done_testing;